Skip to content

Commit

Permalink
Implement moveSeriesUp and moveSeriesDown for User Charts
Browse files Browse the repository at this point in the history
To enable series reordering.
  • Loading branch information
amtriathlon committed Oct 20, 2020
1 parent cde4ec0 commit b7a56a9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/Charts/UserChart.cpp
Expand Up @@ -549,8 +549,8 @@ UserChartSettings::UserChartSettings(Context *context, bool rangemode, GenericCh
upSeriesButton = new QPushButton(tr("Up"));
downSeriesButton = new QPushButton(tr("Down"));
#endif
//connect(upSeriesButton, SIGNAL(clicked()), this, SLOT(moveSeriesUp()));
//connect(downSeriesButton, SIGNAL(clicked()), this, SLOT(moveSeriesDown()));
connect(upSeriesButton, SIGNAL(clicked()), this, SLOT(moveSeriesUp()));
connect(downSeriesButton, SIGNAL(clicked()), this, SLOT(moveSeriesDown()));


QHBoxLayout *seriesButtons = new QHBoxLayout;
Expand Down Expand Up @@ -781,6 +781,7 @@ UserChartSettings::editSeries()
chartConfigChanged();
}
}

void
UserChartSettings::deleteSeries()
{
Expand All @@ -793,6 +794,38 @@ UserChartSettings::deleteSeries()
emit chartConfigChanged();
}

void
UserChartSettings::moveSeriesUp()
{
QList<QTableWidgetItem*> items = seriesTable->selectedItems();
if (items.count() < 1) return; // nothing selected

int index = seriesTable->row(items.first());
if (index == 0) return; // already at the top

// move and update the table preserving selection
seriesinfo.move(index, index-1);
refreshSeriesTab();
seriesTable->setCurrentCell(index-1, 0);
emit chartConfigChanged();
}

void
UserChartSettings::moveSeriesDown()
{
QList<QTableWidgetItem*> items = seriesTable->selectedItems();
if (items.count() < 1) return; // nothing selected

int index = seriesTable->row(items.first());
if (index == seriesinfo.count()-1) return; // already at the bottom

// move and update the table preserving selection
seriesinfo.move(index, index+1);
refreshSeriesTab();
seriesTable->setCurrentCell(index+1, 0);
emit chartConfigChanged();
}

void
UserChartSettings::refreshSeriesTab()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Charts/UserChart.h
Expand Up @@ -143,6 +143,8 @@ class UserChartSettings : public QWidget {
void seriesClicked(int,int);
void addSeries();
void deleteSeries();
void moveSeriesUp();
void moveSeriesDown();

// configuration - axes
void refreshAxesTab(); // update gui with current config
Expand Down

0 comments on commit b7a56a9

Please sign in to comment.