Engauge Digitizer 2
Loading...
Searching...
No Matches
Guidelines Class Reference

This class contains all Guideline objects. More...

#include <Guidelines.h>

Collaboration diagram for Guidelines:
Collaboration graph

Public Member Functions

 Guidelines (MainWindow &mainWindow)
 Single constructor.
 ~Guidelines ()
void clear ()
 Remove guidelines since the current Document is about to be closed.
ColorPalette color () const
 Color to be used for guidelines.
CoordsType coordsType () const
 Return cartesian or polar.
GuidelineAbstractcreateGuideline (const QString &identifier, GuidelineState stateInitial)
 Factory method for creating a new Guideline.
void createGuidelineR (const QString &identifier, double r)
 Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_R_ACTIVE.
void createGuidelineR (const QString &identifier, const QPointF &posScreen)
 Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_R_ACTIVE.
void createGuidelineT (const QString &identifier, double t)
 Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_T_ACTIVE.
void createGuidelineT (const QString &identifier, const QPointF &posScreen)
 Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_T_ACTIVE.
void createGuidelineX (const QString &identifier, double x)
 Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_X_ACTIVE.
void createGuidelineX (const QString &identifier, const QPointF &posScreen)
 Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_X_ACTIVE.
void createGuidelineY (const QString &identifier, double y)
 Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_ACTIVE.
void createGuidelineY (const QString &identifier, const QPointF &posScreen)
 Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_ACTIVE.
void createReplacementGuideline (const QString &identifierReplaced, double newValue, GuidelineState guidelineStateForReplacement)
 Factory method for creating a new replacement Guideline, which replaces one handle and one visible Guideline after a drag.
void handleActiveChange (bool active)
 DigitizeState change so active status may (or may not) be toggled.
void handleGuidelineMode (bool visible, bool locked)
 User toggled guideline mode.
void initialize (GraphicsScene &scene)
 Initialize Guideline factory.
void moveGuidelineXT (const QString &identifier, double valueAfter)
 Move an X/T guideline from one value to another. Closest value wins.
void moveGuidelineYR (const QString &identifier, double valueAfter)
 Move an Y/R guideline from one value to another. Closest value wins.
void removeGuideline (const QString &identifier)
 Remove an X/T or Y/R guideline.
void setModelGuideline (CoordsType coordsType, const DocumentModelGuideline &modelGuideline)
 Load Guidelines from Document.
QString stateDump () const
 States listed as a string for debugging only.
Transformation transformation () const
 Return copy of transformation owned by MainWindow.
void updateColor ()
 Force a color update.
DocumentModelGuideline updateValues (const DocumentModelGuideline &modelGuidelineOld) const
 Updates the guideline values for later storing in Document. Only the values are updated.
void updateWithLatestTransformation ()
 Update transformation. This is called after a command has been executed.

Friends

class TestGuidelines
 For unit testing.

Detailed Description

This class contains all Guideline objects.

Definition at line 27 of file Guidelines.h.

Constructor & Destructor Documentation

◆ Guidelines()

Guidelines::Guidelines ( MainWindow & mainWindow)

Single constructor.

Definition at line 27 of file Guidelines.cpp.

27 :
28 m_mainWindow (mainWindow),
29 m_guidelineFactory (nullptr)
30{
31}

◆ ~Guidelines()

Guidelines::~Guidelines ( )

Definition at line 33 of file Guidelines.cpp.

34{
35 clear ();
36 delete m_guidelineFactory;
37}
void clear()
Remove guidelines since the current Document is about to be closed.

Member Function Documentation

◆ clear()

void Guidelines::clear ( )

Remove guidelines since the current Document is about to be closed.

Definition at line 39 of file Guidelines.cpp.

40{
41 GuidelineContainerPrivate::iterator itr;
42
43 for (itr = m_guidelineContainerXT.begin(); itr != m_guidelineContainerXT.end(); itr++) {
44 GuidelineAbstract *guideline = *itr;
45
46 // Remove the guideline from its scene
47 QGraphicsScene *scene = &guideline->scene();
48
49 if (scene != nullptr) {
50
51 guideline->removeFromScene (scene);
52
53 }
54 }
55
56 for (itr = m_guidelineContainerYR.begin(); itr != m_guidelineContainerYR.end(); itr++) {
57 GuidelineAbstract *guideline = *itr;
58
59 // Remove the guideline from its scene
60 QGraphicsScene *scene = &guideline->scene();
61
62 if (scene != nullptr) {
63
64 guideline->removeFromScene (scene);
65
66 }
67 }
68
69 m_guidelineContainerXT.clear ();
70 m_guidelineContainerYR.clear ();
71}
QGraphicsScene & scene()
GraphicsScene that owns this class.
virtual void removeFromScene(QGraphicsScene *scene)=0
Make graphics item remove itself from the scene.

◆ color()

ColorPalette Guidelines::color ( ) const

Color to be used for guidelines.

Definition at line 73 of file Guidelines.cpp.

74{
75 return m_mainWindow.cmdMediator()->document().modelGuideline ().lineColor();
76}

◆ coordsType()

CoordsType Guidelines::coordsType ( ) const

Return cartesian or polar.

Definition at line 78 of file Guidelines.cpp.

79{
80 return m_mainWindow.cmdMediator()->document().modelCoords().coordsType();
81}

◆ createGuideline()

GuidelineAbstract * Guidelines::createGuideline ( const QString & identifier,
GuidelineState stateInitial )

Factory method for creating a new Guideline.

Definition at line 83 of file Guidelines.cpp.

85{
86 LOG4CPP_DEBUG_S ((*mainCat)) << "Guidelines::createGuideline"
87 << " identifier=" << identifier.toLatin1().data()
88 << " state=" << guidelineStateAsString (stateInitial).toLatin1().data();
89
90 GuidelineAbstract *guideline = m_guidelineFactory->createGuideline (*this,
91 stateInitial,
92 m_mainWindow,
93 identifier);
94
95 return guideline;
96}
QString guidelineStateAsString(GuidelineState state)
log4cpp::Category * mainCat
Definition Logger.cpp:14
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20

◆ createGuidelineR() [1/2]

void Guidelines::createGuidelineR ( const QString & identifier,
const QPointF & posScreen )

Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_R_ACTIVE.

Definition at line 110 of file Guidelines.cpp.

112{
113 GuidelineAbstract *guideline = createGuideline (identifier,
115 if (guideline) {
116 guideline->updateGeometry (posScreen);
117 }
118
119 m_guidelineContainerYR.append (guideline);
120}
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT_APPEARING
virtual void updateGeometry(double valueGraph)=0
Update the geometry so it passes through the specified coordinate value in graph coordinates.
GuidelineAbstract * createGuideline(const QString &identifier, GuidelineState stateInitial)
Factory method for creating a new Guideline.

◆ createGuidelineR() [2/2]

void Guidelines::createGuidelineR ( const QString & identifier,
double r )

Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_R_ACTIVE.

Definition at line 98 of file Guidelines.cpp.

100{
101 GuidelineAbstract *guideline = createGuideline (identifier,
103 if (guideline) {
104 guideline->updateGeometry (r);
105 }
106
107 m_guidelineContainerYR.append (guideline);
108}

◆ createGuidelineT() [1/2]

void Guidelines::createGuidelineT ( const QString & identifier,
const QPointF & posScreen )

Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_T_ACTIVE.

Definition at line 134 of file Guidelines.cpp.

136{
137 GuidelineAbstract *guideline = createGuideline (identifier,
139 if (guideline) {
140 guideline->updateGeometry (posScreen);
141 }
142
143 m_guidelineContainerXT.append (guideline);
144}
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT_APPEARING

◆ createGuidelineT() [2/2]

void Guidelines::createGuidelineT ( const QString & identifier,
double t )

Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_T_ACTIVE.

Definition at line 122 of file Guidelines.cpp.

124{
125 GuidelineAbstract *guideline = createGuideline (identifier,
127 if (guideline) {
128 guideline->updateGeometry (t);
129 }
130
131 m_guidelineContainerXT.append (guideline);
132}

◆ createGuidelineX() [1/2]

void Guidelines::createGuidelineX ( const QString & identifier,
const QPointF & posScreen )

Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_X_ACTIVE.

Definition at line 158 of file Guidelines.cpp.

160{
161 GuidelineAbstract *guideline = createGuideline (identifier,
163 if (guideline) {
164 guideline->updateGeometry (posScreen);
165 }
166
167 m_guidelineContainerXT.append (guideline);
168}
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT_APPEARING

◆ createGuidelineX() [2/2]

void Guidelines::createGuidelineX ( const QString & identifier,
double x )

Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_X_ACTIVE.

Definition at line 146 of file Guidelines.cpp.

148{
149 GuidelineAbstract *guideline = createGuideline (identifier,
151 if (guideline) {
152 guideline->updateGeometry (x);
153 }
154
155 m_guidelineContainerXT.append (guideline);
156}

◆ createGuidelineY() [1/2]

void Guidelines::createGuidelineY ( const QString & identifier,
const QPointF & posScreen )

Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_ACTIVE.

Definition at line 182 of file Guidelines.cpp.

184{
185 GuidelineAbstract *guideline = createGuideline (identifier,
187 if (guideline) {
188 guideline->updateGeometry (posScreen);
189 }
190
191 m_guidelineContainerYR.append (guideline);
192}
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT_APPEARING

◆ createGuidelineY() [2/2]

void Guidelines::createGuidelineY ( const QString & identifier,
double y )

Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_ACTIVE.

Definition at line 170 of file Guidelines.cpp.

172{
173 GuidelineAbstract *guideline = createGuideline (identifier,
175 if (guideline) {
176 guideline->updateGeometry (y);
177 }
178
179 m_guidelineContainerYR.append (guideline);
180}

◆ createReplacementGuideline()

void Guidelines::createReplacementGuideline ( const QString & identifierReplaced,
double newValue,
GuidelineState guidelineStateForReplacement )

Factory method for creating a new replacement Guideline, which replaces one handle and one visible Guideline after a drag.

Definition at line 194 of file Guidelines.cpp.

197{
198 LOG4CPP_DEBUG_S ((*mainCat)) << "Guidelines::createReplacementGuideline";
199
200 // Out with the old. Since it is still on the stack we only unregister, versus remove, it
201 unregisterGuideline (identifierReplaced);
202
203 // And in with the new
204 switch (guidelineStateForReplacement) {
206 createGuidelineR (identifierReplaced,
207 newValue);
208 break;
209
211 createGuidelineT(identifierReplaced,
212 newValue);
213 break;
214
216 createGuidelineX(identifierReplaced,
217 newValue);
218 break;
219
221 createGuidelineY(identifierReplaced,
222 newValue);
223 break;
224
225 default:
226 LOG4CPP_ERROR_S ((*mainCat)) << "Guidelines::createReplacementGuideline encountered unexpected state "
227 << guidelineStateAsString (guidelineStateForReplacement).toLatin1().data();
228
229 }
230}
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT
void createGuidelineY(const QString &identifier, double y)
Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_ACTIVE.
void createGuidelineR(const QString &identifier, double r)
Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_R_ACTIVE.
void createGuidelineT(const QString &identifier, double t)
Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_T_ACTIVE.
void createGuidelineX(const QString &identifier, double x)
Factory method for creating a new GUIDELINE_STATE_DEPLOYED_CONSTANT_X_ACTIVE.
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12

◆ handleActiveChange()

void Guidelines::handleActiveChange ( bool active)

DigitizeState change so active status may (or may not) be toggled.

Definition at line 276 of file Guidelines.cpp.

277{
278 GuidelineContainerPrivate::iterator itr;
279
280 for (itr = m_guidelineContainerXT.begin(); itr != m_guidelineContainerXT.end(); itr++) {
281 GuidelineAbstract *guideline = *itr;
282
283 guideline->handleActiveChange (active);
284 }
285
286 for (itr = m_guidelineContainerYR.begin(); itr != m_guidelineContainerYR.end(); itr++) {
287 GuidelineAbstract *guideline = *itr;
288
289 guideline->handleActiveChange (active);
290 }
291}
void handleActiveChange(bool active)
DigitizeState change so active status may (or may not) be toggled.

◆ handleGuidelineMode()

void Guidelines::handleGuidelineMode ( bool visible,
bool locked )

User toggled guideline mode.

Definition at line 293 of file Guidelines.cpp.

295{
296 GuidelineContainerPrivate::iterator itr;
297
298 for (itr = m_guidelineContainerXT.begin(); itr != m_guidelineContainerXT.end(); itr++) {
299 GuidelineAbstract *guideline = *itr;
300
301 guideline->handleGuidelineMode (visible,
302 isLocked);
303 }
304
305 for (itr = m_guidelineContainerYR.begin(); itr != m_guidelineContainerYR.end(); itr++) {
306 GuidelineAbstract *guideline = *itr;
307
308 guideline->handleGuidelineMode (visible,
309 isLocked);
310 }
311}
void handleGuidelineMode(bool visible, bool locked)
User toggled Guideline visibility and/or locked mode.

◆ initialize()

void Guidelines::initialize ( GraphicsScene & scene)

Initialize Guideline factory.

Definition at line 313 of file Guidelines.cpp.

314{
315 m_guidelineFactory = new GuidelineFactory (&scene);
316}

◆ moveGuidelineXT()

void Guidelines::moveGuidelineXT ( const QString & identifier,
double valueAfter )

Move an X/T guideline from one value to another. Closest value wins.

Definition at line 346 of file Guidelines.cpp.

348{
349 LOG4CPP_DEBUG_S ((*mainCat)) << "Guidelines::moveGuidelineXT"
350 << " identifier=" << identifier.toLatin1().data()
351 << " value=" << valueAfter;
352
353 GuidelineContainerPrivate::iterator itr = findIdentifierXT (identifier);
354
355 if (itr== m_guidelineContainerXT.end ()) {
356 LOG4CPP_ERROR_S ((*mainCat)) << "Guidelines::moveGuidelineXT";
357 } else {
358 // Move it
359 GuidelineAbstract *guideline = *itr;
360 guideline->updateGeometry (valueAfter);
361 }
362}

◆ moveGuidelineYR()

void Guidelines::moveGuidelineYR ( const QString & identifier,
double valueAfter )

Move an Y/R guideline from one value to another. Closest value wins.

Definition at line 364 of file Guidelines.cpp.

366{
367 LOG4CPP_DEBUG_S ((*mainCat)) << "Guidelines::moveGuidelineYR"
368 << " identifier=" << identifier.toLatin1().data()
369 << " value=" << valueAfter;
370
371 GuidelineContainerPrivate::iterator itr = findIdentifierYR (identifier);
372
373 if (itr == m_guidelineContainerYR.end ()) {
374 LOG4CPP_ERROR_S ((*mainCat)) << "Guidelines::moveGuidelineYR";
375 } else {
376 // Move it
377 GuidelineAbstract *guideline = *itr;
378 guideline->updateGeometry (valueAfter);
379 }
380}

◆ removeGuideline()

void Guidelines::removeGuideline ( const QString & identifier)

Remove an X/T or Y/R guideline.

Since Guideline identifiers are unique this method is not implemented with separate X/T and Y/R versions

Definition at line 392 of file Guidelines.cpp.

393{
394 LOG4CPP_DEBUG_S ((*mainCat)) << "Guidelines::removeGuideline"
395 << " identifier=" << identifier.toLatin1().data();
396
397 GuidelineAbstract *guideline = unregisterGuideline (identifier);
398
399 if (guideline != nullptr) {
400 delete guideline;
401 }
402}

◆ setModelGuideline()

void Guidelines::setModelGuideline ( CoordsType coordsType,
const DocumentModelGuideline & modelGuideline )

Load Guidelines from Document.

Definition at line 404 of file Guidelines.cpp.

406{
407 clear ();
408
409 GuidelineValues valuesXT = modelGuideline.valuesX();
410 GuidelineValues valuesYR = modelGuideline.valuesY();
411
412 GuidelineValues::const_iterator itr;
413
414 for (itr = valuesXT.begin(); itr != valuesXT.end(); itr++) {
415 QString identifier = itr.key();
416 double value = itr.value();
417
419 createGuidelineX (identifier,
420 value);
421 } else {
422 createGuidelineT (identifier,
423 value);
424 }
425 }
426
427 for (itr = valuesYR.begin(); itr != valuesYR.end(); itr++) {
428 QString identifier = itr.key();
429 double value = itr.value();
430
432 createGuidelineY (identifier,
433 value);
434 } else {
435 createGuidelineR (identifier,
436 value);
437 }
438 }
439}
@ COORDS_TYPE_CARTESIAN
Definition CoordsType.h:13
QMap< QString, double > GuidelineValues
GuidelineValues valuesY() const
Get method for y/r values.
GuidelineValues valuesX() const
Get method for x/t values.
CoordsType coordsType() const
Return cartesian or polar.

◆ stateDump()

QString Guidelines::stateDump ( ) const

States listed as a string for debugging only.

Definition at line 441 of file Guidelines.cpp.

442{
443 // Sort the entries
444 QStringList sortedXT, sortedYR;
445 GuidelineContainerPrivate::const_iterator itrSort;
446
447 for (itrSort = m_guidelineContainerXT.begin(); itrSort != m_guidelineContainerXT.end(); itrSort++) {
448 GuidelineAbstract *guideline = *itrSort;
449 sortedXT << guideline->stateDump ();
450 }
451
452 for (itrSort = m_guidelineContainerYR.begin(); itrSort != m_guidelineContainerYR.end(); itrSort++) {
453 GuidelineAbstract *guideline = *itrSort;
454 sortedYR << guideline->stateDump ();
455 }
456
457 std::sort (sortedXT.begin(),
458 sortedXT.end());
459 std::sort (sortedYR.begin(),
460 sortedYR.end());
461
462 // Convert entries to output text
463 QString out;
464 QTextStream str (&out);
465
466 str << "Guidelines::stateDump:\n";
467
468 QStringList::const_iterator itrOut;
469
470 for (itrOut = sortedXT.begin(); itrOut != sortedXT.end(); itrOut++) {
471 QString entry = *itrOut;
472 str << " " << entry << "\n";
473 }
474
475 for (itrOut = sortedYR.begin(); itrOut != sortedYR.end(); itrOut++) {
476 QString entry = *itrOut;
477 str << " " << entry << "\n";
478 }
479
480 return out;
481}
QString stateDump() const
Dump of state as a string for debugging only. Context like the QGraphicsItem flags is included.

◆ transformation()

Transformation Guidelines::transformation ( ) const

Return copy of transformation owned by MainWindow.

Definition at line 483 of file Guidelines.cpp.

484{
485 return m_mainWindow.transformation ();
486}

◆ updateColor()

void Guidelines::updateColor ( )

Force a color update.

Definition at line 514 of file Guidelines.cpp.

515{
516 GuidelineContainerPrivate::const_iterator itr;
517
518 for (itr = m_guidelineContainerXT.begin(); itr != m_guidelineContainerXT.end(); itr++) {
519 GuidelineAbstract *guideline = *itr;
520 guideline->updateColor ();
521 }
522
523 for (itr = m_guidelineContainerYR.begin(); itr != m_guidelineContainerYR.end(); itr++) {
524 GuidelineAbstract *guideline = *itr;
525 guideline->updateColor ();
526 }
527}
virtual void updateColor()=0
Force a color update.

◆ updateValues()

DocumentModelGuideline Guidelines::updateValues ( const DocumentModelGuideline & modelGuidelineOld) const

Updates the guideline values for later storing in Document. Only the values are updated.

Definition at line 318 of file Guidelines.cpp.

319{
320 GuidelineValues valuesXT, valuesYR;
321
322 GuidelineContainerPrivate::const_iterator itr;
323
324 for (itr = m_guidelineContainerXT.begin(); itr != m_guidelineContainerXT.end(); itr++) {
325 const GuidelineAbstract *guideline = *itr;
326 QString identifier = guideline->identifier();
327 double value = guideline->posCursorGraph().x();
328 valuesXT [identifier] = value;
329 }
330
331 for (itr = m_guidelineContainerYR.begin(); itr != m_guidelineContainerYR.end(); itr++) {
332 const GuidelineAbstract *guideline = *itr;
333 QString identifier = guideline->identifier();
334 double value = guideline->posCursorGraph().y();
335 valuesYR [identifier] = value;
336 }
337
338 // Returned model
339 DocumentModelGuideline modelGuidelineNew (modelGuidelineOld);
340 modelGuidelineNew.setValuesX (valuesXT);
341 modelGuidelineNew.setValuesY (valuesYR);
342
343 return modelGuidelineNew;
344}
virtual QString identifier() const =0
Unique identifier from QGraphicsItem.
QPointF posCursorGraph() const
Get position in graph coordinates.

◆ updateWithLatestTransformation()

void Guidelines::updateWithLatestTransformation ( )

Update transformation. This is called after a command has been executed.

Definition at line 529 of file Guidelines.cpp.

530{
531 GuidelineContainerPrivate::iterator itr;
532
533 for (itr = m_guidelineContainerXT.begin(); itr != m_guidelineContainerXT.end(); itr++) {
534 GuidelineAbstract *guideline = *itr;
535 guideline->updateWithLatestTransformation ();
536 }
537
538 for (itr = m_guidelineContainerYR.begin(); itr != m_guidelineContainerYR.end(); itr++) {
539 GuidelineAbstract *guideline = *itr;
540 guideline->updateWithLatestTransformation ();
541 }
542}
void updateWithLatestTransformation()
Update given Transformation in GuidelineStateContext. This is called after a command has been execute...

◆ TestGuidelines

friend class TestGuidelines
friend

For unit testing.

Definition at line 30 of file Guidelines.h.


The documentation for this class was generated from the following files: