Engauge Digitizer  2
GraphicsItemsExtractor.cpp
1 /******************************************************************************************************
2  * (C) 2016 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 "Curve.h"
8 #include "DataKey.h"
9 #include "GraphicsItemsExtractor.h"
10 #include "GraphicsItemType.h"
11 #include "Logger.h"
12 #include "Point.h"
13 #include <QGraphicsItem>
14 
16 {
17 }
18 
19 GraphicsItemsExtractor::~GraphicsItemsExtractor()
20 {
21 }
22 
23 bool GraphicsItemsExtractor::allSelectedItemsAreEitherAxisOrGraph (const QList<QGraphicsItem*> &items,
24  AxisOrGraph axisOrGraph) const
25 {
26  bool allAreEitherAxisOrGraph = true;
27 
28  QList<QGraphicsItem*>::const_iterator itr;
29  for (itr = items.begin(); itr != items.end(); itr++) {
30 
31  QGraphicsItem *item = *itr;
32  GraphicsItemType type = (GraphicsItemType) item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt ();
33 
34  if (type == GRAPHICS_ITEM_TYPE_POINT) {
35 
36  QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
37  QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
38 
39  bool unwantedAxisPoint = ((curveName == AXIS_CURVE_NAME) && (axisOrGraph == GRAPH_POINTS));
40  bool unwantedCurvePoint = ((curveName != AXIS_CURVE_NAME) && (axisOrGraph == AXIS_POINTS));
41 
42  if (unwantedAxisPoint || unwantedCurvePoint) {
43 
44  allAreEitherAxisOrGraph = false;
45  break;
46 
47  }
48  } else {
49 
50  allAreEitherAxisOrGraph = false;
51  break;
52 
53  }
54  }
55 
56  return allAreEitherAxisOrGraph;
57 }
58 
59 QStringList GraphicsItemsExtractor::selectedPointIdentifiers (const QList<QGraphicsItem*> &items) const
60 {
61  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::selectedPointIdentifiers"
62  << " selectedItems=" << items.count();
63 
64  QStringList selectedIds;
65  QList<QGraphicsItem*>::const_iterator itr;
66  for (itr = items.begin(); itr != items.end(); itr++) {
67 
68  const QGraphicsItem* item = *itr;
69 
70  // Skip the image and only keep the Points
71  bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
72  if (isPoint) {
73 
74  // Add Point to the list
75  selectedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
76 
77  }
78  }
79 
80  return selectedIds;
81 }
static QString curveNameFromPointIdentifier(const QString &pointIdentifier)
Parse the curve name from the specified point identifier. This does the opposite of uniqueIdentifierG...
Definition: Point.cpp:227
QStringList selectedPointIdentifiers(const QList< QGraphicsItem *> &items) const
Return list of selected point identifiers.
GraphicsItemsExtractor()
Single constructor.
bool allSelectedItemsAreEitherAxisOrGraph(const QList< QGraphicsItem *> &items, AxisOrGraph axisOrGraph) const
Return true if all selected points are of the specified axis or graph type.