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.
DocumentModelGuidelines modelGuidelines () const
 Return complete set of guidelines information for Document.
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 setModelGuidelines (CoordsType coordsType, const DocumentModelGuidelines &modelGuidelines)
 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.
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.modelMainWindow().guidelineColor();
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}

◆ modelGuidelines()

DocumentModelGuidelines Guidelines::modelGuidelines ( ) const

Return complete set of guidelines information for Document.

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 DocumentModelGuidelines model (valuesXT,
339 valuesYR);
340
341 return model;
342}
QMap< QString, double > GuidelineValues
virtual QString identifier() const =0
Unique identifier from QGraphicsItem.
QPointF posCursorGraph() const
Get position in graph coordinates.

◆ 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 344 of file Guidelines.cpp.

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

◆ 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 362 of file Guidelines.cpp.

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

◆ 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 390 of file Guidelines.cpp.

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

◆ setModelGuidelines()

void Guidelines::setModelGuidelines ( CoordsType coordsType,
const DocumentModelGuidelines & modelGuidelines )

Load Guidelines from Document.

Definition at line 402 of file Guidelines.cpp.

404{
405 clear ();
406
407 GuidelineValues valuesXT = modelGuidelines.valuesX();
408 GuidelineValues valuesYR = modelGuidelines.valuesY();
409
410 GuidelineValues::const_iterator itr;
411
412 for (itr = valuesXT.begin(); itr != valuesXT.end(); itr++) {
413 QString identifier = itr.key();
414 double value = itr.value();
415
417 createGuidelineX (identifier,
418 value);
419 } else {
420 createGuidelineT (identifier,
421 value);
422 }
423 }
424
425 for (itr = valuesYR.begin(); itr != valuesYR.end(); itr++) {
426 QString identifier = itr.key();
427 double value = itr.value();
428
430 createGuidelineY (identifier,
431 value);
432 } else {
433 createGuidelineR (identifier,
434 value);
435 }
436 }
437}
@ COORDS_TYPE_CARTESIAN
Definition CoordsType.h:13
CoordsType coordsType() const
Return cartesian or polar.
DocumentModelGuidelines modelGuidelines() const
Return complete set of guidelines information for Document.

◆ stateDump()

QString Guidelines::stateDump ( ) const

States listed as a string for debugging only.

Definition at line 439 of file Guidelines.cpp.

440{
441 // Sort the entries
442 QStringList sortedXT, sortedYR;
443 GuidelineContainerPrivate::const_iterator itrSort;
444
445 for (itrSort = m_guidelineContainerXT.begin(); itrSort != m_guidelineContainerXT.end(); itrSort++) {
446 GuidelineAbstract *guideline = *itrSort;
447 sortedXT << guideline->stateDump ();
448 }
449
450 for (itrSort = m_guidelineContainerYR.begin(); itrSort != m_guidelineContainerYR.end(); itrSort++) {
451 GuidelineAbstract *guideline = *itrSort;
452 sortedYR << guideline->stateDump ();
453 }
454
455 std::sort (sortedXT.begin(),
456 sortedXT.end());
457 std::sort (sortedYR.begin(),
458 sortedYR.end());
459
460 // Convert entries to output text
461 QString out;
462 QTextStream str (&out);
463
464 str << "Guidelines::stateDump:\n";
465
466 QStringList::const_iterator itrOut;
467
468 for (itrOut = sortedXT.begin(); itrOut != sortedXT.end(); itrOut++) {
469 QString entry = *itrOut;
470 str << " " << entry << "\n";
471 }
472
473 for (itrOut = sortedYR.begin(); itrOut != sortedYR.end(); itrOut++) {
474 QString entry = *itrOut;
475 str << " " << entry << "\n";
476 }
477
478 return out;
479}
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 481 of file Guidelines.cpp.

482{
483 return m_mainWindow.transformation ();
484}

◆ updateColor()

void Guidelines::updateColor ( )

Force a color update.

Definition at line 512 of file Guidelines.cpp.

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

◆ updateWithLatestTransformation()

void Guidelines::updateWithLatestTransformation ( )

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

Definition at line 527 of file Guidelines.cpp.

528{
529 GuidelineContainerPrivate::iterator itr;
530
531 for (itr = m_guidelineContainerXT.begin(); itr != m_guidelineContainerXT.end(); itr++) {
532 GuidelineAbstract *guideline = *itr;
533 guideline->updateWithLatestTransformation ();
534 }
535
536 for (itr = m_guidelineContainerYR.begin(); itr != m_guidelineContainerYR.end(); itr++) {
537 GuidelineAbstract *guideline = *itr;
538 guideline->updateWithLatestTransformation ();
539 }
540}
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: