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

Method flags

src/backend/core/AspectTreeModel.cpp:289–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289Qt::ItemFlags AspectTreeModel::flags(const QModelIndex& index) const {
290 if (!index.isValid())
291 return Qt::NoItemFlags;
292
293 Qt::ItemFlags result;
294 auto* aspect = static_cast<AbstractAspect*>(index.internalPointer());
295
296 if (!m_selectableAspects.isEmpty()) {
297 for (AspectType type : m_selectableAspects) {
298 if (aspect->inherits(type)) {
299 result = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
300 if (index != this->index(0, 0, QModelIndex()) && !m_filterString.isEmpty()) {
301 if (this->containsFilterString(aspect))
302 result = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
303 else
304 result &= ~Qt::ItemIsEnabled;
305 }
306 break;
307 } else
308 result &= ~Qt::ItemIsEnabled;
309 }
310 } else {
311 // default case: the list for the selectable aspects is empty and all aspects are selectable.
312 // Apply filter, if available. Indices, that don't match the filter are not selectable.
313 // Don't apply any filter to the very first index in the model - this top index corresponds to the project item.
314 if (index != this->index(0, 0, QModelIndex()) && !m_filterString.isEmpty()) {
315 if (this->containsFilterString(aspect))
316 result = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
317 else
318 result = Qt::ItemIsSelectable;
319 } else
320 result = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
321 }
322
323 // the columns "name" and "description" are editable
324 if (!m_readOnly) {
325 if (index.column() == 0 || index.column() == 3)
326 result |= Qt::ItemIsEditable;
327 }
328
329 const auto* column = dynamic_cast<const Column*>(aspect);
330 if (column) {
331 // allow to drag and drop columns for the faster creation of curves in the plots.
332 // TODO: allow drag&drop later for other objects too, once we implement copy and paste in the project explorer
333 result = result | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
334
335 if (m_plottableColumnsOnly && !column->isPlottable())
336 result &= ~Qt::ItemIsEnabled;
337
338 if (m_numericColumnsOnly && !column->isNumeric())
339 result &= ~Qt::ItemIsEnabled;
340
341 if (m_nonEmptyNumericColumnsOnly && !(column->isNumeric() && column->hasValues()))
342 result &= ~Qt::ItemIsEnabled;
343 }
344
345 return result;
346}

Callers

nothing calls this directly

Calls 10

indexMethod · 0.95
containsFilterStringMethod · 0.95
inheritsMethod · 0.80
isPlottableMethod · 0.80
QModelIndexClass · 0.50
isValidMethod · 0.45
isEmptyMethod · 0.45
columnMethod · 0.45
isNumericMethod · 0.45
hasValuesMethod · 0.45

Tested by

no test coverage detected