MCPcopy Create free account
hub / github.com/ZhuYanzhen1/miniFOC / keyPixelOffset

Method keyPixelOffset

tools/qcustomplot.cpp:24153–24207  ·  view source on GitHub ↗

! \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. */

Source from the content-addressed store, hash-verified

24151 coordinate \a keyCoord.
24152*/
24153double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord)
24154{
24155 // find list of all base bars in case some mBars are stacked:
24156 QList<const QCPBars*> baseBars;
24157 foreach (const QCPBars *b, mBars)
24158 {
24159 while (b->barBelow())
24160 b = b->barBelow();
24161 if (!baseBars.contains(b))
24162 baseBars.append(b);
24163 }
24164 // find base bar this "bars" is stacked on:
24165 const QCPBars *thisBase = bars;
24166 while (thisBase->barBelow())
24167 thisBase = thisBase->barBelow();
24168
24169 // determine key pixel offset of this base bars considering all other base bars in this barsgroup:
24170 double result = 0;
24171 int index = baseBars.indexOf(thisBase);
24172 if (index >= 0)
24173 {
24174 if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose)
24175 {
24176 return result;
24177 } else
24178 {
24179 double lowerPixelWidth, upperPixelWidth;
24180 int startIndex;
24181 int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative
24182 if (baseBars.size() % 2 == 0) // even number of bars
24183 {
24184 startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0);
24185 result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing
24186 } else // uneven number of bars
24187 {
24188 startIndex = (baseBars.size()-1)/2+dir;
24189 baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth);
24190 result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar
24191 result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing
24192 }
24193 for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars
24194 {
24195 baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth);
24196 result += qAbs(upperPixelWidth-lowerPixelWidth);
24197 result += getPixelSpacing(baseBars.at(i), keyCoord);
24198 }
24199 // finally half of our bars width:
24200 baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth);
24201 result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5;
24202 // correct sign of result depending on orientation and direction of key axis:
24203 result *= dir*thisBase->keyAxis()->pixelOrientation();
24204 }
24205 }
24206 return result;
24207}
24208
24209/*! \internal
24210

Callers 3

getKeyRangeMethod · 0.80
dataPixelPositionMethod · 0.80
getBarRectMethod · 0.80

Calls 3

atMethod · 0.80
getPixelWidthMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected