7 #include "CmdEditPointAxis.h" 8 #include "CmdEditPointGraph.h" 9 #include "CmdMediator.h" 10 #include "CmdMoveBy.h" 12 #include "DigitizeStateContext.h" 13 #include "DigitizeStateSelect.h" 14 #include "DlgEditPointAxis.h" 15 #include "DlgEditPointGraph.h" 16 #include "EngaugeAssert.h" 17 #include "GraphicsItemsExtractor.h" 18 #include "GraphicsItemType.h" 19 #include "GraphicsScene.h" 20 #include "GraphicsView.h" 22 #include "MainWindow.h" 24 #include <QGraphicsItem> 26 #include <QMessageBox> 28 #include <QtToString.h> 31 const QString MOVE_TEXT_DOWN (QObject::tr (
"Move down"));
32 const QString MOVE_TEXT_LEFT (QObject::tr (
"Move left"));
33 const QString MOVE_TEXT_RIGHT (QObject::tr (
"Move right"));
34 const QString MOVE_TEXT_UP (QObject::tr (
"Move up"));
41 DigitizeStateSelect::~DigitizeStateSelect ()
50 void DigitizeStateSelect::addHoverHighlighting()
52 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::addHoverHighlighting";
55 QList<QGraphicsItem*>::iterator itr;
56 for (itr = items.begin (); itr != items.end (); itr++) {
58 QGraphicsItem *item = *itr;
59 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
60 item->setAcceptHoverEvents(
true);
68 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::begin";
73 addHoverHighlighting();
79 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::cursor";
81 return QCursor (Qt::ArrowCursor);
86 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::end";
88 removeHoverHighlighting();
92 const QString &pointIdentifier)
94 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventAxis " 95 <<
" point=" << pointIdentifier.toLatin1 ().data ();
102 double x = posGraphBefore.x();
103 double y = posGraphBefore.y();
113 int rtn = dlg->exec ();
115 QPointF posGraphAfter = dlg->
posGraph (isXOnly);
118 if (rtn == QDialog::Accepted) {
123 QString errorMessage;
133 QMessageBox::warning (0,
134 engaugeWindowTitle(),
153 const QStringList &pointIdentifiers)
155 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventGraph " 156 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
158 double *x = 0, *y = 0;
160 if (pointIdentifiers.count() == 1) {
167 QPointF posGraphBefore;
172 *x = posGraphBefore.x();
173 *y = posGraphBefore.y();
192 int rtn = dlg->exec ();
194 bool isXGiven, isYGiven;
195 double xGiven, yGiven;
196 dlg->
posGraph (isXGiven, xGiven, isYGiven, yGiven);
199 if (rtn == QDialog::Accepted) {
216 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleCurveChange";
221 bool atLeastOneSelectedItem)
223 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleKeyPress" 224 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
226 if (atLeastOneSelectedItem) {
228 if (key == Qt::Key_Down ||
230 key == Qt::Key_Left ||
231 key == Qt::Key_Right) {
233 keyPressArrow (cmdMediator,
249 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMousePress" 250 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
254 m_movingStart = posScreen;
260 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMouseRelease" 261 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
263 QPointF deltaScreen = posScreen - m_movingStart;
266 bool positionHasChanged = (positionHasChangedIdentifers.count () > 0);
268 if (positionHasChanged && (
269 deltaScreen.x () != 0 ||
270 deltaScreen.y () != 0)) {
272 QString moveText = moveTextFromDeltaScreen (deltaScreen);
279 positionHasChangedIdentifers);
291 void DigitizeStateSelect::keyPressArrow (
CmdMediator *cmdMediator,
298 deltaScreen = QPointF (0, zoomedToUnzoomedScreenY ());
299 moveText = MOVE_TEXT_DOWN;
303 deltaScreen = QPointF (-1 * zoomedToUnzoomedScreenX (), 0);
304 moveText = MOVE_TEXT_LEFT;
308 deltaScreen = QPointF (zoomedToUnzoomedScreenX (), 0);
309 moveText = MOVE_TEXT_RIGHT;
313 deltaScreen = QPointF (0, -1 * zoomedToUnzoomedScreenY ());
314 moveText = MOVE_TEXT_UP;
318 ENGAUGE_ASSERT (
false);
333 QString DigitizeStateSelect::moveTextFromDeltaScreen (
const QPointF &deltaScreen)
342 bool downOrRight = (deltaScreen.y () > -1.0 * deltaScreen.x ());
343 bool upOrRight = (deltaScreen.y () < deltaScreen.x ());
344 if (downOrRight && upOrRight) {
345 moveText = MOVE_TEXT_RIGHT;
346 }
else if (downOrRight && !upOrRight) {
347 moveText = MOVE_TEXT_DOWN;
348 }
else if (!downOrRight && upOrRight) {
349 moveText = MOVE_TEXT_UP;
351 moveText = MOVE_TEXT_LEFT;
357 void DigitizeStateSelect::removeHoverHighlighting()
359 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::removeHoverHighlighting";
362 QList<QGraphicsItem*>::iterator itr;
363 for (itr = items.begin (); itr != items.end (); itr++) {
365 QGraphicsItem *item = *itr;
366 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
367 item->setAcceptHoverEvents(
false);
372 void DigitizeStateSelect::setHoverHighlighting(
const MainWindowModel &modelMainWindow)
374 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::addHoverHighlighting";
378 QList<QGraphicsItem*>::iterator itr;
379 for (itr = items.begin (); itr != items.end (); itr++) {
381 QGraphicsItem *item = *itr;
382 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
390 return "DigitizeStateSelect";
395 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateAfterPointAddition";
397 addHoverHighlighting ();
403 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelDigitizeCurve";
408 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelSegments";
411 double DigitizeStateSelect::zoomedToUnzoomedScreenX ()
const 417 double DigitizeStateSelect::zoomedToUnzoomedScreenY ()
const
Dialog box for editing the information of one axis point.
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
bool isXOnly(const QString &pointIdentifier) const
See Curve::isXOnly.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
Transformation transformation() const
Return read-only copy of transformation.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
void updateAfterMouseRelease()
Call MainWindow::updateControls (which is private) after the very specific case - a mouse press/relea...
Command for editing the graph coordinates of one or more graph points.
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Command for moving all selected Points by a specified translation.
virtual void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
QPointF posGraph(bool &isXOnly) const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted...
CmdMediator * cmdMediator()
Accessor for commands to process the Document.
virtual void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity...
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
void checkEditPointAxis(const QString &pointIdentifier, const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage)
Check before calling editPointAxis.
void posGraph(bool &isX, double &x, bool &isY, double &y) const
Return one or both coordinates. Only applies if dialog was accepted.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.
QStringList positionHasChangedPointIdentifiers() const
Return a list of identifiers for the points that have moved since the last call to resetPositionHasCh...
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
Model for DlgSettingsMainWindow.
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
virtual void handleMouseMove(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mod...
QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
double highlightOpacity() const
Get method for highlight opacity.
DigitizeStateSelect(DigitizeStateContext &context)
Single constructor.
Dialog box for editing the information of one or more points.
Model for DlgSettingsSegments and CmdSettingsSegments.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
virtual QString state() const
State name for debugging.
Command for editing the graph coordinates one axis point.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
MainWindowModel modelMainWindow() const
Get method for main window model.