diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 52ad3bd5..38bdeaf7 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -92,6 +92,9 @@ void MainWindow::init()
connect(ui->dataTable->filterHeader(), SIGNAL(filterChanged(int,QString)), this, SLOT(updateFilter(int,QString)));
connect(m_browseTableModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataTableSelectionChanged(QModelIndex)));
+ // Select in table the rows correspoding to the selected points in plot
+ connect(plotDock, SIGNAL(pointsSelected(int,int)), this, SLOT(selectTableLines(int,int)));
+
// Set up DB structure tab
dbStructureModel = new DbStructureModel(db, this);
ui->dbTreeWidget->setModel(dbStructureModel);
@@ -676,6 +679,22 @@ void MainWindow::selectTableLine(int lineToSelect)
QApplication::restoreOverrideCursor();
}
+void MainWindow::selectTableLines(int firstLine, int count)
+{
+ int lastLine = firstLine+count-1;
+ // Are there even that many lines?
+ if(lastLine >= m_browseTableModel->totalRowCount())
+ return;
+
+ selectTableLine(firstLine);
+ QItemSelectionModel* selectionModel = ui->dataTable->selectionModel();
+
+ QModelIndex topLeft = ui->dataTable->model()->index(firstLine, 0);
+ QModelIndex bottomRight = ui->dataTable->model()->index(lastLine, ui->dataTable->model()->columnCount()-1);
+
+ ui->dataTable->selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select | QItemSelectionModel::Rows);
+}
+
void MainWindow::navigatePrevious()
{
int curRow = ui->dataTable->currentIndex().row();
diff --git a/src/MainWindow.h b/src/MainWindow.h
index b01b0317..6862ebe5 100644
--- a/src/MainWindow.h
+++ b/src/MainWindow.h
@@ -219,6 +219,7 @@ private slots:
void addRecord();
void deleteRecord();
void selectTableLine( int lineToSelect );
+ void selectTableLines(int firstLine, int count);
void navigatePrevious();
void navigateNext();
void navigateBegin();
diff --git a/src/PlotDock.cpp b/src/PlotDock.cpp
index 57b298c6..20494310 100644
--- a/src/PlotDock.cpp
+++ b/src/PlotDock.cpp
@@ -23,6 +23,7 @@ PlotDock::PlotDock(QWidget* parent)
// Connect signals
connect(ui->treePlotColumns, &QTreeWidget::itemChanged, this, &PlotDock::on_treePlotColumns_itemChanged);
+ connect(ui->plotWidget, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
}
PlotDock::~PlotDock()
@@ -199,6 +200,9 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett
QCPGraph* graph = ui->plotWidget->addGraph();
graph->setPen(QPen(item->backgroundColor(PlotColumnY)));
+ graph->setSelectable (QCP::stDataRange);
+ ui->plotWidget->setInteractions(QCP::iSelectPlottables);
+ ui->plotWidget->setSelectionRectMode(QCP::srmSelect);
// prepare the data vectors for qcustomplot
// possible improvement might be a QVector subclass that directly
@@ -376,7 +380,7 @@ void PlotDock::on_treePlotColumns_itemDoubleClicked(QTreeWidgetItem* item, int c
QColorDialog colordialog(this);
QColor curbkcolor = item->backgroundColor(column);
QColor precolor = !curbkcolor.isValid() ? (Qt::GlobalColor)(qrand() % 13 + 5) : curbkcolor;
- QColor color = colordialog.getColor(precolor, this, tr("Choose a axis color"));
+ QColor color = colordialog.getColor(precolor, this, tr("Choose an axis color"));
if(color.isValid())
{
item->setCheckState(column, Qt::Checked);
@@ -540,3 +544,21 @@ void PlotDock::fetchAllData()
updatePlot(m_currentPlotModel, m_currentTableSettings);
}
}
+
+void PlotDock::selectionChanged()
+{
+
+ for (QCPGraph* graph : ui->plotWidget->selectedGraphs()) {
+
+ for (QCPDataRange dataRange : graph->selection().dataRanges()) {
+
+ int index = dataRange.begin();
+ if (dataRange.length() != 0) {
+ emit pointsSelected(index, dataRange.length());
+ break;
+ }
+
+ }
+ }
+
+}
diff --git a/src/PlotDock.h b/src/PlotDock.h
index b0f1d81b..88b4df28 100644
--- a/src/PlotDock.h
+++ b/src/PlotDock.h
@@ -48,6 +48,9 @@ public slots:
void updatePlot(SqliteTableModel* model, BrowseDataTableSettings* settings = nullptr, bool update = true, bool keepOrResetSelection = true);
void fetchAllData();
+signals:
+ void pointsSelected(int firstIndex, int count);
+
private:
enum PlotColumns
{
@@ -76,6 +79,7 @@ private slots:
void on_butSavePlot_clicked();
void on_comboLineType_currentIndexChanged(int index);
void on_comboPointShape_currentIndexChanged(int index);
+ void selectionChanged();
};
#endif
diff --git a/src/PlotDock.ui b/src/PlotDock.ui
index f4b76fe9..389ec6a3 100644
--- a/src/PlotDock.ui
+++ b/src/PlotDock.ui
@@ -6,7 +6,7 @@
0
0
- 478
+ 515
553
@@ -49,7 +49,16 @@
- _
+ _
+
+
+
+
+ 0
+ 0
+ 0
+
+