@@ -54,7 +54,7 int BarChartSeries::max() | |||
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | |
|
57 |
int BarChartSeries::count |
|
|
57 | int BarChartSeries::countRows() | |
|
58 | 58 | { |
|
59 | 59 | return mModel->rowCount(); |
|
60 | 60 | } |
@@ -27,7 +27,7 public: | |||
|
27 | 27 | // Methods to find out minimum and maximum values of data |
|
28 | 28 | int min(); |
|
29 | 29 | int max(); |
|
30 |
int count |
|
|
30 | int countRows(); | |
|
31 | 31 | int countColumns(); // Count items in one series. |
|
32 | 32 | int countTotalItems(); |
|
33 | 33 | int valueAt(int row, int column); |
@@ -95,32 +95,64 void BarGroup::layoutChanged() | |||
|
95 | 95 | { |
|
96 | 96 | // Scale bars to new layout |
|
97 | 97 | // Layout for bars: |
|
98 |
if (mSeries.count |
|
|
98 | if (mSeries.countRows() <= 0) { | |
|
99 | 99 | // Nothing to do. |
|
100 | 100 | return; |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | // TODO: better way to auto-layout |
|
104 | int count = mSeries.countColumns(); | |
|
105 | int posStep = (mWidth / (count+1)); | |
|
106 | int startPos = (mWidth / (count+1)) - mSeries.countSeries() * mBarDefaultWidth /2; | |
|
107 | qDebug() << "startpos" << startPos; | |
|
104 | // Use reals for accurancy (we might get some compiler warnings... :) | |
|
105 | int columnCount = mSeries.countColumns(); | |
|
106 | int rowCount = mSeries.countRows(); | |
|
108 | 107 | |
|
108 | qreal tW = mWidth; | |
|
109 | qreal tH = mHeight; | |
|
110 | qreal tM = mMax; | |
|
111 | qreal scale = (tH/tM); | |
|
112 | ||
|
113 | qreal tC = columnCount+1; | |
|
114 | qreal xStepPerSeries = (tW/tC); | |
|
115 | ||
|
116 | //qint startPos = (mWidth / (count+1)) - mSeries.countSeries() * mBarDefaultWidth /2; | |
|
117 | // qDebug() << "XPOS:" << xPos; | |
|
118 | ||
|
119 | qDebug() << "XSTEP:" << xStepPerSeries; | |
|
120 | ||
|
121 | // TODO: Correct the calculations... | |
|
109 | 122 | // Scaling. |
|
110 | 123 | int itemIndex(0); |
|
111 | for (int series = 0; series < mSeries.countSeries(); series++) { | |
|
124 | for (int column=0; column < columnCount; column++) { | |
|
125 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); | |
|
126 | qDebug() << "XPOS:" << xPos; | |
|
127 | for (int row = 0; row < rowCount; row++) { | |
|
128 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
|
129 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
|
130 | ||
|
131 | // TODO: width settable per bar? | |
|
132 | bar->resize(mBarDefaultWidth, barHeight); | |
|
133 | bar->setColor(mColors.at(row)); | |
|
134 | bar->setPos(xPos, mHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); | |
|
135 | itemIndex++; | |
|
136 | xPos += mBarDefaultWidth; | |
|
137 | } | |
|
138 | } | |
|
139 | ||
|
140 | /* | |
|
141 | for (int series = 0; series < mSeries.countRows(); series++) { | |
|
112 | 142 | for (int item=0; item < mSeries.countColumns(); item++) { |
|
113 | qDebug() << itemIndex; | |
|
114 | int barHeight = mSeries.valueAt(series, item) * mHeight / mMax; | |
|
143 | qreal barHeight = mSeries.valueAt(series, item) * scale; | |
|
115 | 144 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
116 | 145 |
|
|
117 | 146 | // TODO: width settable per bar? |
|
118 | 147 | bar->resize(mBarDefaultWidth, barHeight); |
|
119 | 148 | bar->setColor(mColors.at(series)); |
|
120 | bar->setPos(item*posStep+startPos + series * mBarDefaultWidth, mHeight); | |
|
149 | bar->setPos(xPos, mHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); | |
|
121 | 150 | itemIndex++; |
|
151 | xPos += mBarDefaultWidth; | |
|
122 | 152 | } |
|
153 | xPos = xStepPerSeries * series; | |
|
123 | 154 | } |
|
155 | */ | |
|
124 | 156 | mLayoutDirty = true; |
|
125 | 157 | } |
|
126 | 158 |
@@ -101,7 +101,7 void StackedBarGroup::layoutChanged() | |||
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | // TODO: better way to auto-layout |
|
104 |
// Use reals for accurancy ( |
|
|
104 | // Use reals for accurancy (we might get some compiler warnings... :) | |
|
105 | 105 | qreal maxSum = mSeries.maxColumnSum(); |
|
106 | 106 | qreal h = mHeight; |
|
107 | 107 | qreal scale = (h / maxSum); |
General Comments 0
You need to be logged in to leave comments.
Login now