MCPcopy Create free account
hub / github.com/CieNTi/serial_port_plotter / keyPixelOffset

Method keyPixelOffset

qcustomplot/qcustomplot.cpp:23395–23449  ·  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

23393 coordinate \a keyCoord.
23394*/
23395double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord)
23396{
23397 // find list of all base bars in case some mBars are stacked:
23398 QList<const QCPBars*> baseBars;
23399 foreach (const QCPBars *b, mBars)
23400 {
23401 while (b->barBelow())
23402 b = b->barBelow();
23403 if (!baseBars.contains(b))
23404 baseBars.append(b);
23405 }
23406 // find base bar this "bars" is stacked on:
23407 const QCPBars *thisBase = bars;
23408 while (thisBase->barBelow())
23409 thisBase = thisBase->barBelow();
23410
23411 // determine key pixel offset of this base bars considering all other base bars in this barsgroup:
23412 double result = 0;
23413 int index = baseBars.indexOf(thisBase);
23414 if (index >= 0)
23415 {
23416 if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose)
23417 {
23418 return result;
23419 } else
23420 {
23421 double lowerPixelWidth, upperPixelWidth;
23422 int startIndex;
23423 int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative
23424 if (baseBars.size() % 2 == 0) // even number of bars
23425 {
23426 startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0);
23427 result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing
23428 } else // uneven number of bars
23429 {
23430 startIndex = (baseBars.size()-1)/2+dir;
23431 baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth);
23432 result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar
23433 result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing
23434 }
23435 for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars
23436 {
23437 baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth);
23438 result += qAbs(upperPixelWidth-lowerPixelWidth);
23439 result += getPixelSpacing(baseBars.at(i), keyCoord);
23440 }
23441 // finally half of our bars width:
23442 baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth);
23443 result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5;
23444 // correct sign of result depending on orientation and direction of key axis:
23445 result *= dir*thisBase->keyAxis()->pixelOrientation();
23446 }
23447 }
23448 return result;
23449}
23450
23451/*! \internal
23452

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