[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Thu Feb 5 20:02:34 CET 2009
SVN commit 921831 by fenton:
Add the ability to Maximize Plots - Tracked by PlotItemManager.
Add the support for disabling plot item update cycle.
M +68 -2 plotitem.cpp
M +13 -0 plotitem.h
M +31 -0 plotitemmanager.cpp
M +7 -0 plotitemmanager.h
M +5 -0 view.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #921830:921831
@@ -79,6 +79,9 @@
_rightPadding(0.0),
_topPadding(0.0),
_showLegend(false),
+ _plotMaximized(false),
+ _allowUpdates(true),
+ _updateDelayed(false),
_legend(0),
_zoomMenu(0),
_filterMenu(0),
@@ -312,6 +315,12 @@
connect(_zoomLogY, SIGNAL(triggered()), this, SLOT(zoomLogY()));
createZoomMenu();
+
+ _plotMaximize = new QAction(tr("Maximize Plot"), this);
+ _plotMaximize->setShortcut(Qt::Key_Z);
+ _plotMaximize->setCheckable(true);
+ registerShortcut(_plotMaximize);
+ connect(_plotMaximize, SIGNAL(triggered()), this, SLOT(plotMaximize()));
}
@@ -350,6 +359,7 @@
_zoomMenu->addAction(_zoomLogY);
}
+
void PlotItem::createFilterMenu() {
if (_filterMenu) {
delete _filterMenu;
@@ -403,6 +413,12 @@
}
}
}
+
+ if (parentView()->viewMode() == View::Data) {
+ _plotMaximize->setChecked(_plotMaximized);
+ menu.addAction(_plotMaximize);
+ }
+
_zoomLogX->setChecked(xAxis()->axisLog());
_zoomLogY->setChecked(yAxis()->axisLog());
menu.addMenu(_zoomMenu);
@@ -445,6 +461,10 @@
void PlotItem::updateObject() {
+ if (!_allowUpdates) {
+ _updateDelayed = true;
+ return;
+ }
#if DEBUG_UPDATE_CYCLE > 1
qDebug() << "UP - Updating Plot";
#endif
@@ -515,6 +535,12 @@
void PlotItem::paint(QPainter *painter) {
+ if (parentViewItem() && isInSharedAxisBox()) {
+ setBrush(Qt::transparent);
+ } else {
+ setBrush(Qt::white);
+ }
+
painter->save();
painter->setPen(Qt::NoPen);
painter->drawRect(rect());
@@ -1013,14 +1039,12 @@
setAllowedGripModes(0);
setFlags(0);
setParent(parent);
- setBrush(Qt::transparent);
} else {
setInSharedAxisBox(false);
setTiedZoom(false);
setAllowedGripModes(Move | Resize | Rotate);
setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
setParent(0);
- setBrush(Qt::white);
}
}
@@ -2271,6 +2295,48 @@
}
+void PlotItem::setAllowUpdates(bool allowed) {
+ if (allowed == _allowUpdates)
+ return;
+
+ _allowUpdates = allowed;
+ if (_allowUpdates) {
+ if (_updateDelayed) {
+ _updateDelayed = false;
+ updateObject();
+ }
+ }
+}
+
+
+void PlotItem::plotMaximize() {
+ if (!_plotMaximized && parentView()->viewMode() != View::Data) {
+ return;
+ }
+
+ if (_plotMaximized) {
+ _plotMaximized = false;
+ PlotItemManager::self()->removeFocusPlot(this);
+ setParent(_plotMaximizedSourceParent);
+ setPos(_plotMaximizedSourcePosition);
+ setViewRect(_plotMaximizedSourceRect);
+ setZValue(_plotMaximizedSourceZValue);
+ } else {
+ _plotMaximized = true;
+ _plotMaximizedSourcePosition = pos();
+ _plotMaximizedSourceRect = viewRect();
+ _plotMaximizedSourceZValue = zValue();
+ _plotMaximizedSourceParent = parentViewItem();
+
+ setParent(0);
+ setPos(0, 0);
+ setViewRect(parentView()->sceneRect());
+ setZValue(1000);
+ PlotItemManager::self()->setFocusPlot(this);
+ }
+}
+
+
void PlotItem::zoomFixedExpression(const QRectF &projection) {
#if DEBUG_ZOOM
qDebug() << "zoomFixedExpression" << projection << "current" << projectionRect();
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #921830:921831
@@ -239,6 +239,8 @@
virtual QString descriptionTip() const; // description for tooltips
ZoomState currentZoomState();
+ void setAllowUpdates(bool allowed);
+
protected:
virtual QString _automaticDescriptiveName() const;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
@@ -274,6 +276,7 @@
void zoomLogY();
virtual void edit();
void marginsUpdated();
+ void plotMaximize();
void showFilterDialog(QAction*);
void showFitDialog(QAction*);
@@ -418,6 +421,15 @@
bool _showLegend;
+ bool _plotMaximized;
+ QPointF _plotMaximizedSourcePosition;
+ QRectF _plotMaximizedSourceRect;
+ qreal _plotMaximizedSourceZValue;
+ ViewItem* _plotMaximizedSourceParent;
+
+ bool _allowUpdates;
+ bool _updateDelayed;
+
LegendItem* _legend;
QMenu *_zoomMenu;
@@ -440,6 +452,7 @@
QAction *_zoomYIn;
QAction *_zoomNormalizeYtoX;
QAction *_zoomLogY;
+ QAction *_plotMaximize;
QMenu *_filterMenu;
QAction *_filterAction;
--- branches/work/kst/portto4/kst/src/libkstapp/plotitemmanager.cpp #921830:921831
@@ -106,6 +106,37 @@
return QList<PlotItem*>();
}
+
+void PlotItemManager::setFocusPlot(PlotItem *plotItem) {
+ _focusedPlots.append(plotItem);
+ if (_plotLists.contains(plotItem->parentView())) {
+ foreach (PlotItem* plot, _plotLists.value(plotItem->parentView())) {
+ if (plotItem != plot) {
+ plot->setAllowUpdates(false);
+ }
+ }
+ }
}
+
+void PlotItemManager::removeFocusPlot(PlotItem *plotItem) {
+ _focusedPlots.remove(plotItem);
+ if (_plotLists.contains(plotItem->parentView())) {
+ foreach (PlotItem* plot, _plotLists.value(plotItem->parentView())) {
+ if (plotItem != plot) {
+ plot->setAllowUpdates(true);
+ }
+ }
+ }
+}
+
+
+void PlotItemManager::clearFocusedPlots() {
+ foreach (PlotItem* plotItem, _focusedPlots) {
+ plotItem->plotMaximize();
+ }
+}
+
+}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/plotitemmanager.h #921830:921831
@@ -34,6 +34,9 @@
void tiedZoomRemoved();
void allPlotsTiedZoom();
+ public Q_SLOTS:
+ void clearFocusedPlots();
+
private:
static void cleanup();
@@ -46,10 +49,14 @@
void addTiedZoomPlot(PlotItem *plotItem, bool checkAll = true);
void removeTiedZoomPlot(PlotItem *plotItem);
+ void setFocusPlot(PlotItem *plotItem);
+ void removeFocusPlot(PlotItem *plotItem);
+
private:
friend class PlotItem;
QHash< View*, QList<PlotItem*> > _plotLists;
QHash< View*, QList<PlotItem*> > _tiedZoomPlotLists;
+ QList<PlotItem*> _focusedPlots;
};
}
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #921830:921831
@@ -19,6 +19,7 @@
#include "viewdialog.h"
#include "viewgridlayout.h"
#include "document.h"
+#include "plotitemmanager.h"
#include <math.h>
@@ -81,6 +82,8 @@
_customLayoutAction = new QAction(tr("Custom"), this);
connect(_customLayoutAction, SIGNAL(triggered()), this, SLOT(createCustomLayout()));
+
+ connect(this, SIGNAL(viewModeChanged(View::ViewMode)), PlotItemManager::self(), SLOT(clearFocusedPlots()));
}
@@ -320,6 +323,8 @@
void View::createLayout(int columns) {
+ PlotItemManager::self()->clearFocusedPlots();
+
LayoutCommand *layout = new LayoutCommand(new LayoutBoxItem(this));
layout->createLayout(columns);
More information about the Kst
mailing list