1 #include "CallbackSceneUpdateAfterCommand.h"
3 #include "CurvesGraphs.h"
4 #include "CurveStyles.h"
6 #include "EngaugeAssert.h"
8 #include "GraphicsItemType.h"
9 #include "GraphicsPoint.h"
10 #include "GraphicsPointFactory.h"
11 #include "GraphicsScene.h"
13 #include "MainWindow.h"
15 #include "PointStyle.h"
16 #include <QApplication>
17 #include <QGraphicsItem>
18 #include "QtToString.h"
19 #include "Transformation.h"
22 QGraphicsScene(mainWindow)
29 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::addTemporaryPoint"
30 <<
" identifer=" << identifier.toLatin1().data();
32 m_graphicsLinesForCurves.
addPoint (AXIS_CURVE_NAME,
40 const QPointF &posScreen)
42 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::createPoint"
43 <<
" identifier=" << identifier.toLatin1().
data();
56 point->
setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
61 QString GraphicsScene::dumpCursors ()
const
63 QString cursorOverride = (QApplication::overrideCursor () != 0) ?
64 QtCursorToString (QApplication::overrideCursor ()->shape ()) :
66 QString cursorImage = QtCursorToString (image()->cursor().shape ());
68 QString dump = QString (
"overrideCursor=%1 imageCursor=%2")
75 const QGraphicsPixmapItem *GraphicsScene::image ()
const
78 QList<QGraphicsItem*> items = QGraphicsScene::items();
79 QList<QGraphicsItem*>::iterator itr;
80 for (itr = items.begin(); itr != items.end(); itr++) {
82 QGraphicsItem* item = *itr;
83 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_IMAGE) {
85 return (QGraphicsPixmapItem *) item;
94 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::positionHasChangedPointIdentifiers";
98 const QList<QGraphicsItem*> &items = QGraphicsScene::items();
99 QList<QGraphicsItem*>::const_iterator itr;
100 for (itr = items.begin(); itr != items.end(); itr++) {
102 const QGraphicsItem *item = *itr;
105 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
108 QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
109 bool positionHasChanged = item->data (DATA_KEY_POSITION_HAS_CHANGED).toBool ();
111 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsScene::positionHasChangedPointIdentifiers"
112 <<
" identifier=" << identifier.toLatin1().data()
113 <<
" positionHasChanged=" << (positionHasChanged ?
"yes" :
"no");
115 if (isPoint && positionHasChanged) {
118 movedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
136 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::removePoint identifier=" << identifier.toLatin1().data();
143 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::removeTemporaryPointIfExists";
152 int itemsBefore = items().count();
156 int itemsAfter = items().count();
158 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::resetOnLoad"
159 <<
" itemsBefore=" << itemsBefore
160 <<
" itemsAfter=" << itemsAfter;
165 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::resetPositionHasChangedFlags";
167 QList<QGraphicsItem*> itms = items ();
168 QList<QGraphicsItem*>::const_iterator itr;
169 for (itr = itms.begin (); itr != itms.end (); itr++) {
171 QGraphicsItem *item = *itr;
172 item->setData (DATA_KEY_POSITION_HAS_CHANGED,
false);
178 const QList<QGraphicsItem*> &items = QGraphicsScene::selectedItems();
180 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::selectedPointIdentifiers"
181 <<
" selectedItems=" << items.count();
183 QStringList selectedIds;
184 QList<QGraphicsItem*>::const_iterator itr;
185 for (itr = items.begin(); itr != items.end(); itr++) {
187 const QGraphicsItem* item = *itr;
190 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
194 selectedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
204 const QString &curveNameWanted)
206 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::showCurves"
207 <<
" show=" << (show ?
"true" :
"false")
208 <<
" showAll=" << (showAll ?
"true" :
"false")
209 <<
" curve=" << curveNameWanted.toLatin1().data();
211 const QList<QGraphicsItem*> &items = QGraphicsScene::items();
212 QList<QGraphicsItem*>::const_iterator itr;
213 for (itr = items.begin(); itr != items.end(); itr++) {
215 QGraphicsItem* item = *itr;
218 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
219 bool isCurve = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_LINE);
221 if (isPoint || isCurve) {
223 bool showThis = show;
224 if (show && !showAll) {
225 QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
230 showThis = (curveNameWanted == curveNameGot);
234 showThis = (curveNameWanted == identifier);
239 item->setVisible (showThis);
247 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateAfterCommand";
249 updateCurves (cmdMediator);
252 updatePointMembership (cmdMediator);
255 void GraphicsScene::updateCurves (
CmdMediator &cmdMediator)
257 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateCurves";
260 QStringList curveNames;
261 curveNames << AXIS_CURVE_NAME;
270 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateCurveStyles";
278 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateGraphicsLinesToMatchGraphicsPoints";
291 void GraphicsScene::updatePointMembership (
CmdMediator &cmdMediator)
293 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updatePointMembership";
298 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
void updateGraphicsLinesToMatchGraphicsPoints(const CurveStyles &modelCurveStyles, const Transformation &transformation)
A mouse move has just occurred so move the selected points, since they were dragged.
void lineMembershipPurge(const CurveStyles &curveStyles)
Mark the end of addPoint calls. Remove stale lines, insert missing lines, and draw the graphics lines...
void removePoint(const QString &identifier)
Remove the specified point. The act of deleting it will automatically remove it from the GraphicsScen...
static QString curveNameFromPointIdentifier(const QString &pointIdentifier)
Parse the curve name from the specified point identifier. This does the opposite of uniqueIdentifierG...
Factor for generating GraphicsPointAbstractBase class objects.
Callback for updating the QGraphicsItems in the scene after a command may have modified Points in Cur...
void updateAfterCommand(CmdMediator &cmdMediator)
Update the Points and their Curves after executing a command.
void printStream(QString indentation, QTextStream &str)
Debugging method that supports print method of this class and printStream method of some other class(...
void removePoint(const QString &identifier)
Remove specified point. This aborts if the point does not exist.
GraphicsScene(MainWindow *mainWindow)
Single constructor.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
void addPoint(const QString &curveName, const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
Add new point.
void lineMembershipReset()
Mark points as unwanted. Afterwards, lineMembershipPurge gets called.
QStringList selectedPointIdentifiers() const
Return a list of identifiers for the currently selected points.
GraphicsPoint * createPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const PointStyle &pointStyle)
Create circle or polygon point according to the PointStyle.
void removeTemporaryPointIfExists()
Remove temporary point if it exists.
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
CallbackSearchReturn callback(const QString &, const Point &point)
Callback method.
void updatePointOrdinalsAfterDrag(const CurveStyles &curveStyles, const Transformation &transformation)
See GraphicsScene::updateOrdinalsAfterDrag.
void updateGraphicsLinesToMatchGraphicsPoints(const CurveStyles &curveStyles)
Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.
Details for a specific Point.
QStringList positionHasChangedPointIdentifiers() const
Return a list of identifiers for the points that have moved since the last call to resetPositionHasCh...
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
static double UNDEFINED_ORDINAL()
Get method for undefined ordinal constant.
void resetPositionHasChangedFlags()
Reset positionHasChanged flag for all items. Typically this is done as part of mousePressEvent.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
Graphics item for drawing a circular or polygonal Point.
void updateCurveStyles(const CurveStyles &modelCurveStyles)
Update curve styles after settings changed.
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
void removeTemporaryPointIfExists()
Remove temporary point if it exists.
void resetOnLoad()
Reset, when loading a document after the first, to same state that first document was at when loaded...
void addTemporaryPoint(const QString &identifier, GraphicsPoint *point)
Add one temporary point to m_graphicsLinesForCurves. Non-temporary points are handled by the updateLi...
void updateCurveStyles(const CurveStyles &modelCurveStyles)
Update the curve style for every curve.
GraphicsPoint * createPoint(const QString &identifier, const PointStyle &pointStyle, const QPointF &posScreen)
Create one QGraphicsItem-based object that represents one Point. It is NOT added to m_graphicsLinesFo...
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
void setToolTip(const QString &toolTip)
Proxy method for QGraphicsItem::setToolTip.
void resetOnLoad()
Reset, when loading a document after the first, to same state that first document was at when loaded...
void addRemoveCurves(GraphicsScene &scene, const QStringList &curveNames)
Add new curves and remove expired curves to match the specified list.
void showCurves(bool show, bool showAll=false, const QString &curveName="")
Show or hide all Curves (if showAll is true) or just the selected Curve (if showAll is false);...
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...