7 #include "CallbackSceneUpdateAfterCommand.h" 9 #include "CurvesGraphs.h" 10 #include "CurveStyles.h" 12 #include "EngaugeAssert.h" 13 #include "EnumsToQt.h" 14 #include "GeometryWindow.h" 15 #include "GraphicsItemType.h" 16 #include "GraphicsPoint.h" 17 #include "GraphicsPointFactory.h" 18 #include "GraphicsScene.h" 20 #include "MainWindow.h" 22 #include "PointStyle.h" 23 #include <QApplication> 24 #include <QGraphicsItem> 25 #include "QtToString.h" 26 #include "SplineDrawer.h" 27 #include "Transformation.h" 30 QGraphicsScene(mainWindow),
31 m_pathItemMultiValued (0)
42 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::addTemporaryPoint" 43 <<
" identifer=" << identifier.toLatin1().data();
45 m_graphicsLinesForCurves.
addPoint (AXIS_CURVE_NAME,
53 const QString &pointIdentifier0,
54 const QString &pointIdentifier1)
56 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::addTemporaryScaleBar";
58 const double ORDINAL_0 = 0, ORDINAL_1 = 1;
60 m_graphicsLinesForCurves.
addPoint (AXIS_CURVE_NAME,
64 m_graphicsLinesForCurves.
addPoint (AXIS_CURVE_NAME,
72 const QPointF &posScreen,
75 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::createPoint" 76 <<
" identifier=" << identifier.toLatin1().data();
89 point->
setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
94 QString GraphicsScene::dumpCursors ()
const 96 QString cursorOverride = (QApplication::overrideCursor () != 0) ?
97 QtCursorToString (QApplication::overrideCursor ()->shape ()) :
99 QString cursorImage = QtCursorToString (image()->cursor().shape ());
101 QString dump = QString (
"overrideCursor=%1 imageCursor=%2")
102 .arg (cursorOverride)
110 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::hideAllItemsExceptImage";
112 for (
int index = 0; index < QGraphicsScene::items().count(); index++) {
113 QGraphicsItem *item = QGraphicsScene::items().at(index);
115 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt() == GRAPHICS_ITEM_TYPE_IMAGE) {
127 const QGraphicsPixmapItem *GraphicsScene::image ()
const 130 QList<QGraphicsItem*> items = QGraphicsScene::items();
131 QList<QGraphicsItem*>::iterator itr;
132 for (itr = items.begin(); itr != items.end(); itr++) {
134 QGraphicsItem* item = *itr;
135 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_IMAGE) {
137 return (QGraphicsPixmapItem *) item;
146 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::positionHasChangedPointIdentifiers";
148 QStringList movedIds;
150 const QList<QGraphicsItem*> &items = QGraphicsScene::items();
151 QList<QGraphicsItem*>::const_iterator itr;
152 for (itr = items.begin(); itr != items.end(); itr++) {
154 const QGraphicsItem *item = *itr;
157 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
160 QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
161 bool positionHasChanged = item->data (DATA_KEY_POSITION_HAS_CHANGED).toBool ();
163 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsScene::positionHasChangedPointIdentifiers" 164 <<
" identifier=" << identifier.toLatin1().data()
165 <<
" positionHasChanged=" << (positionHasChanged ?
"yes" :
"no");
167 if (isPoint && positionHasChanged) {
170 movedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
188 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::removePoint identifier=" << identifier.toLatin1().data();
195 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::removeTemporaryPointIfExists";
202 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::removeTemporaryScaleBarIfExists";
209 int itemsBefore = items().count();
213 int itemsAfter = items().count();
215 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::resetOnLoad" 216 <<
" itemsBefore=" << itemsBefore
217 <<
" itemsAfter=" << itemsAfter;
222 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::resetPositionHasChangedFlags";
224 QList<QGraphicsItem*> itms = items ();
225 QList<QGraphicsItem*>::const_iterator itr;
226 for (itr = itms.begin (); itr != itms.end (); itr++) {
228 QGraphicsItem *item = *itr;
229 item->setData (DATA_KEY_POSITION_HAS_CHANGED,
false);
235 const QString &curveNameWanted)
237 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::showCurves" 238 <<
" show=" << (show ?
"true" :
"false")
239 <<
" showAll=" << (showAll ?
"true" :
"false")
240 <<
" curve=" << curveNameWanted.toLatin1().data();
242 const QList<QGraphicsItem*> &items = QGraphicsScene::items();
243 QList<QGraphicsItem*>::const_iterator itr;
244 for (itr = items.begin(); itr != items.end(); itr++) {
246 QGraphicsItem* item = *itr;
249 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
250 bool isCurve = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_LINE);
252 if (isPoint || isCurve) {
254 bool showThis = show;
255 if (show && !showAll) {
256 QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
261 showThis = (curveNameWanted == curveNameGot);
265 showThis = (curveNameWanted == identifier);
270 item->setVisible (showThis);
277 double highlightOpacity,
281 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateAfterCommand";
285 updateCurves (cmdMediator);
288 updatePointMembership (cmdMediator,
293 void GraphicsScene::updateCurves (
CmdMediator &cmdMediator)
295 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateCurves";
298 QStringList curveNames;
299 curveNames << AXIS_CURVE_NAME;
308 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateCurveStyles";
316 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updateGraphicsLinesToMatchGraphicsPoints";
326 QPainterPath pathMultiValued;
333 updatePathItemMultiValued (pathMultiValued,
338 void GraphicsScene::updatePathItemMultiValued (
const QPainterPath &pathMultiValued,
342 int lineWidth = lineMultiValued.
width();
345 delete m_pathItemMultiValued;
346 m_pathItemMultiValued = this->addPath (pathMultiValued);
347 m_pathItemMultiValued->setPen (QPen (QBrush (QColor (Qt::red)),
350 m_pathItemMultiValued->setAcceptHoverEvents (
true);
351 m_pathItemMultiValued->setToolTip (tr (
"Function currently has multiple Y values for one X value. Please adjust nearby points, " 352 "or change the curve type in Curve Properties"));
355 void GraphicsScene::updatePointMembership (
CmdMediator &cmdMediator,
359 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsScene::updatePointMembership";
365 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
381 QPainterPath pathMultiValued;
387 updatePathItemMultiValued (pathMultiValued,
void updateGraphicsLinesToMatchGraphicsPoints(const CurveStyles &curveStyles, SplineDrawer &splineDrawer, QPainterPath &pathMultiValued, LineStyle &lineMultiValued)
Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.
void updateGraphicsLinesToMatchGraphicsPoints(const CurveStyles &modelCurveStyles, const Transformation &transformation)
A mouse move has just occurred so move the selected points, since they were dragged.
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 printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
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.
unsigned int width() const
Width of line.
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.
void addTemporaryScaleBar(GraphicsPoint *point0, GraphicsPoint *point1, const QString &pointIdentifier0, const QString &pointIdentifier1)
Add temporary scale bar to scene.
void removeTemporaryScaleBarIfExists()
Remove temporary scale bar, composed of two points and the line between them.
void removeTemporaryPointIfExists()
Remove temporary point if it exists.
Window that displays the geometry information, as a table, for the current curve. ...
QStringList positionHasChangedPointIdentifiers() const
Return a list of identifiers for the points that have moved since the last call to resetPositionHasCh...
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
CallbackSearchReturn callback(const QString &, const Point &point)
Callback method.
void updateAfterCommand(CmdMediator &cmdMediator, double highlightOpacity, GeometryWindow *geometryWindow, const Transformation &transformation)
Update the Points and their Curves after executing a command.
GraphicsPoint * createPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const PointStyle &pointStyle, GeometryWindow *geometryWindow)
Create circle or polygon point according to the PointStyle.
void updatePointOrdinalsAfterDrag(const CurveStyles &curveStyles, const Transformation &transformation)
See GraphicsScene::updateOrdinalsAfterDrag.
GraphicsPoint * createPoint(const QString &identifier, const PointStyle &pointStyle, const QPointF &posScreen, GeometryWindow *geometryWindow)
Create one QGraphicsItem-based object that represents one Point. It is NOT added to m_graphicsLinesFo...
Details for a specific Point.
virtual ~GraphicsScene()
Virtual destructor needed since using Q_OBJECT.
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.
Details for a specific Line.
void lineMembershipPurge(const CurveStyles &curveStyles, SplineDrawer &splineDrawer, QPainterPath &pathMultiValued, LineStyle &lineMultiValued)
Mark the end of addPoint calls. Remove stale lines, insert missing lines, and draw the graphics lines...
Graphics item for drawing a circular or polygonal Point.
void updateCurveStyles(const CurveStyles &modelCurveStyles)
Update curve styles after settings changed.
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.
This class takes the output from Spline and uses that to draw the curve in the graphics window...
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
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);...
void updateHighlightOpacity(double highlightOpacity)
Update the highlight opacity value. This may or may not affect the current display immediately depend...
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...