Stacked Graphs
Geometry & Aesthetics
 All Classes Functions Variables Enumerations
graphscene.h
1 #ifndef GRAPHSCENE_H
2 #define GRAPHSCENE_H
3 
4 #include "graphlayouter.h"
5 #include "graphsorter.h"
6 #include "graphcolorizer.h"
7 #include <QGraphicsScene>
8 
14 class GraphScene : public QGraphicsScene
15 {
16  Q_OBJECT
17 
18 public:
19  explicit GraphScene(QWidget *parent);
20  ~GraphScene();
21 
28  void CreateStackedGraph(DataSet& data);
29 
33  QVector<GraphLayouter*> GetLayouts() const { return mLayouters; }
37  QVector<GraphSorter*> GetSorters() const { return mSorters; }
38 
43  void SetLayout(GraphLayouter* const layouter);
44 
49  void SetSorter(GraphSorter* const sorter);
50 
56 
61  void SetSortingAttribute(GraphSorter::SortingAttribute const sortAttribute);
62 
68 
74  void SetLabeling(bool enabled);
75 
80  void SetColors(QColor const beginColor, QColor const endColor);
81 
85  void Set2DColoring(bool enable);
86 
94  QImage GetBitmap(int width, int height, bool keepAspect);
95 signals:
96  void redrawRequired();
97 protected:
98  void mousePressEvent(QGraphicsSceneMouseEvent* ev) override;
99 private:
100  void calculateScale(DataSet& set, double& scaleX, double&scaleY);
101  QString getPopupString(const DataItem& item);
102 
103  void placeLabel(const QString& label, const QPainterPath& path, const QPointF& optimalPoint, const QBrush& brush);
104 
105  bool mDoLabeling;
106 
107  DataSet mCurrentData;
108 
109  QVector<GraphLayouter*> mLayouters;
110  QVector<GraphSorter*> mSorters;
111 
112  GraphLayouter* mCurrentLayouter;
113  GraphSorter* mCurrentSorter;
114  GraphColorizer* mCurrentColorizer;
115  GraphLayouter::InterpolationMode mCurrentInterpMode;
116  GraphSorter::SortingAttribute mCurrentSortAttribute;
117  GraphColorizer::ColoringAttribute mCurrentColoringAttribute;
118 
119  QList<QGraphicsItem*> mOldSelection;
120 private slots:
121  void onSelectionChanged();
122 };
123 
124 #endif // GRAPHSCENE_H
A QGraphicsScene subclass which is responsible for the creation, drawing and rendering of a stacked g...
Definition: graphscene.h:14
void SetColors(QColor const beginColor, QColor const endColor)
Sets the colors which define the start and end color of the linearly interpolated color gradient used...
Definition: graphscene.cpp:122
SortingAttribute
List of attributes used to sort the dataset.
Definition: graphsorter.h:18
QVector< GraphSorter * > GetSorters() const
Returns the available sorters.
Definition: graphscene.h:37
void SetInterpolationMode(GraphLayouter::InterpolationMode const interpMode)
Sets the interpolation method to be used by the GraphLayouter when layouting the graph.
Definition: graphscene.cpp:104
ColoringAttribute
List of attributes which can be used to calculate an appropriate color value.
Definition: graphcolorizer.h:18
The data set.
Definition: dataset.h:85
Derived classes provide layouting functionality.
Definition: graphlayouter.h:11
void Set2DColoring(bool enable)
Sets a flag which enables 2D coloring: alpha value of color changes according to the layours sum valu...
Definition: graphscene.cpp:128
InterpolationMode
List of interpolation methods.
Definition: graphlayouter.h:19
Represents a single layer of the stacked graph.
Definition: dataset.h:23
void CreateStackedGraph(DataSet &data)
Creates a stacked graph out of the given dataset.
Definition: graphscene.cpp:167
Class provides coloring for the graph layers by using linear interpolation.
Definition: graphcolorizer.h:10
void SetLabeling(bool enabled)
Determines if the layers should show their labels.
Definition: graphscene.cpp:134
void SetSorter(GraphSorter *const sorter)
Sets the sorter to use in the CreateStackedGraph method.
Definition: graphscene.cpp:98
Derived classes provide sorting functionality for the graph layers, usign different algorithms...
Definition: graphsorter.h:10
QVector< GraphLayouter * > GetLayouts() const
Returns the available layouts.
Definition: graphscene.h:33
QImage GetBitmap(int width, int height, bool keepAspect)
Renders the current graph into a QImage.
Definition: graphscene.cpp:316
void SetLayout(GraphLayouter *const layouter)
Sets the layouter to use in the CreateStackedGraph method.
Definition: graphscene.cpp:92
void SetSortingAttribute(GraphSorter::SortingAttribute const sortAttribute)
Sets the sorting attribute to be used by the GraphSorter when sorting the dataset.
Definition: graphscene.cpp:110
void SetColoringAttribute(GraphColorizer::ColoringAttribute const colorAttribute)
Sets the coloring attribute to be used by the GraphColorizer when assigning colors to the graph layer...
Definition: graphscene.cpp:116