diff --git a/plotter_gui/filterablelistwidget.cpp b/plotter_gui/filterablelistwidget.cpp index 0a932608f..9362eaf1d 100644 --- a/plotter_gui/filterablelistwidget.cpp +++ b/plotter_gui/filterablelistwidget.cpp @@ -8,6 +8,7 @@ #include #include #include +#include FilterableListWidget::FilterableListWidget(QWidget *parent) : QWidget(parent), @@ -16,9 +17,9 @@ FilterableListWidget::FilterableListWidget(QWidget *parent) : ui->setupUi(this); ui->tableWidget->viewport()->installEventFilter( this ); - table()->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); - table()->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); - table()->horizontalHeader()->resizeSection(1, 120); + table()->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + table()->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); + table()->horizontalHeader()->resizeSection(1, 120); for( int i=0; i< ui->gridLayoutSettings->count(); i++) { @@ -32,6 +33,10 @@ FilterableListWidget::FilterableListWidget(QWidget *parent) : } } } + + this->setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(on_ShowContextMenu(const QPoint &))); } FilterableListWidget::~FilterableListWidget() @@ -96,7 +101,7 @@ void FilterableListWidget::updateFilter() bool FilterableListWidget::eventFilter(QObject *object, QEvent *event) { - // qDebug() <type(); + // qDebug() <type(); if(event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouse_event = static_cast(event); @@ -117,7 +122,7 @@ bool FilterableListWidget::eventFilter(QObject *object, QEvent *event) double distance_from_click = (mouse_event->pos() - _drag_start_pos).manhattanLength(); if ((mouse_event->buttons() == Qt::LeftButton) && - distance_from_click >= QApplication::startDragDistance()) + distance_from_click >= QApplication::startDragDistance()) { QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; @@ -237,3 +242,39 @@ void FilterableListWidget::on_checkBoxHideSecondColumn_toggled(bool checked) emit hiddenItemsChanged(); } } + +void FilterableListWidget::on_ShowContextMenu(const QPoint &pos) +{ + QIcon iconDelete; + iconDelete.addFile(QStringLiteral(":/icons/resources/clean_pane_small@2x.png"), + QSize(26, 26), QIcon::Normal, QIcon::Off); + + QAction* action_removeCurves = new QAction(tr("&Delete selected curves from memory"), this); + action_removeCurves->setIcon(iconDelete); + + connect(action_removeCurves, SIGNAL(triggered()), + this, SLOT(removeSelectedCurves()) ); + + QMenu menu(this); + menu.addAction(action_removeCurves); + menu.exec(mapToGlobal(pos)); +} + +void FilterableListWidget::removeSelectedCurves() +{ + QMessageBox::StandardButton reply; + reply = QMessageBox::question(0, tr("Warning"), + tr("Do you really want to remove these data?\n"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No ); + + if( reply == QMessageBox::Yes ) { + + while( table()->selectedItems().size() > 0 ) + { + QTableWidgetItem* item = table()->selectedItems().first(); + emit deleteCurve( item->text() ); + table()->removeRow( item->row() ); + } + } +} diff --git a/plotter_gui/filterablelistwidget.h b/plotter_gui/filterablelistwidget.h index 00097d2eb..bd24bc993 100644 --- a/plotter_gui/filterablelistwidget.h +++ b/plotter_gui/filterablelistwidget.h @@ -51,6 +51,10 @@ private slots: void on_checkBoxHideSecondColumn_toggled(bool checked); + void on_ShowContextMenu(const QPoint &pos); + + void removeSelectedCurves(); + private: Ui::FilterableListWidget *ui; @@ -63,6 +67,8 @@ private slots: void hiddenItemsChanged(); + void deleteCurve(QString curve_name); + }; #endif // CURVE_SELECTOR_H diff --git a/plotter_gui/mainwindow.cpp b/plotter_gui/mainwindow.cpp index 71b31ded2..bba99d858 100644 --- a/plotter_gui/mainwindow.cpp +++ b/plotter_gui/mainwindow.cpp @@ -54,6 +54,9 @@ MainWindow::MainWindow(const QCommandLineParser &commandline_parser, QWidget *pa connect( _curvelist_widget, SIGNAL(hiddenItemsChanged()), this, SLOT(updateLeftTableValues()) ); + connect(_curvelist_widget, SIGNAL(deleteCurve(QString)), + this, SLOT(deleteLoadedData(QString)) ); + connect(this, SIGNAL(trackerTimeUpdated(QPointF)), this, SLOT(updateLeftTableValues()) ); _main_tabbed_widget = new TabbedPlotWidget( this, &_mapped_plot_data, this); @@ -696,7 +699,7 @@ void MainWindow::onDeleteLoadedData() { QMessageBox::StandardButton reply; reply = QMessageBox::question(0, tr("Warning"), - tr("Do you really want to remove any loaded data?\n"), + tr("Do you really want to remove the loaded data?\n"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ); if( reply == QMessageBox::No ) { diff --git a/plotter_gui/mainwindow.h b/plotter_gui/mainwindow.h index a8f54536c..ff139de28 100644 --- a/plotter_gui/mainwindow.h +++ b/plotter_gui/mainwindow.h @@ -101,6 +101,8 @@ private slots: void updateLeftTableValues(); + void deleteLoadedData(const QString &curve_name); + private: Ui::MainWindow *ui; @@ -168,7 +170,6 @@ private slots: void dragEnterEvent(QDragEnterEvent *event) ; - void deleteLoadedData(const QString &curve_name); QTimer *_replot_timer; signals: