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

Method eventFilter

src/frontend/ProjectExplorer.cpp:342–475  ·  view source on GitHub ↗

! handles the contextmenu-event of the horizontal header in the tree view. Provides a menu for selective showing and hiding of columns. */

Source from the content-addressed store, hash-verified

340 Provides a menu for selective showing and hiding of columns.
341*/
342bool ProjectExplorer::eventFilter(QObject* obj, QEvent* event) {
343 if (obj == m_treeView->header() && event->type() == QEvent::ContextMenu) {
344 // Menu for showing/hiding the columns in the tree view
345 QMenu* columnsMenu = new QMenu(m_treeView->header());
346 columnsMenu->addSection(i18n("Columns"));
347 columnsMenu->addAction(showAllColumnsAction);
348 columnsMenu->addSeparator();
349 for (auto* action : std::as_const(list_showColumnActions))
350 columnsMenu->addAction(action);
351
352 auto* e = static_cast<QContextMenuEvent*>(event);
353 columnsMenu->exec(e->globalPos());
354 delete columnsMenu;
355
356 return true;
357 } else if (obj == m_treeView->viewport()) {
358 if (event->type() == QEvent::MouseButtonPress) {
359 auto* e = static_cast<QMouseEvent*>(event);
360 const auto position = e->globalPosition().toPoint();
361 if (e->button() == Qt::LeftButton) {
362 QModelIndex index = m_treeView->indexAt(e->pos());
363 if (!index.isValid())
364 return false;
365
366 auto* aspect = static_cast<AbstractAspect*>(index.internalPointer());
367 if (aspect->isDraggable()) {
368 m_dragStartPos = position;
369 m_dragStarted = false;
370 }
371 }
372 } else if (event->type() == QEvent::MouseMove) {
373 auto* e = static_cast<QMouseEvent*>(event);
374 const auto position = e->globalPosition().toPoint();
375 if (!m_dragStarted && m_treeView->selectionModel()->selectedIndexes().size() > 0
376 && (position - m_dragStartPos).manhattanLength() >= QApplication::startDragDistance()) {
377 m_dragStarted = true;
378 auto* drag = new QDrag(this);
379 auto* mimeData = new QMimeData;
380
381 // determine the selected objects and serialize the pointers to QMimeData
382 QVector<quintptr> vec;
383 QModelIndexList items = m_treeView->selectionModel()->selectedIndexes();
384 // there are four model indices in each row -> divide by 4 to obtain the number of selected rows (=aspects)
385 const int columnCount = m_treeView->model()->columnCount();
386 for (int i = 0; i < items.size() / columnCount; ++i) {
387 const QModelIndex& index = items.at(i * columnCount);
388 auto* aspect = static_cast<AbstractAspect*>(index.internalPointer());
389 vec << (quintptr)aspect;
390 }
391
392 QByteArray data;
393 QDataStream stream(&data, QIODevice::WriteOnly);
394 stream << (quintptr)m_project; // serialize the project pointer first, will be used as the unique identifier
395 stream << vec;
396
397 mimeData->setData(QStringLiteral("labplot-dnd"), data);
398 drag->setMimeData(mimeData);
399 drag->exec();

Callers

nothing calls this directly

Calls 15

addSeparatorMethod · 0.80
execMethod · 0.80
buttonMethod · 0.80
selectionModelMethod · 0.80
droppedAspectsMethod · 0.80
positionMethod · 0.80
parentAspectMethod · 0.80
modelIndexOfAspectMethod · 0.80
typeMethod · 0.45
isValidMethod · 0.45
isDraggableMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected