MCPcopy Create free account
hub / github.com/KDE/labplot / removeRange

Method removeRange

src/frontend/dockwidgets/CartesianPlotDock.cpp:1126–1188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1124}
1125
1126void CartesianPlotDock::removeRange(const Dimension dim) {
1127 if (!m_plot)
1128 return;
1129
1130 QTableWidget* treewidget = ui.twXRanges;
1131 switch (dim) {
1132 case Dimension::X:
1133 break;
1134 case Dimension::Y:
1135 treewidget = ui.twYRanges;
1136 break;
1137 }
1138
1139 int currentRow{treewidget->currentRow()};
1140 QDEBUG(Q_FUNC_INFO << ", current range = " << currentRow)
1141 if (currentRow < 0 || currentRow > m_plot->rangeCount(dim)) {
1142 DEBUG(Q_FUNC_INFO << ", no current range")
1143 currentRow = m_plot->rangeCount(dim) - 1;
1144 }
1145 QDEBUG(Q_FUNC_INFO << ", removing range " << currentRow)
1146
1147 // check plot ranges using range to remove
1148 const int cSystemCount{m_plot->coordinateSystemCount()};
1149 DEBUG(Q_FUNC_INFO << ", nr of cSystems = " << cSystemCount)
1150 QString msg;
1151 for (int i{0}; i < cSystemCount; i++) {
1152 const auto* cSystem{m_plot->coordinateSystem(i)};
1153
1154 if (cSystem->index(dim) == currentRow) {
1155 if (msg.size() > 0)
1156 msg += QStringLiteral(", ");
1157 msg += QString::number(i + 1);
1158 }
1159 }
1160
1161 if (msg.size() > 0) {
1162 DEBUG(Q_FUNC_INFO << ", range used in plot range " << STDSTRING(msg))
1163
1164 auto status = KMessageBox::warningTwoActions(
1165 this,
1166 i18n("%1 range %2 is used in plot range %3. ", CartesianCoordinateSystem::dimensionToString(dim).toUpper(), currentRow + 1, msg)
1167 + i18n("Really remove it?"),
1168 QString(),
1169 KStandardGuiItem::remove(),
1170 KStandardGuiItem::cancel());
1171 if (status == KMessageBox::SecondaryAction)
1172 return;
1173 else {
1174 // reset x ranges of cSystems using the range to be removed
1175 for (int i{0}; i < cSystemCount; i++) {
1176 auto* cSystem{m_plot->coordinateSystem(i)};
1177
1178 if (cSystem->index(dim) == currentRow)
1179 m_plot->setCoordinateSystemRangeIndex(i, dim, 0); // first range
1180 else if (cSystem->index(dim) > currentRow)
1181 m_plot->setCoordinateSystemRangeIndex(i, dim, cSystem->index(dim) - 1);
1182 }
1183 }

Callers

nothing calls this directly

Calls 7

QStringClass · 0.50
rangeCountMethod · 0.45
coordinateSystemCountMethod · 0.45
coordinateSystemMethod · 0.45
indexMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected