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