Engauge Digitizer 2
Loading...
Searching...
No Matches
GraphicsItemsExtractor.cpp
Go to the documentation of this file.
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"
10#include "GraphicsItemType.h"
11#include "Logger.h"
12#include "Point.h"
13#include <QGraphicsItem>
14
18
22
23bool 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 = static_cast<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
59QStringList 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}
const QString AXIS_CURVE_NAME
@ DATA_KEY_GRAPHICS_ITEM_TYPE
Definition DataKey.h:15
@ DATA_KEY_IDENTIFIER
Definition DataKey.h:14
GraphicsItemType
Runtime type identification (RTTI) for QGraphicsItem objects.
@ GRAPHICS_ITEM_TYPE_POINT
log4cpp::Category * mainCat
Definition Logger.cpp:14
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.
QStringList selectedPointIdentifiers(const QList< QGraphicsItem * > &items) const
Return list of selected point identifiers.
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
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18