00001 #ifndef STACKEDGRAPH_H 00002 #define STACKEDGRAPH_H 00003 00004 #include <QGraphicsScene> 00005 #include "StackedGraphView.h" 00006 #include "DataItem.h" 00007 #include "ColorScheme1D.h" 00008 00012 struct TempData 00013 { 00014 int i; 00015 int j; 00016 QGraphicsItem* item; 00017 }; 00018 00022 class StackedGraph : public QGraphicsScene 00023 { 00024 Q_OBJECT 00025 00026 public: 00035 StackedGraph(const QVector<DataItem>* dataPtr, const QString* unitSymbolPtr, const bool* unitAfterNumberPtr, const QVector<QString>* unitSizeNamesPtr, QWidget* parent); 00036 ~StackedGraph(); 00037 00038 StackedGraphView* getView() {return view;} 00039 int getLength() {calculateFirstLastDate(); return getXPos(lastYear, lastMonth);} 00040 int getXRange() {return xRange;} 00041 int getYRange() {return yRange;} 00042 bool getRenderGraph() {return renderGraph;} 00043 void setRenderGraph(bool renderGraphOn) {renderGraph = renderGraphOn;} 00044 00045 signals: 00046 void maxColorTextChanged(const QString& text, const QColor& color); 00047 void minColorTextChanged(const QString& text, const QColor& color); 00048 00049 public slots: 00050 void makeStackedGraph(); 00051 void setXRange(int newXRange) {if (xRange != double(newXRange)) {xRange = double(newXRange); makeStackedGraph();}} 00052 void setBaselineAlgo(int newBaselineAlgo) {if (baselineAlgo != newBaselineAlgo) {baselineAlgo = newBaselineAlgo; makeStackedGraph();}} 00053 void setSortAlgo(int newSortAlgo) {if (sortAlgo != newSortAlgo) {sortAlgo = newSortAlgo; makeStackedGraph();}} 00054 void setColorAlgo(int newColorAlgo) {if (colorAlgo != newColorAlgo) {colorAlgo = newColorAlgo; makeStackedGraph();}} 00055 void setMaxColor(const QColor& newMaxColor) {colorScheme.setColor_1(newMaxColor); makeStackedGraph();} 00056 void setMinColor(const QColor& newMinColor) {colorScheme.setColor_2(newMinColor); makeStackedGraph();} 00057 void setDetailedInformation(bool detailedInfo) {detailedInformation = detailedInfo; emitColorAlgoMinMaxValue();} 00058 void makeToolTip(QGraphicsItem* item, QPoint pos); 00059 00060 private: 00061 void calculateFirstLastDate(); 00062 void calculateXYScale(); 00063 void calculateColorAlgoMinMaxValue(); 00064 void emitColorAlgoMinMaxValue(); 00065 void sortStackedGraph(); 00066 void paintStackedGraph(); 00067 int getDataXPos(int i, int j); 00068 int getXPos(int year, int month); 00069 int getAverageUnitSize(const QVector<DataItemPart>& items); 00070 00076 QString addUnitToNumber(double number, int unitSize = -1); 00077 void pathTo(QPainterPath& path, double pX, double pY); 00078 void resetPathTo(QPainterPath& path, double pX, double pY); 00079 void textTo(QPainterPath& path, double pX, double pY, double quantity, const QString& label); 00080 int textPosIndex(const QVector<DataItemPart>& data); 00081 00082 StackedGraphView* view; 00083 const QVector<DataItem>* data; 00084 const QString* unitSymbol; 00085 const bool* unitAfterNumber; 00086 const QVector<QString>* unitSizeNames; 00087 QVector<TempData> tempData; 00088 int baselineAlgo,sortAlgo,colorAlgo; 00089 double oX,oY; 00090 double xScale,yScale; 00091 double xRange,yRange; 00092 double yMaxPos; 00093 double colorAlgoMinValue,colorAlgoMaxValue; 00094 int firstYear,firstMonth,lastYear,lastMonth; 00095 bool renderGraph; 00096 bool detailedInformation; 00097 ColorScheme1D colorScheme; 00098 }; 00099 00100 #endif