[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Tue Feb 3 17:24:31 CET 2009
SVN commit 920698 by fenton:
Add DataMode.
M +14 -0 mainwindow.cpp
M +6 -0 mainwindow.h
M +113 -16 plotrenderitem.cpp
M +10 -0 plotrenderitem.h
M +2 -1 view.cpp
M +4 -1 view.h
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #920697:920698
@@ -70,6 +70,7 @@
_undoGroup = new QUndoGroup(this);
_debugDialog = new DebugDialog(this);
Debug::self()->setHandler(_debugDialog);
+ _dataMode = false;
createActions();
createMenus();
@@ -122,6 +123,11 @@
}
+void MainWindow::setDataMode(bool dataMode) {
+ _dataMode = dataMode;
+}
+
+
void MainWindow::setTiedZoom(bool tiedZoom) {
View *v = tabWidget()->currentView();
QList<PlotItem*> plots = PlotItemManager::plotsForView(v);
@@ -715,6 +721,12 @@
_tiedZoomAct->setCheckable(true);
connect(_tiedZoomAct, SIGNAL(toggled(bool)), this, SLOT(setTiedZoom(bool)));
+ _dataModeAct = new QAction(tr("&Data Mode"), this);
+ _dataModeAct->setStatusTip(tr("Toggle the current view's data mode"));
+ _dataModeAct->setIcon(QPixmap(":kst_datamode.png"));
+ _dataModeAct->setCheckable(true);
+ connect(_dataModeAct, SIGNAL(toggled(bool)), this, SLOT(setDataMode(bool)));
+
_newTabAct = new QAction(tr("&New tab"), this);
_newTabAct->setStatusTip(tr("Create a new tab"));
_newTabAct->setIcon(QPixmap(":kst_newtab.png"));
@@ -755,6 +767,7 @@
_viewMenu = menuBar()->addMenu(tr("&View"));
_viewMenu->addAction(_tiedZoomAct);
+ _viewMenu->addAction(_dataModeAct);
_viewMenu->addSeparator();
_viewMenu->addAction(_layoutModeAct);
@@ -813,6 +826,7 @@
_zoomToolBar = addToolBar(tr("Zoom"));
_zoomToolBar->addAction(_tiedZoomAct);
+ _zoomToolBar->addAction(_dataModeAct);
_layoutToolBar = new QToolBar(tr("Layout"), this);
_layoutToolBar->addAction(_layoutModeAct);
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #920697:920698
@@ -43,6 +43,7 @@
Document *document() const;
QProgressBar *progressBar() const;
void initFromCommandLine();
+ bool isDataMode() { return _dataMode; }
public Q_SLOTS:
void showDataManager();
@@ -101,6 +102,8 @@
void setLayoutMode(bool layoutMode);
void setTiedZoom(bool tiedZoom);
+ void setDataMode(bool dataMode);
+
protected:
void closeEvent(QCloseEvent *e);
@@ -125,6 +128,8 @@
QPointer<QProgressBar> _progressBar;
+ bool _dataMode;
+
QMenu *_fileMenu;
QMenu *_editMenu;
QMenu *_dataMenu;
@@ -157,6 +162,7 @@
QAction *_closeTabAct;
QAction *_dataManagerAct;
QAction *_debugDialogAct;
+ QAction *_dataModeAct;
QAction *_exitAct;
QAction *_exportGraphicsAct;
QAction *_newTabAct;
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #920697:920698
@@ -18,6 +18,8 @@
#include "objectstore.h"
#include "updatemanager.h"
#include "sharedaxisboxitem.h"
+#include "application.h"
+#include "image.h"
#include <QTime>
#include <QMenu>
@@ -33,7 +35,7 @@
namespace Kst {
PlotRenderItem::PlotRenderItem(PlotItem *parentItem)
- : ViewItem(parentItem->parentView()), _referencePointMode(false) {
+ : ViewItem(parentItem->parentView()), _referencePointMode(false), _highlightPointActive(false), _invertHighlight(false) {
setName(tr("Plot Render"));
setZValue(PLOTRENDER_ZVALUE);
@@ -53,6 +55,16 @@
updateGeometry(); //the initial rect
updateViewMode(); //the initial view
+
+ _referenceMode = new QAction(tr("Reference Mode"), this);
+ _referenceMode->setShortcut(Qt::Key_C);
+ registerShortcut(_referenceMode);
+ connect(_referenceMode, SIGNAL(triggered()), this, SLOT(referenceMode()));
+
+ _referenceModeDisabled = new QAction(tr("Reference Mode"), this);
+ _referenceModeDisabled->setShortcut(Qt::SHIFT + Qt::Key_C);
+ registerShortcut(_referenceModeDisabled);
+ connect(_referenceModeDisabled, SIGNAL(triggered()), this, SLOT(referenceModeDisabled()));
}
@@ -65,6 +77,22 @@
}
+void PlotRenderItem::referenceMode() {
+ _referencePointMode = true;
+ if (_highlightPointActive) {
+ _referencePoint = _highlightPoint;
+ } else {
+ _referencePoint = plotItem()->mapToProjection(_lastPos);
+ }
+ update();
+}
+
+
+void PlotRenderItem::referenceModeDisabled() {
+ _referencePointMode = false;
+}
+
+
PlotRenderItem::RenderType PlotRenderItem::type() {
return _type;
}
@@ -207,6 +235,7 @@
painter->restore();
paintReferencePoint(painter);
+ paintHighlightPoint(painter);
if (!parentView()->isPrinting()) {
if (_selectionRect.isValid()) {
@@ -256,6 +285,23 @@
}
+void PlotRenderItem::paintHighlightPoint(QPainter *painter) {
+ if (_highlightPointActive && kstApp->mainWindow()->isDataMode() && plotItem()->projectionRect().contains(_referencePoint)) {
+ QPointF point = plotItem()->mapToPlot(_highlightPoint);
+ painter->save();
+ painter->setPen(QPen(QColor("gray"), 1));
+ painter->setBrush(Qt::SolidPattern);
+ QColor highlightColor(QColor(0, 0, 0, 127));
+ if (_invertHighlight) {
+ highlightColor = QColor(255, 255, 255, 127);
+ }
+ painter->setBrush(highlightColor);
+ painter->drawEllipse(point.x()-3, point.y()-3, 7, 7);
+ painter->restore();
+ }
+}
+
+
QString PlotRenderItem::leftLabel() const {
// This will make sense once curves learn
// to return <Quantity> [<Units>]
@@ -310,16 +356,6 @@
_selectionRect.setTo(QPointF(_lastPos.x(), rect().bottom()));
}
- if (event->key() == Qt::Key_C) {
- if (modifiers & Qt::ShiftModifier) {
- _referencePointMode = false;
- } else {
- _referencePointMode = true;
- _referencePoint = plotItem()->mapToProjection(_lastPos);
- update();
- }
- }
-
ViewItem::keyPressEvent(event);
updateSelectionRect();
@@ -484,20 +520,77 @@
updateCursor(event->pos());
}
const QPointF point = plotItem()->mapToProjection(event->pos());
- QString message = QString("(%1, %2)").arg(QString::number(point.x(), 'G')).arg(QString::number(point.y()));
- kstApp->mainWindow()->statusBar()->showMessage(message);
+ if (kstApp->mainWindow()->isDataMode()) {
+ highlightNearestDataPoint(point);
+ } else {
+ _highlightPointActive = false;
+ QString message = QString("(%1, %2)").arg(QString::number(point.x(), 'G')).arg(QString::number(point.y()));
+ kstApp->mainWindow()->statusBar()->showMessage(message);
+ }
}
+void PlotRenderItem::highlightNearestDataPoint(const QPointF& position) {
+ QString curveMsg;
+ QString imageMsg;
+
+ _highlightPointActive = false;
+ _invertHighlight = false;
+
+ if (!relationList().isEmpty()) {
+ QString curveName, imageName;
+
+ bool bFirst = true;
+ bool bFoundImage = false;
+
+ qreal distance, minDistance = 1.0E300;
+ qreal x, y;
+ QPointF matchedPoint;
+ qreal imageZ;
+
+ foreach(RelationPtr relation, relationList()) {
+ if (Curve* curve = kst_cast<Curve>(relation)) {
+ int index = curve->getIndexNearXY(position.x(), 0, position.y());
+ curve->point(index, x, y);
+ distance = fabs(position.y() - y);
+ if (bFirst || distance < minDistance) {
+ matchedPoint = QPointF(x, y);
+ bFirst = false;
+ minDistance = distance;
+ curveName = curve->Name();
+ if (curve->color() == Qt::black) {
+ _invertHighlight = true;
+ }
+ }
+ } else if (Image* image = kst_cast<Image>(relation)) {
+ if (!bFoundImage && image->getNearestZ(position.x(), position.y(), imageZ)) {
+ bFoundImage = true;
+ imageName = image->Name();
+ }
+ }
+ }
+ if (!curveName.isEmpty()) {
+ QString message = curveName + QString(" (%1, %2)").arg(QString::number(matchedPoint.x(), 'G')).arg(QString::number(matchedPoint.y()));
+ kstApp->mainWindow()->statusBar()->showMessage(message);
+ _highlightPointActive = true;
+ _highlightPoint = QPointF(matchedPoint.x(), matchedPoint.y());
+ update();
+ } else if (!imageName.isEmpty()) {
+ QString message = imageName + QString(" (%1, %2, %3)").arg(QString::number(position.x(), 'G')).arg(QString::number(position.y())).arg(QString::number(imageZ, 'G'));
+ kstApp->mainWindow()->statusBar()->showMessage(message);
+ }
+ }
+}
+
+
void PlotRenderItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
ViewItem::hoverEnterEvent(event);
-
if (parentView()->viewMode() != View::Data) {
event->ignore();
return;
}
- setFocus();
+ setFocus(Qt::MouseFocusReason);
updateCursor(event->pos());
@@ -845,7 +938,11 @@
bool PlotRenderItem::tryShortcut(const QString &keySequence) {
- return plotItem()->tryShortcut(keySequence);
+ if (ViewItem::tryShortcut(keySequence)) {
+ return true;
+ } else {
+ return plotItem()->tryShortcut(keySequence);
+ }
}
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.h #920697:920698
@@ -53,6 +53,7 @@
virtual void paint(QPainter *painter);
virtual void paintRelations(QPainter *painter) = 0;
void paintReferencePoint(QPainter *painter);
+ void paintHighlightPoint(QPainter *painter);
virtual bool configureFromXml(QXmlStreamReader &xml, ObjectStore *store);
@@ -75,6 +76,8 @@
virtual void createCustomLayout();
virtual void remove();
virtual void relationUpdated(ObjectPtr object);
+ virtual void referenceMode();
+ virtual void referenceModeDisabled();
protected:
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
@@ -114,11 +117,18 @@
void computeMeanCentered(Qt::Orientation orientation, qreal *min, qreal *max) const;
void computeNoSpike(Qt::Orientation orientation, qreal *min, qreal *max) const;
+ void highlightNearestDataPoint(const QPointF& position);
+
private:
RenderType _type;
QPointF _lastPos;
bool _referencePointMode;
QPointF _referencePoint;
+ bool _highlightPointActive;
+ bool _invertHighlight;
+ QPointF _highlightPoint;
+ QAction *_referenceMode;
+ QAction *_referenceModeDisabled;
RelationList _relationList;
SelectionRect _selectionRect;
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #920697:920698
@@ -46,7 +46,8 @@
_snapToGridHorizontal(false),
_snapToGridVertical(false),
_shareAxis(true),
- _printing(false) {
+ _printing(false),
+ _dataMode(false) {
_undoStack = new QUndoStack(this);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
--- branches/work/kst/portto4/kst/src/libkstapp/view.h #920697:920698
@@ -94,6 +94,9 @@
void setPrinting(bool printing) { _printing = printing; }
bool isPrinting() { return _printing; }
+ void setDataMode(bool dataMode) { _dataMode = dataMode; }
+ bool isDataMode() { return _dataMode; }
+
virtual void contextMenuEvent();
Q_SIGNALS:
@@ -144,8 +147,8 @@
bool _snapToGridHorizontal;
bool _snapToGridVertical;
bool _shareAxis;
-
bool _printing;
+ bool _dataMode;
};
}
More information about the Kst
mailing list