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;
89 ENGAUGE_ASSERT (
false);
95 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::positionHasChangedPointIdentifiers";
99 const QList<QGraphicsItem*> &items = QGraphicsScene::items();
100 QList<QGraphicsItem*>::const_iterator itr;
101 for (itr = items.begin(); itr != items.end(); itr++) {
103 const QGraphicsItem *item = *itr;
106 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
109 QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
110 bool positionHasChanged = item->data (DATA_KEY_POSITION_HAS_CHANGED).toBool ();
112 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsScene::positionHasChangedPointIdentifiers"
113 <<
" identifier=" << identifier.toLatin1().data()
114 <<
" positionHasChanged=" << (positionHasChanged ?
"yes" :
"no");
116 if (isPoint && positionHasChanged) {
119 movedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
137 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::removePoint identifier=" << identifier.toLatin1().data();
144 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::removeTemporaryPointIfExists";
153 int itemsBefore = items().count();
157 int itemsAfter = items().count();
159 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::resetOnLoad"
160 <<
" itemsBefore=" << itemsBefore
161 <<
" itemsAfter=" << itemsAfter;
166 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::resetPositionHasChangedFlags";
168 QList<QGraphicsItem*> itms = items ();
169 QList<QGraphicsItem*>::const_iterator itr;
170 for (itr = itms.begin (); itr != itms.end (); itr++) {
172 QGraphicsItem *item = *itr;
173 item->setData (DATA_KEY_POSITION_HAS_CHANGED,
false);
179 const QList<QGraphicsItem*> &items = QGraphicsScene::selectedItems();
181 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::selectedPointIdentifiers"
182 <<
" selectedItems=" << items.count();
184 QStringList selectedIds;
185 QList<QGraphicsItem*>::const_iterator itr;
186 for (itr = items.begin(); itr != items.end(); itr++) {
188 const QGraphicsItem* item = *itr;
191 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
195 selectedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
205 const QString &curveNameWanted)
207 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::showCurves"
208 <<
" show=" << (show ?
"true" :
"false")
209 <<
" showAll=" << (showAll ?
"true" :
"false")
210 <<
" curve=" << curveNameWanted.toLatin1().data();
212 const QList<QGraphicsItem*> &items = QGraphicsScene::items();
213 QList<QGraphicsItem*>::const_iterator itr;
214 for (itr = items.begin(); itr != items.end(); itr++) {
216 QGraphicsItem* item = *itr;
219 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
220 bool isCurve = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_LINE);
222 if (isPoint || isCurve) {
224 bool showThis = show;
225 if (show && !showAll) {
226 QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
231 showThis = (curveNameWanted == curveNameGot);
235 showThis = (curveNameWanted == identifier);
240 item->setVisible (showThis);
248 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateAfterCommand";
250 updateCurves (cmdMediator);
253 updatePointMembership (cmdMediator);
256 void GraphicsScene::updateCurves (
CmdMediator &cmdMediator)
258 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateCurves";
261 QStringList curveNames;
262 curveNames << AXIS_CURVE_NAME;
271 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateCurveStyles";
279 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateGraphicsLinesToMatchGraphicsPoints";
292 void GraphicsScene::updatePointMembership (
CmdMediator &cmdMediator)
294 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updatePointMembership";
299 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...