Skip to content

Commit

Permalink
Range of plot points can be selected in graph and in table
Browse files Browse the repository at this point in the history
The user is now able of selecting a range of contiguous points in any of
the graphs of the plot, through rectangle selection or click in single
point. This selection triggers automatically the selection of the
corresponding lines in the browsed table. In this way the user can analyse
the plot in detail.

Two other minor improvements: spelling error fixed and the dummy column in
the plot selection table has now transparent foreground (intends to avoid
wondering of the user about what functionality provides this column).
  • Loading branch information
mgrojo committed Nov 11, 2017
1 parent 0c30659 commit e8e5671
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/MainWindow.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/MainWindow.h
Expand Up @@ -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();
Expand Down
24 changes: 23 additions & 1 deletion src/PlotDock.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

}
}

}
4 changes: 4 additions & 0 deletions src/PlotDock.h
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
13 changes: 11 additions & 2 deletions src/PlotDock.ui
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>478</width>
<width>515</width>

This comment has been minimized.

Copy link
@mgrojo

mgrojo Nov 11, 2017

Author Member

This is added automatically by qtcreator, I don't know why. Should I revert these kind of changes before commit?

This comment has been minimized.

Copy link
@MKleusberg

MKleusberg Nov 13, 2017

Member

Yeah, Qt Creator likes to add these. I think it might be because of the different platforms we're developing on, for example the height of a QLineEdit on my system might be different than the height of a QLineEdit on another platform. I try to remove these before making commits but sometimes forget 😉

<height>553</height>
</rect>
</property>
Expand Down Expand Up @@ -49,7 +49,16 @@
</column>
<column>
<property name="text">
<string>_</string>
<string notr="true">_</string>

This comment has been minimized.

Copy link
@mgrojo

mgrojo Nov 11, 2017

Author Member

By the way, what is the use of this dummy column? Is it only a padding? I'd rather remove it to give all this space to the "Columns" column. We could then draw horizontal borders as a hint since when the column name is short, it might be too far from the X and Y columns. The advantage would be space enough for long column names.

This comment has been minimized.

Copy link
@MKleusberg

MKleusberg Nov 13, 2017

Member

Yep, this is just for padding. Stumbled upon it a while ago, too 😉 Feel free to remove it if you want and just set alternateRowColors to true for drawing some visual guideline as you mentioned.

</property>
<property name="foreground">
<brush brushstyle="NoBrush">
<color alpha="0">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</property>
</column>
</widget>
Expand Down

0 comments on commit e8e5671

Please sign in to comment.