mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-07 12:29:59 -05:00
plot: reselect columns after model change
This commit is contained in:
+26
-3
@@ -1382,10 +1382,25 @@ void MainWindow::updatePlot(SqliteTableModel *model, bool update)
|
|||||||
// add columns to x/y seleciton tree widget
|
// add columns to x/y seleciton tree widget
|
||||||
if(update)
|
if(update)
|
||||||
{
|
{
|
||||||
|
// disconnect treeplotcolumns item changed updates
|
||||||
disconnect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
|
disconnect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
|
||||||
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
|
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
|
||||||
|
|
||||||
m_currentPlotModel = model;
|
m_currentPlotModel = model;
|
||||||
|
|
||||||
|
// save current selected columns, so we can restore them after the update
|
||||||
|
QString sItemX; // selected X column
|
||||||
|
QStringList sItemsY; // selected Y columns
|
||||||
|
for(int i = 0; i < ui->treePlotColumns->topLevelItemCount(); ++i)
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* item = ui->treePlotColumns->topLevelItem(i);
|
||||||
|
if(item->checkState(PlotColumnX) == Qt::Checked)
|
||||||
|
sItemX = item->text(PlotColumnField);
|
||||||
|
|
||||||
|
if(item->checkState(PlotColumnY) == Qt::Checked)
|
||||||
|
sItemsY << item->text(PlotColumnField);
|
||||||
|
}
|
||||||
|
|
||||||
ui->treePlotColumns->clear();
|
ui->treePlotColumns->clear();
|
||||||
|
|
||||||
if(model)
|
if(model)
|
||||||
@@ -1403,10 +1418,18 @@ void MainWindow::updatePlot(SqliteTableModel *model, bool update)
|
|||||||
itemdata = i << 16;
|
itemdata = i << 16;
|
||||||
itemdata |= columntype;
|
itemdata |= columntype;
|
||||||
columnitem->setData(PlotColumnField, Qt::UserRole, itemdata);
|
columnitem->setData(PlotColumnField, Qt::UserRole, itemdata);
|
||||||
|
|
||||||
columnitem->setText(PlotColumnField, model->headerData(i, Qt::Horizontal).toString());
|
columnitem->setText(PlotColumnField, model->headerData(i, Qt::Horizontal).toString());
|
||||||
columnitem->setCheckState(PlotColumnY, Qt::Unchecked);
|
|
||||||
columnitem->setCheckState(PlotColumnX, Qt::Unchecked);
|
// restore previous check state
|
||||||
|
if(sItemsY.contains(columnitem->text(PlotColumnField)))
|
||||||
|
columnitem->setCheckState(PlotColumnY, Qt::Checked);
|
||||||
|
else
|
||||||
|
columnitem->setCheckState(PlotColumnY, Qt::Unchecked);
|
||||||
|
if(sItemX == columnitem->text(PlotColumnField))
|
||||||
|
columnitem->setCheckState(PlotColumnX, Qt::Checked);
|
||||||
|
else
|
||||||
|
columnitem->setCheckState(PlotColumnX, Qt::Unchecked);
|
||||||
|
|
||||||
ui->treePlotColumns->addTopLevelItem(columnitem);
|
ui->treePlotColumns->addTopLevelItem(columnitem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user