Skip to content

Commit fdbda56

Browse files
committed
plot: only allow X column to be selected once
1 parent d084646 commit fdbda56

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/MainWindow.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,27 +1389,28 @@ void MainWindow::updatePlot(SqliteTableModel *model, bool update)
13891389
uint itemdata = 0;
13901390
itemdata = i << 16;
13911391
itemdata |= columntype;
1392-
columnitem->setData(0, Qt::UserRole, itemdata);
1392+
columnitem->setData(PlotColumnField, Qt::UserRole, itemdata);
13931393

1394-
columnitem->setText(0, model->headerData(i, Qt::Horizontal).toString());
1395-
columnitem->setCheckState(1, Qt::Unchecked);
1396-
columnitem->setCheckState(2, Qt::Unchecked);
1394+
columnitem->setText(PlotColumnField, model->headerData(i, Qt::Horizontal).toString());
1395+
columnitem->setCheckState(PlotColumnY, Qt::Unchecked);
1396+
columnitem->setCheckState(PlotColumnX, Qt::Unchecked);
13971397
ui->treePlotColumns->addTopLevelItem(columnitem);
13981398
}
13991399
}
14001400
}
14011401

14021402
ui->plotWidget->yAxis->setLabel("Y");
14031403
ui->plotWidget->xAxis->setLabel("X");
1404-
connect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
1404+
connect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
1405+
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
14051406
}
14061407

14071408
// search for the x axis select
14081409
QTreeWidgetItem* xitem = 0;
14091410
for(int i = 0; i < ui->treePlotColumns->topLevelItemCount(); ++i)
14101411
{
14111412
xitem = ui->treePlotColumns->topLevelItem(i);
1412-
if(xitem->checkState(2) == Qt::Checked)
1413+
if(xitem->checkState(PlotColumnX) == Qt::Checked)
14131414
break;
14141415

14151416
xitem = 0;
@@ -1422,7 +1423,7 @@ void MainWindow::updatePlot(SqliteTableModel *model, bool update)
14221423
ui->plotWidget->clearGraphs();
14231424
if(xitem)
14241425
{
1425-
uint xitemdata = xitem->data(0, Qt::UserRole).toUInt();
1426+
uint xitemdata = xitem->data(PlotColumnField, Qt::UserRole).toUInt();
14261427
int x = xitemdata >> 16;
14271428
int xtype = xitemdata & (uint)0xFF;
14281429

@@ -1442,7 +1443,7 @@ void MainWindow::updatePlot(SqliteTableModel *model, bool update)
14421443
for(int i = 0; i < ui->treePlotColumns->topLevelItemCount(); ++i)
14431444
{
14441445
QTreeWidgetItem* item = ui->treePlotColumns->topLevelItem(i);
1445-
if(item->checkState((1)) == Qt::Checked && ui->plotWidget->graphCount() < colors.size())
1446+
if(item->checkState((PlotColumnY)) == Qt::Checked && ui->plotWidget->graphCount() < colors.size())
14461447
{
14471448
uint itemdata = item->data(0, Qt::UserRole).toUInt();
14481449
int column = itemdata >> 16;
@@ -1484,7 +1485,26 @@ void MainWindow::updatePlot(SqliteTableModel *model, bool update)
14841485
ui->plotWidget->replot();
14851486
}
14861487

1487-
void MainWindow::on_treePlotColumns_itemChanged(QTreeWidgetItem *item, int column)
1488+
void MainWindow::on_treePlotColumns_itemChanged(QTreeWidgetItem *changeitem, int column)
14881489
{
1490+
// make sure only 1 X axis is selected
1491+
if(column == PlotColumnX)
1492+
{
1493+
// disable change updates, or we get unwanted redrawing and weird behavior
1494+
disconnect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
1495+
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
1496+
1497+
for(int i = 0; i < ui->treePlotColumns->topLevelItemCount(); ++i)
1498+
{
1499+
QTreeWidgetItem* item = ui->treePlotColumns->topLevelItem(i);
1500+
if(item->checkState(column) == Qt::Checked && item != changeitem)
1501+
{
1502+
item->setCheckState(column, Qt::Unchecked);
1503+
}
1504+
}
1505+
1506+
connect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
1507+
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
1508+
}
14891509
updatePlot(m_currentPlotModel, false);
14901510
}

src/MainWindow.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ class MainWindow : public QMainWindow
5656
int wal_autocheckpoint;
5757
} pragmaValues;
5858

59+
enum PlotColumns
60+
{
61+
PlotColumnField = 0,
62+
PlotColumnY = 1,
63+
PlotColumnX = 2
64+
};
65+
5966
Ui::MainWindow* ui;
6067

6168
SqliteTableModel* m_browseTableModel;

0 commit comments

Comments
 (0)