Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4706dd7

Browse files
committed
plot: Correctly disable signals when needed
In the plot code use the blockSignals() method instead of connecting and disconnecting signals and slots every time. The disconnects didn't really work using the new C++11 connection code, so this commit restored the functionality as it was intended. This means that *a ton* of calls to updatePlot() are eliminated which improves the performance. It also avoid messing up the graph selection table in the Plot Dock in certain cases. See issue #950.
1 parent e1fbc98 commit 4706dd7

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/PlotDock.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ PlotDock::PlotDock(QWidget* parent)
2020
ui->splitterForPlot->restoreState(Settings::getValue("PlotDock", "splitterSize").toByteArray());
2121
ui->comboLineType->setCurrentIndex(Settings::getValue("PlotDock", "lineType").toInt());
2222
ui->comboPointShape->setCurrentIndex(Settings::getValue("PlotDock", "pointShape").toInt());
23+
24+
// Connect signals
25+
connect(ui->treePlotColumns, &QTreeWidget::itemChanged, this, &PlotDock::on_treePlotColumns_itemChanged);
2326
}
2427

2528
PlotDock::~PlotDock()
@@ -41,9 +44,8 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett
4144
// Store pointer to the current browse table settings in the main window
4245
m_currentTableSettings = settings;
4346

44-
// disconnect treeplotcolumns item changed updates
45-
disconnect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
46-
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
47+
// disable tree plot columns item changed updates
48+
ui->treePlotColumns->blockSignals(true);
4749

4850
m_currentPlotModel = model;
4951

@@ -141,7 +143,7 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett
141143

142144
ui->plotWidget->yAxis->setLabel("Y");
143145
ui->plotWidget->xAxis->setLabel("X");
144-
connect(ui->treePlotColumns, &QTreeWidget::itemChanged, this, &PlotDock::on_treePlotColumns_itemChanged);
146+
ui->treePlotColumns->blockSignals(false);
145147
}
146148

147149
// search for the x axis select
@@ -255,8 +257,7 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett
255257
void PlotDock::on_treePlotColumns_itemChanged(QTreeWidgetItem* changeitem, int column)
256258
{
257259
// disable change updates, or we get unwanted redrawing and weird behavior
258-
disconnect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
259-
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
260+
ui->treePlotColumns->blockSignals(true);
260261

261262
// make sure only 1 X axis is selected
262263
if(column == PlotColumnX)
@@ -349,17 +350,15 @@ void PlotDock::on_treePlotColumns_itemChanged(QTreeWidgetItem* changeitem, int c
349350
}
350351
}
351352

352-
connect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
353-
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
353+
ui->treePlotColumns->blockSignals(false);
354354

355355
updatePlot(m_currentPlotModel, m_currentTableSettings, false);
356356
}
357357

358358
void PlotDock::on_treePlotColumns_itemDoubleClicked(QTreeWidgetItem* item, int column)
359359
{
360360
// disable change updates, or we get unwanted redrawing and weird behavior
361-
disconnect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
362-
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
361+
ui->treePlotColumns->blockSignals(true);
363362

364363
if(column == PlotColumnY)
365364
{
@@ -390,8 +389,7 @@ void PlotDock::on_treePlotColumns_itemDoubleClicked(QTreeWidgetItem* item, int c
390389
}
391390
}
392391

393-
connect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
394-
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
392+
ui->treePlotColumns->blockSignals(false);
395393

396394
updatePlot(m_currentPlotModel, m_currentTableSettings, false);
397395
}

0 commit comments

Comments
 (0)