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();
114 int rtn = dlg->exec ();
116 QPointF posGraphAfter = dlg->
posGraph (isXOnly);
119 if (rtn == QDialog::Accepted) {
124 QString errorMessage;
134 QMessageBox::warning (0,
135 engaugeWindowTitle(),
154 const QStringList &pointIdentifiers)
156 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventGraph " 157 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
159 double *x = 0, *y = 0;
161 if (pointIdentifiers.count() == 1) {
168 QPointF posGraphBefore;
173 *x = posGraphBefore.x();
174 *y = posGraphBefore.y();
194 int rtn = dlg->exec ();
196 bool isXGiven, isYGiven;
197 double xGiven, yGiven;
198 dlg->
posGraph (isXGiven, xGiven, isYGiven, yGiven);
201 if (rtn == QDialog::Accepted) {
218 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleCurveChange";
223 bool atLeastOneSelectedItem)
225 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleKeyPress" 226 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
228 if (atLeastOneSelectedItem) {
230 if (key == Qt::Key_Down ||
232 key == Qt::Key_Left ||
233 key == Qt::Key_Right) {
235 keyPressArrow (cmdMediator,
251 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMousePress" 252 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
256 m_movingStart = posScreen;
262 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMouseRelease" 263 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
265 QPointF deltaScreen = posScreen - m_movingStart;
268 bool positionHasChanged = (positionHasChangedIdentifers.count () > 0);
270 if (positionHasChanged && (
271 deltaScreen.x () != 0 ||
272 deltaScreen.y () != 0)) {
274 QString moveText = moveTextFromDeltaScreen (deltaScreen);
281 positionHasChangedIdentifers);
293 void DigitizeStateSelect::keyPressArrow (
CmdMediator *cmdMediator,
300 deltaScreen = QPointF (0, zoomedToUnzoomedScreenY ());
301 moveText = MOVE_TEXT_DOWN;
305 deltaScreen = QPointF (-1 * zoomedToUnzoomedScreenX (), 0);
306 moveText = MOVE_TEXT_LEFT;
310 deltaScreen = QPointF (zoomedToUnzoomedScreenX (), 0);
311 moveText = MOVE_TEXT_RIGHT;
315 deltaScreen = QPointF (0, -1 * zoomedToUnzoomedScreenY ());
316 moveText = MOVE_TEXT_UP;
320 ENGAUGE_ASSERT (
false);
335 QString DigitizeStateSelect::moveTextFromDeltaScreen (
const QPointF &deltaScreen)
344 bool downOrRight = (deltaScreen.y () > -1.0 * deltaScreen.x ());
345 bool upOrRight = (deltaScreen.y () < deltaScreen.x ());
346 if (downOrRight && upOrRight) {
347 moveText = MOVE_TEXT_RIGHT;
348 }
else if (downOrRight && !upOrRight) {
349 moveText = MOVE_TEXT_DOWN;
350 }
else if (!downOrRight && upOrRight) {
351 moveText = MOVE_TEXT_UP;
353 moveText = MOVE_TEXT_LEFT;
359 void DigitizeStateSelect::removeHoverHighlighting()
361 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::removeHoverHighlighting";
364 QList<QGraphicsItem*>::iterator itr;
365 for (itr = items.begin (); itr != items.end (); itr++) {
367 QGraphicsItem *item = *itr;
368 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
369 item->setAcceptHoverEvents(
false);
374 void DigitizeStateSelect::setHoverHighlighting(
const MainWindowModel &modelMainWindow)
376 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::addHoverHighlighting";
380 QList<QGraphicsItem*>::iterator itr;
381 for (itr = items.begin (); itr != items.end (); itr++) {
383 QGraphicsItem *item = *itr;
384 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
392 return "DigitizeStateSelect";
397 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateAfterPointAddition";
399 addHoverHighlighting ();
405 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelDigitizeCurve";
410 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelSegments";
413 double DigitizeStateSelect::zoomedToUnzoomedScreenX ()
const 419 double DigitizeStateSelect::zoomedToUnzoomedScreenY ()
const Dialog box for editing the information of one axis point.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
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...
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
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.
QStringList positionHasChangedPointIdentifiers() const
Return a list of identifiers for the points that have moved since the last call to resetPositionHasCh...
double highlightOpacity() const
Get method for highlight opacity.
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...
virtual QString state() const
State name for debugging.
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.
Transformation transformation() const
Return read-only copy of transformation.
QPointF posGraph(bool &isXOnly) const
Return the graph coordinates position specified by the user. 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.
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 void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
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...
DigitizeStateSelect(DigitizeStateContext &context)
Single constructor.
MainWindowModel modelMainWindow() const
Get method for main window model.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
void posGraph(bool &isX, double &x, bool &isY, double &y) const
Return one or both coordinates. Only applies if dialog was accepted.
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.
QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
Command for editing the graph coordinates one axis point.
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
bool isXOnly(const QString &pointIdentifier) const
See Curve::isXOnly.