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>
31 #include <QtToString.h>
32 #include "Transformation.h"
35 const QString MOVE_TEXT_DOWN (QObject::tr (
"Move down"));
36 const QString MOVE_TEXT_LEFT (QObject::tr (
"Move left"));
37 const QString MOVE_TEXT_RIGHT (QObject::tr (
"Move right"));
38 const QString MOVE_TEXT_UP (QObject::tr (
"Move up"));
45 DigitizeStateSelect::~DigitizeStateSelect ()
54 void DigitizeStateSelect::addHoverHighlighting()
56 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::addHoverHighlighting";
59 QList<QGraphicsItem*>::iterator itr;
60 for (itr = items.begin (); itr != items.end (); itr++) {
62 QGraphicsItem *item = *itr;
63 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
64 item->setAcceptHoverEvents(
true);
72 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::begin";
77 addHoverHighlighting();
89 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::cursor";
91 return QCursor (Qt::ArrowCursor);
96 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::end";
98 removeHoverHighlighting();
102 const QString &pointIdentifier)
104 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventAxis "
105 <<
" point=" << pointIdentifier.toLatin1 ().data ();
108 handleContextMenuEventAxis2 (cmdMediator);
110 handleContextMenuEventAxis34 (cmdMediator,
115 void DigitizeStateSelect::handleContextMenuEventAxis2 (
CmdMediator *cmdMediator)
117 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventAxis2";
119 const bool IS_NOT_X_ONLY =
false;
123 QString pointIdentifier = scaleBarPointIdentifier (cmdMediator);
129 double scaleLength = scaleBarLength (cmdMediator);
135 int rtn = dlg->exec ();
140 if (rtn == QDialog::Accepted) {
145 QString errorMessage;
147 bool isXNonzero = (qAbs (posGraphBefore.x()) > 0);
148 QPointF posGraphAfter (isXNonzero ? scaleLength : 0,
149 isXNonzero ? 0 : scaleLength);
158 QMessageBox::warning (
nullptr,
159 engaugeWindowTitle(),
177 void DigitizeStateSelect::handleContextMenuEventAxis34 (
CmdMediator *cmdMediator,
178 const QString &pointIdentifier)
180 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventAxis34";
187 double x = posGraphBefore.x();
188 double y = posGraphBefore.y();
199 int rtn = dlg->exec ();
201 QPointF posGraphAfter = dlg->
posGraph (isXOnly);
204 if (rtn == QDialog::Accepted) {
209 QString errorMessage;
219 QMessageBox::warning (
nullptr,
220 engaugeWindowTitle(),
239 const QStringList &pointIdentifiers)
241 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleContextMenuEventGraph "
242 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
244 double *x =
nullptr, *y =
nullptr;
246 if (pointIdentifiers.count() == 1) {
253 QPointF posGraphBefore;
258 *x = posGraphBefore.x();
259 *y = posGraphBefore.y();
275 int rtn = dlg->exec ();
277 bool isXGiven, isYGiven;
278 double xGiven, yGiven;
279 dlg->
posGraph (isXGiven, xGiven, isYGiven, yGiven);
282 if (rtn == QDialog::Accepted) {
299 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleCurveChange";
304 bool atLeastOneSelectedItem)
306 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleKeyPress"
307 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
309 if (atLeastOneSelectedItem) {
311 if (key == Qt::Key_Down ||
313 key == Qt::Key_Left ||
314 key == Qt::Key_Right) {
316 keyPressArrow (cmdMediator,
332 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMousePress"
333 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
337 m_movingStart = posScreen;
343 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMouseRelease"
344 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
346 QPointF deltaScreen = posScreen - m_movingStart;
349 bool positionHasChanged = (positionHasChangedIdentifers.count () > 0);
351 if (positionHasChanged && (
352 qAbs (deltaScreen.x ()) > 0 ||
353 qAbs (deltaScreen.y ()) > 0)) {
355 QString moveText = moveTextFromDeltaScreen (deltaScreen);
362 positionHasChangedIdentifers);
371 showCoordinatesIfSinglePointIsSelected ();
375 void DigitizeStateSelect::keyPressArrow (
CmdMediator *cmdMediator,
382 deltaScreen = QPointF (0, zoomedToUnzoomedScreenY ());
383 moveText = MOVE_TEXT_DOWN;
387 deltaScreen = QPointF (-1 * zoomedToUnzoomedScreenX (), 0);
388 moveText = MOVE_TEXT_LEFT;
392 deltaScreen = QPointF (zoomedToUnzoomedScreenX (), 0);
393 moveText = MOVE_TEXT_RIGHT;
397 deltaScreen = QPointF (0, -1 * zoomedToUnzoomedScreenY ());
398 moveText = MOVE_TEXT_UP;
402 ENGAUGE_ASSERT (
false);
417 QString DigitizeStateSelect::moveTextFromDeltaScreen (
const QPointF &deltaScreen)
426 bool downOrRight = (deltaScreen.y () > -1.0 * deltaScreen.x ());
427 bool upOrRight = (deltaScreen.y () < deltaScreen.x ());
428 if (downOrRight && upOrRight) {
429 moveText = MOVE_TEXT_RIGHT;
430 }
else if (downOrRight && !upOrRight) {
431 moveText = MOVE_TEXT_DOWN;
432 }
else if (!downOrRight && upOrRight) {
433 moveText = MOVE_TEXT_UP;
435 moveText = MOVE_TEXT_LEFT;
441 void DigitizeStateSelect::removeHoverHighlighting()
443 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::removeHoverHighlighting";
446 QList<QGraphicsItem*>::iterator itr;
447 for (itr = items.begin (); itr != items.end (); itr++) {
449 QGraphicsItem *item = *itr;
450 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
451 item->setAcceptHoverEvents(
false);
456 double DigitizeStateSelect::scaleBarLength (
CmdMediator *cmdMediator)
const
460 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
467 QString DigitizeStateSelect::scaleBarPointIdentifier (
CmdMediator *cmdMediator)
const
471 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
478 void DigitizeStateSelect::setHoverHighlighting(
const MainWindowModel &modelMainWindow)
480 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::addHoverHighlighting";
484 QList<QGraphicsItem*>::iterator itr;
485 for (itr = items.begin (); itr != items.end (); itr++) {
487 QGraphicsItem *item = *itr;
488 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
494 void DigitizeStateSelect::showCoordinatesIfSinglePointIsSelected ()
498 if (items.size () == 1) {
501 QGraphicsItem *item = * (items.begin ());
503 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
506 QString coordsScreen, coordsGraph, resolutionGraph;
520 return "DigitizeStateSelect";
525 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateAfterPointAddition";
527 addHoverHighlighting ();
533 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelDigitizeCurve";
538 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelSegments";
541 double DigitizeStateSelect::zoomedToUnzoomedScreenX ()
const
547 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.
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
Callback for identifying, for the scale bar of a map, various quantities.
double scaleBarLength() const
Length of scale bar.
virtual bool canPaste(const Transformation &transformation, const QSize &viewSize) const
Return true if there is good data in the clipboard for pasting, and that is compatible with the curre...
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...
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.
bool modeMap() const
True if document scale is set using a scale bar, otherwise using axis points.
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 showTemporaryMessage(const QString &temporaryMessage)
Show temporary message in status bar.
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...
QString scaleBarPointIdentifier() const
Identified axis point.
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.
double scaleLength() const
Return the scale bar length specified by the user. Only applies if dialog was accepted.
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.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.