@@ -17,7 +17,7 void BarPresenter::layoutChanged() | |||||
17 | { |
|
17 | { | |
18 | // Scale bars to new layout |
|
18 | // Scale bars to new layout | |
19 | // Layout for bars: |
|
19 | // Layout for bars: | |
20 |
if (mSeries-> |
|
20 | if (mSeries->barsetCount() <= 0) { | |
21 | qDebug() << "No sets in model!"; |
|
21 | qDebug() << "No sets in model!"; | |
22 | return; |
|
22 | return; | |
23 | } |
|
23 | } | |
@@ -29,8 +29,8 void BarPresenter::layoutChanged() | |||||
29 |
|
29 | |||
30 | // TODO: better way to auto-layout? |
|
30 | // TODO: better way to auto-layout? | |
31 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
31 | // Use reals for accurancy (we might get some compiler warnings... :) | |
32 |
int categoryCount = mSeries->c |
|
32 | int categoryCount = mSeries->categoryCount(); | |
33 |
int setCount = mSeries-> |
|
33 | int setCount = mSeries->barsetCount(); | |
34 |
|
34 | |||
35 | qreal tW = mWidth; |
|
35 | qreal tW = mWidth; | |
36 | qreal tH = mHeight; |
|
36 | qreal tH = mHeight; | |
@@ -67,10 +67,10 void BarPresenter::layoutChanged() | |||||
67 |
|
67 | |||
68 | // Position floating values |
|
68 | // Position floating values | |
69 | itemIndex = 0; |
|
69 | itemIndex = 0; | |
70 |
for (int category=0; category < mSeries->c |
|
70 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
71 | qreal xPos = xStepPerSet * category + ((tW + mBarDefaultWidth*setCount)/(categoryCount*2)); |
|
71 | qreal xPos = xStepPerSet * category + ((tW + mBarDefaultWidth*setCount)/(categoryCount*2)); | |
72 | qreal yPos = mHeight; |
|
72 | qreal yPos = mHeight; | |
73 |
for (int set=0; set < mSeries-> |
|
73 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
74 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
74 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
75 | BarValue* value = mFloatingValues.at(itemIndex); |
|
75 | BarValue* value = mFloatingValues.at(itemIndex); | |
76 |
|
76 |
@@ -68,8 +68,8 void BarPresenterBase::dataChanged() | |||||
68 | mFloatingValues.clear(); |
|
68 | mFloatingValues.clear(); | |
69 |
|
69 | |||
70 | // Create new graphic items for bars |
|
70 | // Create new graphic items for bars | |
71 |
for (int c=0; c<mSeries->c |
|
71 | for (int c=0; c<mSeries->categoryCount(); c++) { | |
72 |
for (int s=0; s<mSeries-> |
|
72 | for (int s=0; s<mSeries->barsetCount(); s++) { | |
73 | QBarSet *set = mSeries->barsetAt(s); |
|
73 | QBarSet *set = mSeries->barsetAt(s); | |
74 | Bar *bar = new Bar(this); |
|
74 | Bar *bar = new Bar(this); | |
75 | childItems().append(bar); |
|
75 | childItems().append(bar); | |
@@ -81,7 +81,7 void BarPresenterBase::dataChanged() | |||||
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | // Create labels |
|
83 | // Create labels | |
84 |
int count = mSeries->c |
|
84 | int count = mSeries->categoryCount(); | |
85 | for (int i=0; i<count; i++) { |
|
85 | for (int i=0; i<count; i++) { | |
86 | BarLabel* label = new BarLabel(this); |
|
86 | BarLabel* label = new BarLabel(this); | |
87 | label->set(mSeries->label(i)); |
|
87 | label->set(mSeries->label(i)); | |
@@ -90,7 +90,7 void BarPresenterBase::dataChanged() | |||||
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | // Create separators |
|
92 | // Create separators | |
93 |
count = mSeries->c |
|
93 | count = mSeries->categoryCount() - 1; // There is one less separator than columns | |
94 | for (int i=0; i<count; i++) { |
|
94 | for (int i=0; i<count; i++) { | |
95 | Separator* sep = new Separator(this); |
|
95 | Separator* sep = new Separator(this); | |
96 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme |
|
96 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme | |
@@ -100,8 +100,8 void BarPresenterBase::dataChanged() | |||||
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | // Create floating values |
|
102 | // Create floating values | |
103 |
for (int category=0; category<mSeries->c |
|
103 | for (int category=0; category<mSeries->categoryCount(); category++) { | |
104 |
for (int s=0; s<mSeries-> |
|
104 | for (int s=0; s<mSeries->barsetCount(); s++) { | |
105 | QBarSet *set = mSeries->barsetAt(s); |
|
105 | QBarSet *set = mSeries->barsetAt(s); | |
106 | BarValue *value = new BarValue(*set, this); |
|
106 | BarValue *value = new BarValue(*set, this); | |
107 | childItems().append(value); |
|
107 | childItems().append(value); |
@@ -18,7 +18,7 void PercentBarPresenter::layoutChanged() | |||||
18 | { |
|
18 | { | |
19 | // Scale bars to new layout |
|
19 | // Scale bars to new layout | |
20 | // Layout for bars: |
|
20 | // Layout for bars: | |
21 |
if (mSeries-> |
|
21 | if (mSeries->barsetCount() <= 0) { | |
22 | qDebug() << "No sets in model!"; |
|
22 | qDebug() << "No sets in model!"; | |
23 | // Nothing to do. |
|
23 | // Nothing to do. | |
24 | return; |
|
24 | return; | |
@@ -31,7 +31,7 void PercentBarPresenter::layoutChanged() | |||||
31 |
|
31 | |||
32 | // TODO: better way to auto-layout |
|
32 | // TODO: better way to auto-layout | |
33 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
33 | // Use reals for accurancy (we might get some compiler warnings... :) | |
34 |
int count = mSeries->c |
|
34 | int count = mSeries->categoryCount(); | |
35 | int itemIndex(0); |
|
35 | int itemIndex(0); | |
36 | int labelIndex(0); |
|
36 | int labelIndex(0); | |
37 | qreal tW = mWidth; |
|
37 | qreal tW = mWidth; | |
@@ -40,11 +40,11 void PercentBarPresenter::layoutChanged() | |||||
40 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
40 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
41 | qreal h = mHeight; |
|
41 | qreal h = mHeight; | |
42 |
|
42 | |||
43 |
for (int category = 0; category < mSeries->c |
|
43 | for (int category = 0; category < mSeries->categoryCount(); category++) { | |
44 | qreal colSum = mSeries->categorySum(category); |
|
44 | qreal colSum = mSeries->categorySum(category); | |
45 | qreal scale = (h / colSum); |
|
45 | qreal scale = (h / colSum); | |
46 | qreal yPos = h; |
|
46 | qreal yPos = h; | |
47 |
for (int set=0; set < mSeries-> |
|
47 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
48 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
48 | qreal barHeight = mSeries->valueAt(set, category) * scale; | |
49 | Bar* bar = mBars.at(itemIndex); |
|
49 | Bar* bar = mBars.at(itemIndex); | |
50 |
|
50 | |||
@@ -65,7 +65,7 void PercentBarPresenter::layoutChanged() | |||||
65 |
|
65 | |||
66 | // Position separators |
|
66 | // Position separators | |
67 | xPos = xStep + xStep/2; |
|
67 | xPos = xStep + xStep/2; | |
68 |
for (int s=0; s < mSeries->c |
|
68 | for (int s=0; s < mSeries->categoryCount() - 1; s++) { | |
69 | Separator* sep = mSeparators.at(s); |
|
69 | Separator* sep = mSeparators.at(s); | |
70 | sep->setPos(xPos,0); |
|
70 | sep->setPos(xPos,0); | |
71 | sep->setSize(QSizeF(1,mHeight)); |
|
71 | sep->setSize(QSizeF(1,mHeight)); | |
@@ -75,11 +75,11 void PercentBarPresenter::layoutChanged() | |||||
75 | // Position floating values |
|
75 | // Position floating values | |
76 | itemIndex = 0; |
|
76 | itemIndex = 0; | |
77 | xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
77 | xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
78 |
for (int category=0; category < mSeries->c |
|
78 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
79 | qreal yPos = h; |
|
79 | qreal yPos = h; | |
80 | qreal colSum = mSeries->categorySum(category); |
|
80 | qreal colSum = mSeries->categorySum(category); | |
81 | qreal scale = (h / colSum); |
|
81 | qreal scale = (h / colSum); | |
82 |
for (int set=0; set < mSeries-> |
|
82 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
83 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
83 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
84 | BarValue* value = mFloatingValues.at(itemIndex); |
|
84 | BarValue* value = mFloatingValues.at(itemIndex); | |
85 |
|
85 |
@@ -76,7 +76,7 void QBarSeries::removeBarSet(QBarSet *set) | |||||
76 | /*! |
|
76 | /*! | |
77 | Returns number of sets in series. |
|
77 | Returns number of sets in series. | |
78 | */ |
|
78 | */ | |
79 |
int QBarSeries:: |
|
79 | int QBarSeries::barsetCount() | |
80 | { |
|
80 | { | |
81 | return mModel->countSets(); |
|
81 | return mModel->countSets(); | |
82 | } |
|
82 | } | |
@@ -84,7 +84,7 int QBarSeries::countSets() | |||||
84 | /*! |
|
84 | /*! | |
85 | Returns number of categories in series |
|
85 | Returns number of categories in series | |
86 | */ |
|
86 | */ | |
87 |
int QBarSeries::c |
|
87 | int QBarSeries::categoryCount() | |
88 | { |
|
88 | { | |
89 | return mModel->countCategories(); |
|
89 | return mModel->countCategories(); | |
90 | } |
|
90 | } |
@@ -20,8 +20,8 public: | |||||
20 |
|
20 | |||
21 | void addBarSet(QBarSet *set); // Takes ownership of set |
|
21 | void addBarSet(QBarSet *set); // Takes ownership of set | |
22 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
22 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
23 |
int |
|
23 | int barsetCount(); | |
24 |
int c |
|
24 | int categoryCount(); | |
25 | QList<QBarSet*> barSets(); |
|
25 | QList<QBarSet*> barSets(); | |
26 |
|
26 | |||
27 | QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) |
|
27 | QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) |
@@ -17,13 +17,13 void StackedBarPresenter::layoutChanged() | |||||
17 | { |
|
17 | { | |
18 | // Scale bars to new layout |
|
18 | // Scale bars to new layout | |
19 | // Layout for bars: |
|
19 | // Layout for bars: | |
20 |
if (mSeries-> |
|
20 | if (mSeries->barsetCount() <= 0) { | |
21 | qDebug() << "No sets in model!"; |
|
21 | qDebug() << "No sets in model!"; | |
22 | // Nothing to do. |
|
22 | // Nothing to do. | |
23 | return; |
|
23 | return; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 |
if (mSeries->c |
|
26 | if (mSeries->categoryCount() == 0) { | |
27 | qDebug() << "No categories in model!"; |
|
27 | qDebug() << "No categories in model!"; | |
28 | // Nothing to do |
|
28 | // Nothing to do | |
29 | return; |
|
29 | return; | |
@@ -44,13 +44,13 void StackedBarPresenter::layoutChanged() | |||||
44 | int itemIndex(0); |
|
44 | int itemIndex(0); | |
45 | int labelIndex(0); |
|
45 | int labelIndex(0); | |
46 | qreal tW = mWidth; |
|
46 | qreal tW = mWidth; | |
47 |
qreal tC = mSeries->c |
|
47 | qreal tC = mSeries->categoryCount() + 1; | |
48 | qreal xStep = (tW/tC); |
|
48 | qreal xStep = (tW/tC); | |
49 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
49 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
50 |
|
50 | |||
51 |
for (int category = 0; category < mSeries->c |
|
51 | for (int category = 0; category < mSeries->categoryCount(); category++) { | |
52 | qreal yPos = h; |
|
52 | qreal yPos = h; | |
53 |
for (int set=0; set < mSeries-> |
|
53 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
54 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
54 | qreal barHeight = mSeries->valueAt(set, category) * scale; | |
55 | Bar* bar = mBars.at(itemIndex); |
|
55 | Bar* bar = mBars.at(itemIndex); | |
56 |
|
56 | |||
@@ -70,7 +70,7 void StackedBarPresenter::layoutChanged() | |||||
70 |
|
70 | |||
71 | // Position separators |
|
71 | // Position separators | |
72 | xPos = xStep + xStep/2; |
|
72 | xPos = xStep + xStep/2; | |
73 |
for (int s=0; s < mSeries->c |
|
73 | for (int s=0; s < mSeries->categoryCount() - 1; s++) { | |
74 | Separator* sep = mSeparators.at(s); |
|
74 | Separator* sep = mSeparators.at(s); | |
75 | sep->setPos(xPos,0); |
|
75 | sep->setPos(xPos,0); | |
76 | sep->setSize(QSizeF(1,mHeight)); |
|
76 | sep->setSize(QSizeF(1,mHeight)); | |
@@ -80,9 +80,9 void StackedBarPresenter::layoutChanged() | |||||
80 | // Position floating values |
|
80 | // Position floating values | |
81 | itemIndex = 0; |
|
81 | itemIndex = 0; | |
82 | xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
82 | xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
83 |
for (int category=0; category < mSeries->c |
|
83 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
84 | qreal yPos = h; |
|
84 | qreal yPos = h; | |
85 |
for (int set=0; set < mSeries-> |
|
85 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
86 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
86 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
87 | BarValue* value = mFloatingValues.at(itemIndex); |
|
87 | BarValue* value = mFloatingValues.at(itemIndex); | |
88 |
|
88 |
@@ -73,7 +73,7 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
73 | case QSeries::SeriesTypeBar: { |
|
73 | case QSeries::SeriesTypeBar: { | |
74 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
74 | qDebug() << "QChartSeries::SeriesTypeBar"; | |
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
76 |
qreal x = barSeries->c |
|
76 | qreal x = barSeries->categoryCount(); | |
77 | qreal y = barSeries->max(); |
|
77 | qreal y = barSeries->max(); | |
78 | domain.m_minX = qMin(domain.m_minX,x); |
|
78 | domain.m_minX = qMin(domain.m_minX,x); | |
79 | domain.m_minY = qMin(domain.m_minY,y); |
|
79 | domain.m_minY = qMin(domain.m_minY,y); | |
@@ -85,7 +85,7 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; | |
86 |
|
86 | |||
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
88 |
qreal x = stackedBarSeries->c |
|
88 | qreal x = stackedBarSeries->categoryCount(); | |
89 | qreal y = stackedBarSeries->maxCategorySum(); |
|
89 | qreal y = stackedBarSeries->maxCategorySum(); | |
90 | domain.m_minX = qMin(domain.m_minX,x); |
|
90 | domain.m_minX = qMin(domain.m_minX,x); | |
91 | domain.m_minY = qMin(domain.m_minY,y); |
|
91 | domain.m_minY = qMin(domain.m_minY,y); | |
@@ -97,7 +97,7 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; | |
98 |
|
98 | |||
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
100 |
qreal x = percentBarSeries->c |
|
100 | qreal x = percentBarSeries->categoryCount(); | |
101 | domain.m_minX = qMin(domain.m_minX,x); |
|
101 | domain.m_minX = qMin(domain.m_minX,x); | |
102 | domain.m_minY = 0; |
|
102 | domain.m_minY = 0; | |
103 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
103 | domain.m_maxX = qMax(domain.m_maxX,x); |
@@ -144,7 +144,7 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count) | |||||
144 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) |
|
144 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) | |
145 | { |
|
145 | { | |
146 | QList<QBarSet*> sets = series->barSets(); |
|
146 | QList<QBarSet*> sets = series->barSets(); | |
147 |
for (int i=0; i<series-> |
|
147 | for (int i=0; i<series->barsetCount(); i++) { | |
148 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
148 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
149 | } |
|
149 | } | |
150 | } |
|
150 | } | |
@@ -152,7 +152,7 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) | |||||
152 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count) |
|
152 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count) | |
153 | { |
|
153 | { | |
154 | QList<QBarSet*> sets = series->barSets(); |
|
154 | QList<QBarSet*> sets = series->barSets(); | |
155 |
for (int i=0; i<series-> |
|
155 | for (int i=0; i<series->barsetCount(); i++) { | |
156 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
156 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
157 | } |
|
157 | } | |
158 | } |
|
158 | } | |
@@ -160,7 +160,7 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,i | |||||
160 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count) |
|
160 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count) | |
161 | { |
|
161 | { | |
162 | QList<QBarSet*> sets = series->barSets(); |
|
162 | QList<QBarSet*> sets = series->barSets(); | |
163 |
for (int i=0; i<series-> |
|
163 | for (int i=0; i<series->barsetCount(); i++) { | |
164 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
164 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
165 | } |
|
165 | } | |
166 | } |
|
166 | } |
@@ -271,7 +271,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS | |||||
271 | series->addBarSet(set); |
|
271 | series->addBarSet(set); | |
272 | } |
|
272 | } | |
273 | series->setFloatingValuesEnabled(true); |
|
273 | series->setFloatingValuesEnabled(true); | |
274 | series->setToolTipEnabled(); |
|
274 | series->setToolTipEnabled(true); | |
275 | series->setSeparatorsEnabled(false); |
|
275 | series->setSeparatorsEnabled(false); | |
276 | m_chartWidget->addSeries(series); |
|
276 | m_chartWidget->addSeries(series); | |
277 | setCurrentSeries(series); |
|
277 | setCurrentSeries(series); |
General Comments 0
You need to be logged in to leave comments.
Login now