7 #include "CallbackScaleBar.h" 8 #include "CmdEditPointAxis.h" 9 #include "CmdEditPointGraph.h" 10 #include "CmdMediator.h" 11 #include "CmdMoveBy.h" 13 #include "DigitizeStateContext.h" 14 #include "DigitizeStateSelect.h" 15 #include "DlgEditPointAxis.h" 16 #include "DlgEditPointGraph.h" 17 #include "DlgEditScale.h" 18 #include "EngaugeAssert.h" 19 #include "GraphicsItemsExtractor.h" 20 #include "GraphicsItemType.h" 21 #include "GraphicsScene.h" 22 #include "GraphicsView.h" 24 #include "MainWindow.h" 26 #include <QGraphicsItem> 28 #include <QMessageBox> 30 #include <QtToString.h> 33 const QString MOVE_TEXT_DOWN (QObject::tr (
"Move down"));
34 const QString MOVE_TEXT_LEFT (QObject::tr (
"Move left"));
35 const QString MOVE_TEXT_RIGHT (QObject::tr (
"Move right"));
36 const QString MOVE_TEXT_UP (QObject::tr (
"Move up"));
43 DigitizeStateSelect::~DigitizeStateSelect ()
52 void DigitizeStateSelect::addHoverHighlighting()
54 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::addHoverHighlighting";
57 QList<QGraphicsItem*>::iterator itr;
58 for (itr = items.begin (); itr != items.end (); itr++) {
60 QGraphicsItem *item = *itr;
61 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
62 item->setAcceptHoverEvents(
true);
70 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::begin";
75 addHoverHighlighting();
81 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::cursor";
83 return QCursor (Qt::ArrowCursor);
88 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::end";
90 removeHoverHighlighting();
94 const QString &pointIdentifier)
96 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventAxis " 97 <<
" point=" << pointIdentifier.toLatin1 ().data ();
100 handleContextMenuEventAxis2 (cmdMediator);
102 handleContextMenuEventAxis34 (cmdMediator,
107 void DigitizeStateSelect::handleContextMenuEventAxis2 (
CmdMediator *cmdMediator)
109 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventAxis2";
111 const bool IS_NOT_X_ONLY =
false;
115 QString pointIdentifier = scaleBarPointIdentifier (cmdMediator);
121 double scaleLength = scaleBarLength (cmdMediator);
127 int rtn = dlg->exec ();
132 if (rtn == QDialog::Accepted) {
137 QString errorMessage;
139 bool isXNonzero = (posGraphBefore.x() != 0);
140 QPointF posGraphAfter (isXNonzero ? scaleLength : 0,
141 isXNonzero ? 0 : scaleLength);
150 QMessageBox::warning (0,
151 engaugeWindowTitle(),
169 void DigitizeStateSelect::handleContextMenuEventAxis34 (
CmdMediator *cmdMediator,
170 const QString &pointIdentifier)
172 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventAxis34";
179 double x = posGraphBefore.x();
180 double y = posGraphBefore.y();
191 int rtn = dlg->exec ();
193 QPointF posGraphAfter = dlg->
posGraph (isXOnly);
196 if (rtn == QDialog::Accepted) {
201 QString errorMessage;
211 QMessageBox::warning (0,
212 engaugeWindowTitle(),
231 const QStringList &pointIdentifiers)
233 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventGraph " 234 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
236 double *x = 0, *y = 0;
238 if (pointIdentifiers.count() == 1) {
245 QPointF posGraphBefore;
250 *x = posGraphBefore.x();
251 *y = posGraphBefore.y();
271 int rtn = dlg->exec ();
273 bool isXGiven, isYGiven;
274 double xGiven, yGiven;
275 dlg->
posGraph (isXGiven, xGiven, isYGiven, yGiven);
278 if (rtn == QDialog::Accepted) {
295 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleCurveChange";
300 bool atLeastOneSelectedItem)
302 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleKeyPress" 303 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
305 if (atLeastOneSelectedItem) {
307 if (key == Qt::Key_Down ||
309 key == Qt::Key_Left ||
310 key == Qt::Key_Right) {
312 keyPressArrow (cmdMediator,
328 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMousePress" 329 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
333 m_movingStart = posScreen;
339 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMouseRelease" 340 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
342 QPointF deltaScreen = posScreen - m_movingStart;
345 bool positionHasChanged = (positionHasChangedIdentifers.count () > 0);
347 if (positionHasChanged && (
348 deltaScreen.x () != 0 ||
349 deltaScreen.y () != 0)) {
351 QString moveText = moveTextFromDeltaScreen (deltaScreen);
358 positionHasChangedIdentifers);
370 void DigitizeStateSelect::keyPressArrow (
CmdMediator *cmdMediator,
377 deltaScreen = QPointF (0, zoomedToUnzoomedScreenY ());
378 moveText = MOVE_TEXT_DOWN;
382 deltaScreen = QPointF (-1 * zoomedToUnzoomedScreenX (), 0);
383 moveText = MOVE_TEXT_LEFT;
387 deltaScreen = QPointF (zoomedToUnzoomedScreenX (), 0);
388 moveText = MOVE_TEXT_RIGHT;
392 deltaScreen = QPointF (0, -1 * zoomedToUnzoomedScreenY ());
393 moveText = MOVE_TEXT_UP;
397 ENGAUGE_ASSERT (
false);
412 QString DigitizeStateSelect::moveTextFromDeltaScreen (
const QPointF &deltaScreen)
421 bool downOrRight = (deltaScreen.y () > -1.0 * deltaScreen.x ());
422 bool upOrRight = (deltaScreen.y () < deltaScreen.x ());
423 if (downOrRight && upOrRight) {
424 moveText = MOVE_TEXT_RIGHT;
425 }
else if (downOrRight && !upOrRight) {
426 moveText = MOVE_TEXT_DOWN;
427 }
else if (!downOrRight && upOrRight) {
428 moveText = MOVE_TEXT_UP;
430 moveText = MOVE_TEXT_LEFT;
436 void DigitizeStateSelect::removeHoverHighlighting()
438 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::removeHoverHighlighting";
441 QList<QGraphicsItem*>::iterator itr;
442 for (itr = items.begin (); itr != items.end (); itr++) {
444 QGraphicsItem *item = *itr;
445 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
446 item->setAcceptHoverEvents(
false);
451 double DigitizeStateSelect::scaleBarLength (
CmdMediator *cmdMediator)
const 455 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
462 QString DigitizeStateSelect::scaleBarPointIdentifier (
CmdMediator *cmdMediator)
const 466 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
473 void DigitizeStateSelect::setHoverHighlighting(
const MainWindowModel &modelMainWindow)
475 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::addHoverHighlighting";
479 QList<QGraphicsItem*>::iterator itr;
480 for (itr = items.begin (); itr != items.end (); itr++) {
482 QGraphicsItem *item = *itr;
483 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
491 return "DigitizeStateSelect";
496 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateAfterPointAddition";
498 addHoverHighlighting ();
504 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelDigitizeCurve";
509 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelSegments";
512 double DigitizeStateSelect::zoomedToUnzoomedScreenX ()
const 518 double DigitizeStateSelect::zoomedToUnzoomedScreenY ()
const Dialog box for editing the information of one axis point, in a graph with two axes.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
Callback for identifying, for the scale bar of a map, various quantities.
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.
QString scaleBarPointIdentifier() const
Identified axis point.
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...
Dialog box for editing the information of the map scale.
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...
double scaleBarLength() const
Length of scale bar.
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.
double scaleLength() const
Return the scale bar length specified by the user. Only applies if dialog was accepted.
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.