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

Method setSelectedColumns

src/frontend/spreadsheet/PlotDataDialog.cpp:217–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217void PlotDataDialog::setSelectedColumns(QVector<Column*> selectedColumns) {
218 // skip error and non-plottable columns
219 for (Column* col : selectedColumns) {
220 if ((col->plotDesignation() == AbstractColumn::PlotDesignation::X || col->plotDesignation() == AbstractColumn::PlotDesignation::Y
221 || col->plotDesignation() == AbstractColumn::PlotDesignation::NoDesignation)
222 && col->isPlottable())
223 m_columns << col;
224 }
225
226 // disable everything if the spreadsheet doesn't have any columns to plot
227 if (m_columns.isEmpty()) {
228 ui->gbCurvePlacement->setEnabled(false);
229 ui->gbPlotPlacement->setEnabled(false);
230 return;
231 }
232
233 // determine the column names
234 // and the name of the first column having "X" as the plot designation (relevant for xy-curves only)
235 QStringList columnNames;
236 QString xColumnName;
237 for (const Column* column : m_columns) {
238 columnNames << column->name();
239 if (m_basicPlotType && xColumnName.isEmpty() && column->plotDesignation() == AbstractColumn::PlotDesignation::X)
240 xColumnName = column->name();
241 }
242
243 if (m_basicPlotType && xColumnName.isEmpty()) {
244 // no X-column was selected -> look for the first non-selected X-column left to the first selected column
245 const auto& columns = m_parentAspect->children<Column>();
246 const int index = columns.indexOf(selectedColumns.first()) - 1;
247 for (int i = index; i >= 0; --i) {
248 auto* column = columns.at(i);
249 if (column->plotDesignation() == AbstractColumn::PlotDesignation::X && column->isPlottable()) {
250 xColumnName = column->name();
251 m_columns.prepend(column);
252 columnNames.prepend(xColumnName);
253 break;
254 }
255 }
256
257 if (xColumnName.isEmpty()) {
258 // no X-column was found left to the first selected column -> look right to the last selected column
259 const int index = columns.indexOf(selectedColumns.last()) + 1;
260 for (int i = index; i < columns.count(); ++i) {
261 auto* column = columns.at(i);
262 if (column->plotDesignation() == AbstractColumn::PlotDesignation::X && column->isPlottable()) {
263 xColumnName = column->name();
264 m_columns.prepend(column);
265 columnNames.prepend(xColumnName);
266 break;
267 }
268 }
269 }
270 }
271
272 if (m_basicPlotType && !m_fitDistributionMode)
273 processColumnsForXYCurve(columnNames, xColumnName);
274 else

Callers 4

plotDataMethod · 0.80
plotDataMethod · 0.80
plotAnalysisDataMethod · 0.80

Calls 11

isPlottableMethod · 0.80
heightMethod · 0.80
plotDesignationMethod · 0.45
isEmptyMethod · 0.45
setEnabledMethod · 0.45
nameMethod · 0.45
indexOfMethod · 0.45
countMethod · 0.45
sizeMethod · 0.45
widgetMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected