Skip to content

Commit

Permalink
adding the ability to delete curves
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Mar 14, 2017
1 parent 2669c05 commit 408423a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
51 changes: 46 additions & 5 deletions plotter_gui/filterablelistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QMimeData>
#include <QHeaderView>
#include <QFontDatabase>
#include <QMessageBox>

FilterableListWidget::FilterableListWidget(QWidget *parent) :
QWidget(parent),
Expand All @@ -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++)
{
Expand All @@ -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()
Expand Down Expand Up @@ -96,7 +101,7 @@ void FilterableListWidget::updateFilter()

bool FilterableListWidget::eventFilter(QObject *object, QEvent *event)
{
// qDebug() <<event->type();
// qDebug() <<event->type();
if(event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *mouse_event = static_cast<QMouseEvent*>(event);
Expand All @@ -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;
Expand Down Expand Up @@ -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/[email protected]"),
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() );
}
}
}
6 changes: 6 additions & 0 deletions plotter_gui/filterablelistwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ private slots:

void on_checkBoxHideSecondColumn_toggled(bool checked);

void on_ShowContextMenu(const QPoint &pos);

void removeSelectedCurves();

private:

Ui::FilterableListWidget *ui;
Expand All @@ -63,6 +67,8 @@ private slots:

void hiddenItemsChanged();

void deleteCurve(QString curve_name);

};

#endif // CURVE_SELECTOR_H
5 changes: 4 additions & 1 deletion plotter_gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ) {
Expand Down
3 changes: 2 additions & 1 deletion plotter_gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ private slots:

void updateLeftTableValues();

void deleteLoadedData(const QString &curve_name);

private:
Ui::MainWindow *ui;

Expand Down Expand Up @@ -168,7 +170,6 @@ private slots:

void dragEnterEvent(QDragEnterEvent *event) ;

void deleteLoadedData(const QString &curve_name);

QTimer *_replot_timer;
signals:
Expand Down

0 comments on commit 408423a

Please sign in to comment.