00001
00002
00003
00004
00005
00006
00007 #include "Curve.h"
00008 #include "DataKey.h"
00009 #include "GraphicsItemsExtractor.h"
00010 #include "GraphicsItemType.h"
00011 #include "Logger.h"
00012 #include "Point.h"
00013 #include <QGraphicsItem>
00014
00015 GraphicsItemsExtractor::GraphicsItemsExtractor()
00016 {
00017 }
00018
00019 GraphicsItemsExtractor::~GraphicsItemsExtractor()
00020 {
00021 }
00022
00023 bool GraphicsItemsExtractor::allSelectedItemsAreEitherAxisOrGraph (const QList<QGraphicsItem*> &items,
00024 AxisOrGraph axisOrGraph) const
00025 {
00026 bool allAreEitherAxisOrGraph = true;
00027
00028 QList<QGraphicsItem*>::const_iterator itr;
00029 for (itr = items.begin(); itr != items.end(); itr++) {
00030
00031 QGraphicsItem *item = *itr;
00032 GraphicsItemType type = (GraphicsItemType) item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt ();
00033
00034 if (type == GRAPHICS_ITEM_TYPE_POINT) {
00035
00036 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
00037 QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
00038
00039 bool unwantedAxisPoint = ((curveName == AXIS_CURVE_NAME) && (axisOrGraph == GRAPH_POINTS));
00040 bool unwantedCurvePoint = ((curveName != AXIS_CURVE_NAME) && (axisOrGraph == AXIS_POINTS));
00041
00042 if (unwantedAxisPoint || unwantedCurvePoint) {
00043
00044 allAreEitherAxisOrGraph = false;
00045 break;
00046
00047 }
00048 } else {
00049
00050 allAreEitherAxisOrGraph = false;
00051 break;
00052
00053 }
00054 }
00055
00056 return allAreEitherAxisOrGraph;
00057 }
00058
00059 QStringList GraphicsItemsExtractor::selectedPointIdentifiers (const QList<QGraphicsItem*> &items) const
00060 {
00061 LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::selectedPointIdentifiers"
00062 << " selectedItems=" << items.count();
00063
00064 QStringList selectedIds;
00065 QList<QGraphicsItem*>::const_iterator itr;
00066 for (itr = items.begin(); itr != items.end(); itr++) {
00067
00068 const QGraphicsItem* item = *itr;
00069
00070
00071 bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
00072 if (isPoint) {
00073
00074
00075 selectedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
00076
00077 }
00078 }
00079
00080 return selectedIds;
00081 }