##// END OF EJS Templates
Added pen & brush to QBarSet
sauimone -
r214:84a6aaeda27a
parent child
Show More
@@ -33,10 +33,30 void BarChartModel::removeBarSet(QBarSet *set)
33 33 {
34 34 if (mDataModel.contains(set)) {
35 35 mDataModel.removeOne(set);
36 delete set;
37 36 }
38 37 }
39 38
39 QBarSet* BarChartModel::nextSet(bool getFirst)
40 {
41 if (getFirst) {
42 mCurrentSet = 0;
43 }
44
45 if ((mDataModel.count() <= 0) || (mDataModel.count() <= mCurrentSet)) {
46 return 0;
47 }
48
49 QBarSet* set = mDataModel.at(mCurrentSet);
50 mCurrentSet++;
51 return set;
52 }
53
54
55 QBarSet& BarChartModel::setAt(int index)
56 {
57 return *mDataModel.at(index);
58 }
59
40 60 int BarChartModel::countSets()
41 61 {
42 62 return mDataModel.count();
@@ -22,6 +22,9 public:
22 22 QBarCategory& category();
23 23 void addBarSet(QBarSet *set);
24 24 void removeBarSet(QBarSet *set);
25 QBarSet* nextSet(bool getFirst);
26
27 QBarSet& setAt(int index); // Internal
25 28
26 29 int countSets(); // Number of sets in model
27 30 int countCategories(); // Number of categories
@@ -46,6 +49,8 private:
46 49 QList<QBarSet*> mDataModel;
47 50 QBarCategory* mCategory; // Owned
48 51
52 int mCurrentSet;
53
49 54 };
50 55
51 56 QTCOMMERCIALCHART_END_NAMESPACE
@@ -23,6 +23,16 void BarChartSeries::removeBarSet(QBarSet *set)
23 23 mModel->removeBarSet(set);
24 24 }
25 25
26 int BarChartSeries::countSets()
27 {
28 return mModel->countSets();
29 }
30
31 QBarSet* BarChartSeries::nextSet(bool getFirst)
32 {
33 return mModel->nextSet(getFirst);
34 }
35
26 36 int BarChartSeries::countCategories()
27 37 {
28 38 return mModel->countCategories();
@@ -21,8 +21,10 public:
21 21
22 22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
23 23
24 void addBarSet(QBarSet *set); // Takes ownership
25 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
24 void addBarSet(QBarSet *set); // Takes ownership of set
25 void removeBarSet(QBarSet *set); // Removes set, releases ownership.
26 int countSets();
27 QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true
26 28
27 29 //TODO:
28 30 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
@@ -1,6 +1,7
1 1 #include "bargroup.h"
2 2 #include "bar_p.h"
3 3 #include "barlabel_p.h"
4 #include "qbarset.h"
4 5 #include <QDebug>
5 6
6 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -51,10 +52,7 void BarGroup::layoutChanged()
51 52
52 53 // TODO: width settable per bar?
53 54 bar->resize(mBarDefaultWidth, barHeight);
54 bar->setBrush(mBrushes.at(set));
55 // bar->setPen(mModel.barSet(set).pen());
56 // bar->setColor(mColors.at(set));
57 // bar->setPen();
55 bar->setBrush(mModel.setAt(set).brush());
58 56 bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight);
59 57 itemIndex++;
60 58 xPos += mBarDefaultWidth;
@@ -47,21 +47,6 void BarGroupBase::setBarWidth( int w )
47 47 mBarDefaultWidth = w;
48 48 }
49 49 /*
50 int BarGroupBase::addColor( QColor color )
51 {
52 // qDebug() << "BarGroupBase::addColor";
53 int colorIndex = mColors.count();
54 mColors.append(color);
55 return colorIndex;
56 }
57 */
58 /*
59 void BarGroupBase::resetColors()
60 {
61 // qDebug() << "BarGroupBase::resetColors";
62 mColors.clear();
63 }
64 */
65 50 void BarGroupBase::resetBrushes()
66 51 {
67 52 mBrushes.clear();
@@ -71,8 +56,7 void BarGroupBase::addBrush(QBrush brush)
71 56 {
72 57 mBrushes.append(brush);
73 58 }
74
75
59 */
76 60 void BarGroupBase::dataChanged()
77 61 {
78 62 // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them?
@@ -25,11 +25,9 public:
25 25
26 26 // TODO: these may change with layout awarness.
27 27 void setBarWidth( int w );
28 // int addColor( QColor color );
29 // void resetColors();
30 28
31 void resetBrushes();
32 void addBrush(QBrush brush);
29 // void resetBrushes();
30 // void addBrush(QBrush brush);
33 31
34 32 void setPen(QPen pen);
35 33 QPen pen();
@@ -62,7 +60,7 protected:
62 60 BarChartModel& mModel;
63 61
64 62 QPen mPen;
65 QList<QBrush> mBrushes;
63 // QList<QBrush> mBrushes;
66 64 };
67 65
68 66 QTCOMMERCIALCHART_END_NAMESPACE
@@ -25,6 +25,16 void PercentBarChartSeries::removeBarSet(QBarSet *set)
25 25 mModel->removeBarSet(set);
26 26 }
27 27
28 int PercentBarChartSeries::countSets()
29 {
30 return mModel->countSets();
31 }
32
33 QBarSet* PercentBarChartSeries::nextSet(bool getFirst)
34 {
35 return mModel->nextSet(getFirst);
36 }
37
28 38 int PercentBarChartSeries::countCategories()
29 39 {
30 40 return mModel->countCategories();
@@ -23,6 +23,8 public:
23 23
24 24 void addBarSet(QBarSet *set); // Takes ownership
25 25 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
26 int countSets();
27 QBarSet* nextSet(bool first=false); // Returns first set, if called with true
26 28
27 29 //TODO:
28 30 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
@@ -2,6 +2,7
2 2 #include "bar_p.h"
3 3 #include "barlabel_p.h"
4 4 #include "separator_p.h"
5 #include "qbarset.h"
5 6 #include <QDebug>
6 7
7 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -49,9 +50,7 void PercentBarGroup::layoutChanged()
49 50
50 51 // TODO: width settable per bar?
51 52 bar->resize(mBarDefaultWidth, barHeight);
52 bar->setBrush(mBrushes.at(set));
53 // bar->setBrush(mBrush);
54 // bar->setColor(mColors.at(set));
53 bar->setBrush(mModel.setAt(set).brush());
55 54 bar->setPos(xPos, yPos-barHeight);
56 55 itemIndex++;
57 56 yPos -= barHeight;
@@ -36,6 +36,28 void QBarSet::setValue(int index, qreal value)
36 36 mValues.replace(index,value);
37 37 }
38 38
39 void QBarSet::setPen(const QPen& pen)
40 {
41 mPen = pen;
42 }
43
44 const QPen& QBarSet::pen() const
45 {
46 return mPen;
47 }
48
49 void QBarSet::setBrush(const QBrush& brush)
50 {
51 mBrush = brush;
52 }
53
54 const QBrush& QBarSet::brush() const
55 {
56 return mBrush;
57 }
58
59
60
39 61 //TODO?:
40 62 //#include "moc_qbarset.cpp"
41 63 QTCOMMERCIALCHART_END_NAMESPACE
@@ -21,10 +21,18 public:
21 21 qreal valueAt(int index); // for modifying individual values
22 22 void setValue(int index, qreal value); //
23 23
24 void setPen(const QPen& pen);
25 const QPen& pen() const;
26
27 void setBrush(const QBrush& brush);
28 const QBrush& brush() const;
29
24 30 private:
25 31
26 32 QString mName;
27 33 QList<qreal> mValues;
34 QPen mPen;
35 QBrush mBrush;
28 36 };
29 37
30 38 QTCOMMERCIALCHART_END_NAMESPACE
@@ -23,6 +23,16 void StackedBarChartSeries::removeBarSet(QBarSet *set)
23 23 mModel->removeBarSet(set);
24 24 }
25 25
26 int StackedBarChartSeries::countSets()
27 {
28 return mModel->countSets();
29 }
30
31 QBarSet* StackedBarChartSeries::nextSet(bool getFirst)
32 {
33 return mModel->nextSet(getFirst);
34 }
35
26 36 int StackedBarChartSeries::countCategories()
27 37 {
28 38 return mModel->countCategories();
@@ -23,6 +23,8 public:
23 23
24 24 void addBarSet(QBarSet *set); // Takes ownership
25 25 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
26 int countSets();
27 QBarSet* nextSet(bool first=false); // Returns first set, if called with true
26 28
27 29 //TODO:
28 30 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
@@ -2,6 +2,7
2 2 #include "bar_p.h"
3 3 #include "barlabel_p.h"
4 4 #include "separator_p.h"
5 #include "qbarset.h"
5 6 #include <QDebug>
6 7
7 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -54,9 +55,7 void StackedBarGroup::layoutChanged()
54 55 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
55 56
56 57 bar->resize(mBarDefaultWidth, barHeight);
57 bar->setBrush(mBrushes.at(set));
58 // bar->setBrush(mBrush);
59 // bar->setColor(mColors.at(set));
58 bar->setBrush(mModel.setAt(set).brush());
60 59 bar->setPos(xPos, yPos-barHeight);
61 60 itemIndex++;
62 61 yPos -= barHeight;
@@ -4,6 +4,7
4 4
5 5
6 6 //series
7 #include "qbarset.h"
7 8 #include "barchartseries.h"
8 9 #include "stackedbarchartseries.h"
9 10 #include "percentbarchartseries.h"
@@ -140,47 +141,23 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int coun
140 141
141 142 void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count)
142 143 {
143 // TODO: better way to descide series color and remove hard coded colors.
144 item->resetBrushes();
145 for (int i=0; i<m_seriesColor.count(); i++) {
146 QBrush brush(m_seriesColor.at(i));
147 item->addBrush(brush);
144 for (int i=0; i<series->countSets(); i++) {
145 series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
148 146 }
149 item->addBrush(QBrush(QColor(255,0,0,128)));
150 item->addBrush(QBrush(QColor(255,255,0,128)));
151 item->addBrush(QBrush(QColor(0,255,0,128)));
152 item->addBrush(QBrush(QColor(0,0,255,128)));
153 item->addBrush(QBrush(QColor(255,128,0,128)));
154 147 }
155 148
156 149 void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count)
157 150 {
158 // TODO: better way to descide series color and remove hard coded colors.
159 item->resetBrushes();
160 for (int i=0; i<m_seriesColor.count(); i++) {
161 QBrush brush(m_seriesColor.at(i));
162 item->addBrush(brush);
151 for (int i=0; i<series->countSets(); i++) {
152 series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
163 153 }
164 item->addBrush(QBrush(QColor(255,0,0,128)));
165 item->addBrush(QBrush(QColor(255,255,0,128)));
166 item->addBrush(QBrush(QColor(0,255,0,128)));
167 item->addBrush(QBrush(QColor(0,0,255,128)));
168 item->addBrush(QBrush(QColor(255,128,0,128)));
169 154 }
170 155
171 156 void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count)
172 157 {
173 // TODO: better way to descide series color and remove hard coded colors.
174 item->resetBrushes();
175 for (int i=0; i<m_seriesColor.count(); i++) {
176 QBrush brush(m_seriesColor.at(i));
177 item->addBrush(brush);
158 for (int i=0; i<series->countSets(); i++) {
159 series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
178 160 }
179 item->addBrush(QBrush(QColor(255,0,0,128)));
180 item->addBrush(QBrush(QColor(255,255,0,128)));
181 item->addBrush(QBrush(QColor(0,255,0,128)));
182 item->addBrush(QBrush(QColor(0,0,255,128)));
183 item->addBrush(QBrush(QColor(255,128,0,128)));
184 161 }
185 162
186 163 void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count)
General Comments 0
You need to be logged in to leave comments. Login now