plot: only select a color on double click

otherwise we will get some random globalcolor from qt
This commit is contained in:
Peinthor Rene
2014-05-16 17:49:42 +02:00
parent a4f8ee7721
commit 39ab238ddd
2 changed files with 34 additions and 4 deletions

View File

@@ -1564,14 +1564,13 @@ void MainWindow::on_treePlotColumns_itemChanged(QTreeWidgetItem *changeitem, int
}
}
}
else
else if(column == PlotColumnY)
{
if(changeitem->checkState(column) == Qt::Checked)
{
QColorDialog colordialog(this);
// get a default color
QColor curbkcolor = changeitem->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 = !curbkcolor.isValid() ? (Qt::GlobalColor)(qrand() % 13 + 5) : curbkcolor;
if(color.isValid())
{
changeitem->setBackgroundColor(column, color);
@@ -1589,6 +1588,36 @@ void MainWindow::on_treePlotColumns_itemChanged(QTreeWidgetItem *changeitem, int
updatePlot(m_currentPlotModel, false);
}
void MainWindow::on_treePlotColumns_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
// disable change updates, or we get unwanted redrawing and weird behavior
disconnect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
if(column == PlotColumnY)
{
// On double click open the colordialog
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"));
if(color.isValid())
{
item->setCheckState(column, Qt::Checked);
item->setBackgroundColor(column, color);
}
else
{
item->setCheckState(column, Qt::Unchecked);
}
}
connect(ui->treePlotColumns, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
this,SLOT(on_treePlotColumns_itemChanged(QTreeWidgetItem*,int)));
updatePlot(m_currentPlotModel, false);
}
void MainWindow::on_butSavePlot_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this,

View File

@@ -168,6 +168,7 @@ private slots:
virtual void httpresponse(QNetworkReply* reply);
virtual void updatePlot(SqliteTableModel* model, bool update = true);
void on_treePlotColumns_itemChanged(QTreeWidgetItem *item, int column);
void on_treePlotColumns_itemDoubleClicked(QTreeWidgetItem *item, int column);
void on_butSavePlot_clicked();
};