! \internal Returns the pixel offset in the key dimension the specified \a bars plottable should have at the given key coordinate \a keyCoord. The offset is relative to the pixel position of the key coordinate \a keyCoord. */
| 24186 | coordinate \a keyCoord. |
| 24187 | */ |
| 24188 | double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) |
| 24189 | { |
| 24190 | // find list of all base bars in case some mBars are stacked: |
| 24191 | QList<const QCPBars*> baseBars; |
| 24192 | foreach (const QCPBars *b, mBars) |
| 24193 | { |
| 24194 | while (b->barBelow()) |
| 24195 | b = b->barBelow(); |
| 24196 | if (!baseBars.contains(b)) |
| 24197 | baseBars.append(b); |
| 24198 | } |
| 24199 | // find base bar this "bars" is stacked on: |
| 24200 | const QCPBars *thisBase = bars; |
| 24201 | while (thisBase->barBelow()) |
| 24202 | thisBase = thisBase->barBelow(); |
| 24203 | |
| 24204 | // determine key pixel offset of this base bars considering all other base bars in this barsgroup: |
| 24205 | double result = 0; |
| 24206 | int index = baseBars.indexOf(thisBase); |
| 24207 | if (index >= 0) |
| 24208 | { |
| 24209 | if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) |
| 24210 | { |
| 24211 | return result; |
| 24212 | } else |
| 24213 | { |
| 24214 | double lowerPixelWidth, upperPixelWidth; |
| 24215 | int startIndex; |
| 24216 | int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative |
| 24217 | if (baseBars.size() % 2 == 0) // even number of bars |
| 24218 | { |
| 24219 | startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); |
| 24220 | result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing |
| 24221 | } else // uneven number of bars |
| 24222 | { |
| 24223 | startIndex = (baseBars.size()-1)/2+dir; |
| 24224 | baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); |
| 24225 | result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar |
| 24226 | result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing |
| 24227 | } |
| 24228 | for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars |
| 24229 | { |
| 24230 | baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); |
| 24231 | result += qAbs(upperPixelWidth-lowerPixelWidth); |
| 24232 | result += getPixelSpacing(baseBars.at(i), keyCoord); |
| 24233 | } |
| 24234 | // finally half of our bars width: |
| 24235 | baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); |
| 24236 | result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; |
| 24237 | // correct sign of result depending on orientation and direction of key axis: |
| 24238 | result *= dir*thisBase->keyAxis()->pixelOrientation(); |
| 24239 | } |
| 24240 | } |
| 24241 | return result; |
| 24242 | } |
| 24243 | |
| 24244 | /*! \internal |
| 24245 |
no test coverage detected