SLOTs for changes triggered in the dock widget used in worksheet element docks
| 124 | //************************************************************* |
| 125 | // used in worksheet element docks |
| 126 | void BaseDock::plotRangeChanged(int index) { |
| 127 | if (m_suppressPlotRetransform) |
| 128 | return; |
| 129 | DEBUG(Q_FUNC_INFO << ", index = " << index) |
| 130 | |
| 131 | auto* element{static_cast<WorksheetElement*>(m_aspect)}; |
| 132 | CartesianPlot* plot; |
| 133 | if (element->plot()) |
| 134 | plot = element->plot(); |
| 135 | else |
| 136 | plot = dynamic_cast<CartesianPlot*>(m_aspect->parentAspect()); |
| 137 | |
| 138 | if (!plot) |
| 139 | return; |
| 140 | |
| 141 | if (index < 0 || index > plot->coordinateSystemCount()) { |
| 142 | index = element->coordinateSystemIndex(); |
| 143 | DEBUG(Q_FUNC_INFO << ", using default index " << index) |
| 144 | } |
| 145 | |
| 146 | const int xIndexNew = plot->coordinateSystem(index)->index(Dimension::X); |
| 147 | const int yIndexNew = plot->coordinateSystem(index)->index(Dimension::Y); |
| 148 | |
| 149 | bool xIndexNewDifferent = false; |
| 150 | bool yIndexNewDifferent = false; |
| 151 | QVector<int> xRangesChanged; |
| 152 | QVector<int> yRangesChanged; |
| 153 | for (auto aspect : m_aspects) { |
| 154 | auto* e{static_cast<WorksheetElement*>(aspect)}; |
| 155 | if (index != e->coordinateSystemIndex()) { |
| 156 | const auto* elementOldCSystem = plot->coordinateSystem(e->coordinateSystemIndex()); |
| 157 | const auto xIndexOld = elementOldCSystem->index(Dimension::X); |
| 158 | const auto yIndexOld = elementOldCSystem->index(Dimension::Y); |
| 159 | // If indices are same, the range will not change, so do not track those |
| 160 | if (xIndexOld != xIndexNew) { |
| 161 | xIndexNewDifferent = true; |
| 162 | if (!xRangesChanged.contains(xIndexOld)) |
| 163 | xRangesChanged.append(xIndexOld); |
| 164 | } |
| 165 | if (yIndexOld != yIndexNew) { |
| 166 | yIndexNewDifferent = true; |
| 167 | if (!yRangesChanged.contains(yIndexOld)) |
| 168 | yRangesChanged.append(yIndexOld); |
| 169 | } |
| 170 | e->setSuppressRetransform(true); |
| 171 | e->setCoordinateSystemIndex(index); |
| 172 | e->setSuppressRetransform(false); |
| 173 | if (dynamic_cast<Axis*>(e) && dynamic_cast<AxisDock*>(this)) |
| 174 | dynamic_cast<AxisDock*>(this)->updateAutoScale(); |
| 175 | updateLocale(); // update line edits |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | // Retransform all changed indices and the new indices |
| 180 | if (!xRangesChanged.contains(xIndexNew) && xIndexNewDifferent) |
| 181 | xRangesChanged.append(xIndexNew); |
| 182 | for (const int index : xRangesChanged) { |
| 183 | plot->setRangeDirty(Dimension::X, index, true); |