7 #include "CallbackSceneUpdateAfterCommand.h" 9 #include "CurvesGraphs.h" 10 #include "CurveStyles.h" 12 #include "EngaugeAssert.h" 13 #include "EnumsToQt.h" 14 #include "GraphicsItemType.h" 15 #include "GraphicsPoint.h" 16 #include "GraphicsPointFactory.h" 17 #include "GraphicsScene.h" 19 #include "MainWindow.h" 21 #include "PointStyle.h" 22 #include <QApplication> 23 #include <QGraphicsItem> 24 #include "QtToString.h" 25 #include "Transformation.h" 28 QGraphicsScene(mainWindow)
35 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::addTemporaryPoint" 36 <<
" identifer=" << identifier.toLatin1().data();
38 m_graphicsLinesForCurves.
addPoint (AXIS_CURVE_NAME,
46 const QPointF &posScreen)
48 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::createPoint" 49 <<
" identifier=" << identifier.toLatin1().
data();
62 point->
setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
67 QString GraphicsScene::dumpCursors ()
const 69 QString cursorOverride = (QApplication::overrideCursor () != 0) ?
70 QtCursorToString (QApplication::overrideCursor ()->shape ()) :
72 QString cursorImage = QtCursorToString (image()->cursor().shape ());
74 QString dump = QString (
"overrideCursor=%1 imageCursor=%2")
83 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::hideAllItemsExceptImage";
85 for (
int index = 0; index < QGraphicsScene::items().count(); index++) {
86 QGraphicsItem *item = QGraphicsScene::items().at(index);
88 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt() == GRAPHICS_ITEM_TYPE_IMAGE) {
100 const QGraphicsPixmapItem *GraphicsScene::image ()
const 103 QList<QGraphicsItem*> items = QGraphicsScene::items();
104 QList<QGraphicsItem*>::iterator itr;
105 for (itr = items.begin(); itr != items.end(); itr++) {
107 QGraphicsItem* item = *itr;
108 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_IMAGE) {
110 return (QGraphicsPixmapItem *) item;
119 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::positionHasChangedPointIdentifiers";
121 QStringList movedIds;
123 const QList<QGraphicsItem*> &items = QGraphicsScene::items();
124 QList<QGraphicsItem*>::const_iterator itr;
125 for (itr = items.begin(); itr != items.end(); itr++) {
127 const QGraphicsItem *item = *itr;
130 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
133 QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
134 bool positionHasChanged = item->data (DATA_KEY_POSITION_HAS_CHANGED).toBool ();
136 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsScene::positionHasChangedPointIdentifiers" 137 <<
" identifier=" << identifier.toLatin1().data()
138 <<
" positionHasChanged=" << (positionHasChanged ?
"yes" :
"no");
140 if (isPoint && positionHasChanged) {
143 movedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
161 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::removePoint identifier=" << identifier.toLatin1().data();
168 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::removeTemporaryPointIfExists";
177 int itemsBefore = items().count();
181 int itemsAfter = items().count();
183 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::resetOnLoad" 184 <<
" itemsBefore=" << itemsBefore
185 <<
" itemsAfter=" << itemsAfter;
190 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::resetPositionHasChangedFlags";
192 QList<QGraphicsItem*> itms = items ();
193 QList<QGraphicsItem*>::const_iterator itr;
194 for (itr = itms.begin (); itr != itms.end (); itr++) {
196 QGraphicsItem *item = *itr;
197 item->setData (DATA_KEY_POSITION_HAS_CHANGED,
false);
203 const QList<QGraphicsItem*> &items = QGraphicsScene::selectedItems();
205 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::selectedPointIdentifiers" 206 <<
" selectedItems=" << items.count();
208 QStringList selectedIds;
209 QList<QGraphicsItem*>::const_iterator itr;
210 for (itr = items.begin(); itr != items.end(); itr++) {
212 const QGraphicsItem* item = *itr;
215 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
219 selectedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
229 const QString &curveNameWanted)
231 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::showCurves" 232 <<
" show=" << (show ?
"true" :
"false")
233 <<
" showAll=" << (showAll ?
"true" :
"false")
234 <<
" curve=" << curveNameWanted.toLatin1().data();
236 const QList<QGraphicsItem*> &items = QGraphicsScene::items();
237 QList<QGraphicsItem*>::const_iterator itr;
238 for (itr = items.begin(); itr != items.end(); itr++) {
240 QGraphicsItem* item = *itr;
243 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
244 bool isCurve = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_LINE);
246 if (isPoint || isCurve) {
248 bool showThis = show;
249 if (show && !showAll) {
250 QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
255 showThis = (curveNameWanted == curveNameGot);
259 showThis = (curveNameWanted == identifier);
264 item->setVisible (showThis);
272 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateAfterCommand";
274 updateCurves (cmdMediator);
277 updatePointMembership (cmdMediator);
280 void GraphicsScene::updateCurves (
CmdMediator &cmdMediator)
282 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateCurves";
285 QStringList curveNames;
286 curveNames << AXIS_CURVE_NAME;
295 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateCurveStyles";
303 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateGraphicsLinesToMatchGraphicsPoints";
316 void GraphicsScene::updatePointMembership (
CmdMediator &cmdMediator)
318 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updatePointMembership";
323 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 hideAllItemsExceptImage()
Hide all graphics items, except background image, in preparation for preview during IMPORT_TYPE_ADVAN...
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...