##// END OF EJS Templates
moved presenter to private headers. code cleanup
sauimone -
r217:97e8d42197e7
parent child
Show More
@@ -1,28 +1,28
1 #ifndef QBARGROUP_H
2 #define QBARGROUP_H
1 #ifndef BARPRESENTER_H
2 #define BARPRESENTER_H
3 3
4 4 #include "barpresenterbase.h"
5 5 #include "qbarchartseries.h"
6 6 #include <QGraphicsItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 // Base class for bar groups
11 11
12 12 class BarPresenter : public BarPresenterBase
13 13 {
14 14 public:
15 15 explicit BarPresenter(BarChartModel& model, QGraphicsItem *parent = 0);
16 16
17 17 private:
18 18
19 // From BarGroupBase
19 // From BarPresenterBase
20 20 void layoutChanged(); // layout has changed -> need to recalculate bar sizes
21 21
22 22 private:
23 23 // Data
24 24 };
25 25
26 26 QTCOMMERCIALCHART_END_NAMESPACE
27 27
28 #endif // QBARGROUP_H
28 #endif // BARPRESENTER_H
@@ -1,121 +1,111
1 1 #include "barpresenterbase.h"
2 2 #include "bar_p.h"
3 3 #include "barlabel_p.h"
4 4 #include "separator_p.h"
5 5 #include <QDebug>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 BarPresenterBase::BarPresenterBase(BarChartModel& model, QGraphicsItem *parent)
10 10 : ChartItem(parent)
11 11 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
12 12 ,mLayoutSet(false)
13 13 ,mLayoutDirty(true)
14 14 ,mSeparatorsVisible(true)
15 15 ,mModel(model)
16 16 {
17 17 dataChanged();
18 18 }
19 19
20 20 void BarPresenterBase::setSeparatorsVisible(bool visible)
21 21 {
22 22 mSeparatorsVisible = visible;
23 23 }
24 24
25 25 void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
26 26 {
27 27 // qDebug() << "BarGroupBase::paint" << childItems().count();
28 28 if (!mLayoutSet) {
29 29 qDebug() << "BarGroupBase::paint called without layout set. Aborting.";
30 30 return;
31 31 }
32 32 // if (mLayoutDirty) {
33 33 // Layout or data has changed. Need to redraw.
34 34 foreach(QGraphicsItem* i, childItems()) {
35 35 i->paint(painter,option,widget);
36 36 }
37 37 // }
38 38 }
39 39
40 40 QRectF BarPresenterBase::boundingRect() const
41 41 {
42 42 return QRectF(0,0,mWidth,mHeight);
43 43 }
44 44
45 45 void BarPresenterBase::setBarWidth( int w )
46 46 {
47 47 mBarDefaultWidth = w;
48 48 }
49 /*
50 void BarGroupBase::resetBrushes()
51 {
52 mBrushes.clear();
53 }
54 49
55 void BarGroupBase::addBrush(QBrush brush)
56 {
57 mBrushes.append(brush);
58 }
59 */
60 50 void BarPresenterBase::dataChanged()
61 51 {
62 52 // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them?
63 53
64 54 // Delete old bars
65 55 foreach (QGraphicsItem* item, childItems()) {
66 56 delete item;
67 57 }
68 58
69 59 // Create new graphic items for bars
70 60 int totalItems = mModel.countTotalItems();
71 61 for (int i=0; i<totalItems; i++) {
72 62 Bar *bar = new Bar(this);
73 63 childItems().append(bar);
74 64 }
75 65
76 66 int count = mModel.countCategories();
77 67 for (int i=0; i<count; i++) {
78 68 BarLabel* label = new BarLabel(this);
79 69 label->set(mModel.label(i));
80 70 childItems().append(label);
81 71 }
82 72
83 73 count = mModel.countCategories() - 1; // There is one less separator than columns
84 74 for (int i=0; i<count; i++) {
85 75 Separator* sep = new Separator(this);
86 76 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
87 77 childItems().append(sep);
88 78 }
89 79
90 80 // TODO: if (autolayout) { layoutChanged() } or something
91 81 mLayoutDirty = true;
92 82 }
93 83
94 84 //handlers
95 85
96 86 void BarPresenterBase::handleModelChanged(int index)
97 87 {
98 88 // qDebug() << "BarGroupBase::handleModelChanged" << index;
99 89 dataChanged();
100 90 }
101 91
102 92 void BarPresenterBase::handleDomainChanged(const Domain& domain)
103 93 {
104 94 // qDebug() << "BarGroupBase::handleDomainChanged";
105 95 // TODO: Figure out the use case for this.
106 96 // Affects the size of visible item, so layout is changed.
107 97 // layoutChanged();
108 98 }
109 99
110 100 void BarPresenterBase::handleGeometryChanged(const QRectF& rect)
111 101 {
112 102 mWidth = rect.width();
113 103 mHeight = rect.height();
114 104 layoutChanged();
115 105 mLayoutSet = true;
116 106 setPos(rect.topLeft());
117 107 }
118 108
119 109 #include "moc_barpresenterbase.cpp"
120 110
121 111 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,68 +1,63
1 #ifndef BARGROUPBASE_H
2 #define BARGROUPBASE_H
1 #ifndef BARPRESENTERBASE_H
2 #define BARPRESENTERBASE_H
3 3
4 4 #include "chartitem_p.h"
5 5 #include "barchartmodel_p.h"
6 6 #include <QPen>
7 7 #include <QBrush>
8 8 #include <QGraphicsItem>
9 9
10 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11
12 12 // Base Class for bar groups. Common implemantation of different groups. Not to be instantiated.
13 13 class BarPresenterBase : public QObject, public ChartItem
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 BarPresenterBase(BarChartModel& model, QGraphicsItem *parent = 0);
18 18 void setSeparatorsVisible(bool visible = true);
19 19
20 20 public:
21 21
22 22 // From QGraphicsItem
23 23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24 24 QRectF boundingRect() const;
25 25
26 26 // TODO: these may change with layout awarness.
27 27 void setBarWidth( int w );
28 28
29 // void resetBrushes();
30 // void addBrush(QBrush brush);
31
32 29 void setPen(QPen pen);
33 30 QPen pen();
34 31
35 32 void setBrush(QBrush brush);
36 33 QBrush brush();
37 34
38
39 35 // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it
40 36 virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes
41 37 virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes
42 38
43 39 protected slots:
44 40 void handleModelChanged(int index);
45 41 void handleDomainChanged(const Domain& domain);
46 42 void handleGeometryChanged(const QRectF& size);
47 43
48 44 protected:
49 45
50 46 // TODO: consider these.
51 47 int mHeight; // Layout spesific
52 48 int mWidth;
53 49 int mBarDefaultWidth;
54 50
55 51 bool mLayoutSet; // True, if component has been laid out.
56 52 bool mLayoutDirty;
57 53
58 54 QList<QColor> mColors; // List of colors for series for now
59 55 bool mSeparatorsVisible;
60 56 BarChartModel& mModel;
61 57
62 58 QPen mPen;
63 // QList<QBrush> mBrushes;
64 59 };
65 60
66 61 QTCOMMERCIALCHART_END_NAMESPACE
67 62
68 #endif // BARGROUPBASE_H
63 #endif // BARPRESENTERBASE_H
@@ -1,28 +1,28
1 #ifndef PERCENTBARGROUP_H
2 #define PERCENTBARGROUP_H
1 #ifndef PERCENTBARPRESENTER_H
2 #define PERCENTBARPRESENTER_H
3 3
4 4 #include "chartitem_p.h"
5 5 #include "bar_p.h"
6 6 #include "qpercentbarchartseries.h"
7 7 #include "barpresenterbase.h"
8 8 #include <QGraphicsItem>
9 9
10 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11
12 12 class PercentBarPresenter : public BarPresenterBase
13 13 {
14 14 public:
15 15 PercentBarPresenter(BarChartModel& model, QGraphicsItem *parent = 0);
16 16
17 17 private:
18 18
19 19 void layoutChanged(); // layout has changed -> need to recalculate bar sizes
20 20
21 21 private:
22 22
23 23 // Data
24 24 };
25 25
26 26 QTCOMMERCIALCHART_END_NAMESPACE
27 27
28 #endif // PERCENTBARGROUP_H
28 #endif // PERCENTBARPRESENTER_H
@@ -1,56 +1,53
1 1 #ifndef BARCHARTSERIES_H
2 2 #define BARCHARTSERIES_H
3 3
4 4 #include <QList>
5 5 #include <QAbstractItemModel>
6 6 #include "qchartseries.h"
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QBarCategory;
11 11 class QBarSet;
12 class BarPresenter;
13 12 class BarChartModel;
14 13
15 14 // Container for series
16 15 class QTCOMMERCIALCHART_EXPORT QBarChartSeries : public QChartSeries
17 16 {
18 17 Q_OBJECT
19 18 public:
20 19 QBarChartSeries(QBarCategory *category, QObject* parent=0);
21 20
22 21 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
23 22
24 23 void addBarSet(QBarSet *set); // Takes ownership of set
25 24 void removeBarSet(QBarSet *set); // Removes set, releases ownership.
26 25 int countSets();
27 26 QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true
28 27
29 28 //TODO:
30 29 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
31 30
32 31 // TODO: Functions below this are not part of api and will be moved
33 32 // to private implementation, when we start using it (not part of api)
34 33 int countCategories();
35 34 qreal min();
36 35 qreal max();
37 36 qreal valueAt(int set, int category);
38 37 qreal maxCategorySum();
39 38
40 39 BarChartModel& model();
41 40
42 41 signals:
43 42 void changed(int index);
44 43
45 44 public Q_SLOTS:
46 45
47 46 private:
48 47
49 BarPresenter* mBarGroup;
50 48 BarChartModel* mModel;
51
52 49 };
53 50
54 51 QTCOMMERCIALCHART_END_NAMESPACE
55 52
56 53 #endif // BARCHARTSERIES_H
@@ -1,58 +1,56
1 1 #ifndef PERCENTBARCHARTSERIES_H
2 2 #define PERCENTBARCHARTSERIES_H
3 3
4 4 #include <QList>
5 5 #include <QAbstractItemModel>
6 6 #include "qchartseries.h"
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 class PercentBarPresenter;
11 10 class QBarCategory;
12 11 class QBarSet;
13 12 class BarChartModel;
14 13
15 14 class QTCOMMERCIALCHART_EXPORT QPercentBarChartSeries : public QChartSeries
16 15 {
17 16 Q_OBJECT
18 17 public:
19 18 QPercentBarChartSeries(QBarCategory *category, QObject* parent=0);
20 19
21 20 // from BarChartSeriesBase
22 21 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; }
23 22
24 23 void addBarSet(QBarSet *set); // Takes ownership
25 24 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
26 25 int countSets();
27 26 QBarSet* nextSet(bool first=false); // Returns first set, if called with true
28 27
29 28 //TODO:
30 29 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
31 30
32 31 // TODO: Functions below this are not part of api and will be moved
33 32 // to private implementation, when we start using it (not part of api)
34 33 int countCategories();
35 34 qreal min();
36 35 qreal max();
37 36 qreal valueAt(int set, int category);
38 37 qreal maxCategorySum();
39 38
40 39 BarChartModel& model();
41 40
42 41 signals:
43 42 void changed(int index);
44 43
45 44 public Q_SLOTS:
46 45
47 46
48 47 private:
49 48
50 PercentBarPresenter* mPercentBarGroup;
51 49 BarChartModel* mModel;
52 50
53 51 };
54 52
55 53 QTCOMMERCIALCHART_END_NAMESPACE
56 54
57 55
58 56 #endif // PERCENTBARCHARTSERIES_H
@@ -1,55 +1,53
1 1 #ifndef STACKEDBARCHARTSERIES_H
2 2 #define STACKEDBARCHARTSERIES_H
3 3
4 4 #include <QList>
5 5 #include <QAbstractItemModel>
6 6 #include "qchartseries.h"
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 class StackedBarPresenter;
11 10 class QBarCategory;
12 11 class QBarSet;
13 12 class BarChartModel;
14 13
15 14 class QTCOMMERCIALCHART_EXPORT QStackedBarChartSeries : public QChartSeries
16 15 {
17 16 Q_OBJECT
18 17 public:
19 18 QStackedBarChartSeries(QBarCategory *category, QObject* parent=0);
20 19
21 20 // from QChartSeries
22 21 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; }
23 22
24 23 void addBarSet(QBarSet *set); // Takes ownership
25 24 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
26 25 int countSets();
27 26 QBarSet* nextSet(bool first=false); // Returns first set, if called with true
28 27
29 28 //TODO:
30 29 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
31 30
32 31 // TODO: Functions below this are not part of api and will be moved
33 32 // to private implementation, when we start using it (not part of api)
34 33 int countCategories();
35 34 qreal min();
36 35 qreal max();
37 36 qreal valueAt(int set, int category);
38 37 qreal maxCategorySum();
39 38
40 39 BarChartModel& model();
41 40
42 41 signals:
43 42 void changed(int index);
44 43
45 44 public Q_SLOTS:
46 45
47 46 private:
48 47
49 StackedBarPresenter* mStackedBarGroup;
50 48 BarChartModel* mModel;
51 49 };
52 50
53 51 QTCOMMERCIALCHART_END_NAMESPACE
54 52
55 53 #endif // STACKEDBARCHARTSERIES_H
@@ -1,120 +1,120
1 1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
2 2 TARGET = QtCommercialChart
3 3 DESTDIR = $$CHART_BUILD_LIB_DIR
4 4 TEMPLATE = lib
5 5 QT += core \
6 6 gui
7 7 CONFIG += debug_and_release
8 8 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
9 9 SOURCES += \
10 10 barchart/bar.cpp \
11 11 barchart/barlabel.cpp \
12 12 barchart/barchartmodel.cpp \
13 13 barchart/separator.cpp \
14 14 barchart/qbarset.cpp \
15 15 barchart/qbarcategory.cpp \
16 16 barchart/qbarchartseries.cpp \
17 17 barchart/qpercentbarchartseries.cpp \
18 18 barchart/qstackedbarchartseries.cpp \
19 19 barchart/barpresenterbase.cpp \
20 20 barchart/barpresenter.cpp \
21 21 barchart/stackedbarpresenter.cpp \
22 22 barchart/percentbarpresenter.cpp \
23 23 linechart/linechartanimationitem.cpp \
24 24 linechart/linechartitem.cpp \
25 25 linechart/qlinechartseries.cpp \
26 26 qchart.cpp \
27 27 axisitem.cpp \
28 28 qchartview.cpp \
29 29 qchartseries.cpp \
30 30 qchartaxis.cpp \
31 31 charttheme.cpp \
32 32 chartdataset.cpp \
33 33 chartpresenter.cpp \
34 34 domain.cpp
35 35 PRIVATE_HEADERS += linechart/linechartitem_p.h \
36 36 linechart/linechartanimationitem_p.h \
37 37 barchart/barlabel_p.h \
38 38 barchart/bar_p.h \
39 39 barchart/separator_p.h \
40 40 barchart/barchartmodel_p.h \
41 barchart/barpresenter.h \
42 barchart/stackedbarpresenter.h \
43 barchart/percentbarpresenter.h \
44 barchart/barpresenterbase.h \
41 45 axisitem_p.h \
42 46 chartitem_p.h \
43 47 charttheme_p.h \
44 48 chartdataset_p.h \
45 49 chartpresenter_p.h \
46 50 domain_p.h
47 51 PUBLIC_HEADERS += linechart/qlinechartseries.h \
48 52 barchart/qbarchartseries.h \
49 barchart/barpresenter.h \
50 53 barchart/qstackedbarchartseries.h \
51 barchart/stackedbarpresenter.h \
52 54 barchart/qpercentbarchartseries.h \
53 barchart/percentbarpresenter.h \
54 barchart/barpresenterbase.h \
55 55 barchart/qbarset.h \
56 56 barchart/qbarcategory.h \
57 57 qchartseries.h \
58 58 qchart.h \
59 59 qchartglobal.h \
60 60 qchartview.h \
61 61 qchartaxis.h
62 62
63 63 include(piechart/piechart.pri)
64 64 include(scatterseries/scatter.pri)
65 65
66 66 THEMES += themes/chartthemeicy_p.h \
67 67 themes/chartthemegrayscale_p.h \
68 68 themes/chartthemescientific_p.h \
69 69 themes/chartthemevanilla_p.h
70 70 HEADERS += $$PUBLIC_HEADERS
71 71 HEADERS += $$PRIVATE_HEADERS
72 72 HEADERS += $$THEMES
73 73 INCLUDEPATH += linechart \
74 74 barchart \
75 75 themes \
76 76 .
77 77 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
78 78 MOC_DIR = $$CHART_BUILD_DIR/lib
79 79 UI_DIR = $$CHART_BUILD_DIR/lib
80 80 RCC_DIR = $$CHART_BUILD_DIR/lib
81 81 DEFINES += QTCOMMERCIALCHART_LIBRARY
82 82 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
83 83 public_headers.files = $$PUBLIC_HEADERS
84 84 target.path = $$[QT_INSTALL_LIBS]
85 85 INSTALLS += target \
86 86 public_headers
87 87 install_build_public_headers.name = bild_public_headers
88 88 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
89 89 install_build_public_headers.input = PUBLIC_HEADERS
90 90 install_build_public_headers.commands = $$QMAKE_COPY \
91 91 ${QMAKE_FILE_NAME} \
92 92 $$CHART_BUILD_PUBLIC_HEADER_DIR
93 93 install_build_public_headers.CONFIG += target_predeps \
94 94 no_link
95 95 install_build_private_headers.name = bild_private_headers
96 96 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
97 97 install_build_private_headers.input = PRIVATE_HEADERS
98 98 install_build_private_headers.commands = $$QMAKE_COPY \
99 99 ${QMAKE_FILE_NAME} \
100 100 $$CHART_BUILD_PRIVATE_HEADER_DIR
101 101 install_build_private_headers.CONFIG += target_predeps \
102 102 no_link
103 103 QMAKE_EXTRA_COMPILERS += install_build_public_headers install_build_private_headers
104 104 chartversion.target = qchartversion_p.h
105 105 chartversion.commands = @echo \
106 106 "build_time" \
107 107 > \
108 108 $$chartversion.target;
109 109 chartversion.depends = $$HEADERS \
110 110 $$SOURCES
111 111 PRE_TARGETDEPS += qchartversion_p.h
112 112 QMAKE_CLEAN += qchartversion_p.h
113 113 QMAKE_EXTRA_TARGETS += chartversion
114 114 unix:QMAKE_DISTCLEAN += -r \
115 115 $$CHART_BUILD_HEADER_DIR \
116 116 $$CHART_BUILD_LIB_DIR
117 117 win32:QMAKE_DISTCLEAN += /Q \
118 118 $$CHART_BUILD_HEADER_DIR \
119 119 $$CHART_BUILD_LIB_DIR
120 120
General Comments 0
You need to be logged in to leave comments. Login now