MCPcopy Create free account
hub / github.com/KDAB/KDChart / TickIterator

Method TickIterator

src/KDChart/Cartesian/KDChartCartesianAxis.cpp:68–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66// remaining labels.
67
68TickIterator::TickIterator(CartesianAxis *a, CartesianCoordinatePlane *plane, uint majorThinningFactor,
69 bool omitLastTick)
70 : m_axis(a)
71 , m_majorThinningFactor(majorThinningFactor)
72 , m_majorLabelCount(0)
73 , m_type(NoTick)
74{
75 // deal with the things that are specific to axes (like annotations), before the generic init().
76 const CartesianAxis::Private *axisPriv = CartesianAxis::Private::get(a);
77 XySwitch xy(axisPriv->isVertical());
78 m_dimension = xy(plane->gridDimensionsList().first(), plane->gridDimensionsList().last());
79 if (omitLastTick) {
80 // In bar and stock charts the last X tick is a fencepost with no associated value, which is
81 // convenient for grid painting. Here we have to manually exclude it to avoid overpainting.
82 m_dimension.end -= m_dimension.stepWidth;
83 }
84
85 m_annotations = axisPriv->annotations;
86 m_customTicks = axisPriv->customTicksPositions;
87
88 const qreal inf = std::numeric_limits<qreal>::infinity();
89
90 if (m_customTicks.count()) {
91 std::sort(m_customTicks.begin(), m_customTicks.end());
92 m_customTickIndex = 0;
93 m_customTick = m_customTicks.at(m_customTickIndex);
94 } else {
95 m_customTickIndex = -1;
96 m_customTick = inf;
97 }
98
99 if (m_majorThinningFactor > 1 && hasShorterLabels()) {
100 m_manualLabelTexts = m_axis->shortLabels();
101 } else {
102 m_manualLabelTexts = m_axis->labels();
103 }
104 m_manualLabelIndex = m_manualLabelTexts.isEmpty() ? -1 : 0;
105
106 if (!m_dimension.isCalculated) {
107 // ### depending on the data, it is difficult to impossible to choose anchors (where ticks
108 // corresponding to the header labels are) on the ordinate or even the abscissa with
109 // 2-dimensional data. this should be somewhat mitigated by isCalculated only being false
110 // when header data labels should work, at least that seems to be what the code that sets up
111 // the dimensions is trying to do.
112 QStringList dataHeaderLabels;
113 AbstractDiagram *const dia = plane->diagram();
114 dataHeaderLabels = dia->itemRowLabels();
115 if (!dataHeaderLabels.isEmpty()) {
116 AttributesModel *model = dia->attributesModel();
117 const int anchorCount = model->rowCount(QModelIndex());
118 if (anchorCount == dataHeaderLabels.count()) {
119 for (int i = 0; i < anchorCount; i++) {
120 // ### ordinal number as anchor point generally only works for 1-dimensional data
121 m_dataHeaderLabels.insert(qreal(i), dataHeaderLabels.at(i));
122 }
123 }
124 }
125 }

Callers

nothing calls this directly

Calls 15

allAxisAnnotationsFunction · 0.85
isVerticalMethod · 0.80
gridDimensionsListMethod · 0.80
shortLabelsMethod · 0.80
labelsMethod · 0.80
itemRowLabelsMethod · 0.80
showMajorTickMarksMethod · 0.80
rulerAttributesMethod · 0.80
showMinorTickMarksMethod · 0.80
QModelIndexClass · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected