Engauge Digitizer  2
ScaleBarAxisPointsUnite.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "CallbackScaleBar.h"
8 #include "CmdMediator.h"
9 #include "Document.h"
10 #include "Logger.h"
11 #include <QVector>
12 #include "ScaleBarAxisPointsUnite.h"
13 
15 {
16  LOG4CPP_INFO_S ((*mainCat)) << "ScaleBarAxisPointsUnite::ScaleBarAxisPointsUnite";
17 }
18 
19 ScaleBarAxisPointsUnite::~ScaleBarAxisPointsUnite()
20 {
21 }
22 
23 QStringList ScaleBarAxisPointsUnite::axisPointIdentifiers (CmdMediator *cmdMediator) const
24 {
25  CallbackScaleBar ftor;
26 
27  Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
29  cmdMediator->iterateThroughCurvePointsAxes (ftorWithCallback);
30 
31  return ftor.axisCurvePointIdentifiers ();
32 }
33 
34 QStringList ScaleBarAxisPointsUnite::unite (CmdMediator *cmdMediator,
35  const QStringList &pointIdentifiersIn) const
36 {
37  const int AXIS_POINT_COUNT_IF_UNITING = 2;
38 
39  QStringList pointIdentifiersOut (pointIdentifiersIn);
40 
41  // Collect axis point identifiers
42  QStringList axisIdentifiers = axisPointIdentifiers (cmdMediator);
43 
44  // Skip if not a map with scale bar
45  if ((cmdMediator->document().documentAxesPointsRequired() == DOCUMENT_AXES_POINTS_REQUIRED_2) &&
46  (axisIdentifiers.count () == AXIS_POINT_COUNT_IF_UNITING)) {
47 
48  // Calculate occurrence counts
49  QVector<int> counts (AXIS_POINT_COUNT_IF_UNITING);
50  for (int i = 0; i < AXIS_POINT_COUNT_IF_UNITING; i++) {
51  counts [i] = 0;
52 
53  QStringList::const_iterator itr;
54  for (itr = pointIdentifiersIn.begin (); itr != pointIdentifiersIn.end (); itr++) {
55  QString pointIdentifier = *itr;
56 
57  if (axisIdentifiers [i] == pointIdentifier) {
58  ++counts [i];
59  }
60  }
61  }
62 
63  // Add in either of two cases
64  if (counts [0] == 0 && counts [1] == 1) {
65  // Add first
66  pointIdentifiersOut << axisIdentifiers [0];
67  } else if (counts [0] == 1 && counts [1] == 0) {
68  // Add second
69  pointIdentifiersOut << axisIdentifiers [1];
70  }
71  }
72 
73  return pointIdentifiersOut;
74 }
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
Callback for identifying, for the scale bar of a map, various quantities.
QStringList axisCurvePointIdentifiers() const
Points in axis curve.
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
Definition: Document.cpp:360
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
ScaleBarAxisPointsUnite()
Single constructor.
QStringList unite(CmdMediator *cmdMediator, const QStringList &pointIdentifiersIn) const
Add.
Command queue stack.
Definition: CmdMediator.h:23
void iterateThroughCurvePointsAxes(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for the single axes curve.
Definition: CmdMediator.cpp:87