mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
plot: Don't generate colours randomly
This adds a basic table of 12 colours which DB4S chooses from when new plot graphs are added. This also introduces a pointer to this table of colours which if moved forward each time a graph is added. This it's less likely that two graphs have the same colour in one plot. A better but more complex approach would be to find an algorithm to generate new colours dynamicalls. See issue #816 for details.
This commit is contained in:
@@ -2045,16 +2045,66 @@ void MainWindow::on_treePlotColumns_itemChanged(QTreeWidgetItem *changeitem, int
|
||||
} else if(column == PlotColumnY) {
|
||||
if(changeitem->checkState(column) == Qt::Checked)
|
||||
{
|
||||
// get a default color
|
||||
QColor curbkcolor = changeitem->backgroundColor(column);
|
||||
QColor color = !curbkcolor.isValid() ? (Qt::GlobalColor)(qrand() % 13 + 5) : curbkcolor;
|
||||
// Getget a default colour
|
||||
QColor colour = changeitem->backgroundColor(column);
|
||||
if(!colour.isValid())
|
||||
{
|
||||
static int last_colour_index = 0;
|
||||
switch(last_colour_index++)
|
||||
{
|
||||
case 0:
|
||||
colour = QColor(0, 69, 134);
|
||||
break;
|
||||
case 1:
|
||||
colour = QColor(255, 66, 14);
|
||||
break;
|
||||
case 2:
|
||||
colour = QColor(255, 211, 32);
|
||||
break;
|
||||
case 3:
|
||||
colour = QColor(87, 157, 28);
|
||||
break;
|
||||
case 4:
|
||||
colour = QColor(126, 0, 33);
|
||||
break;
|
||||
case 5:
|
||||
colour = QColor(131, 202, 255);
|
||||
break;
|
||||
case 6:
|
||||
colour = QColor(49, 64, 4);
|
||||
break;
|
||||
case 7:
|
||||
colour = QColor(174, 207, 0);
|
||||
break;
|
||||
case 8:
|
||||
colour = QColor(75, 31, 111);
|
||||
break;
|
||||
case 9:
|
||||
colour = QColor(255, 149, 14);
|
||||
break;
|
||||
case 10:
|
||||
colour = QColor(197, 00, 11);
|
||||
break;
|
||||
case 11:
|
||||
colour = QColor(0, 132, 209);
|
||||
|
||||
// Since this is the last colour in our table, reset the counter back
|
||||
// to the first colour
|
||||
last_colour_index = 0;
|
||||
break;
|
||||
default:
|
||||
// NOTE: This shouldn't happen!
|
||||
colour = QColor(0, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set colour
|
||||
changeitem->setBackgroundColor(column, color);
|
||||
changeitem->setBackgroundColor(column, colour);
|
||||
|
||||
// Save settings for this table
|
||||
PlotSettings& plot_settings = browseTableSettings[current_table].plotYAxes[changeitem->text(PlotColumnField)];
|
||||
plot_settings.colour = color;
|
||||
plot_settings.colour = colour;
|
||||
plot_settings.lineStyle = ui->comboLineType->currentIndex();
|
||||
plot_settings.pointShape = (ui->comboPointShape->currentIndex() > 0 ? (ui->comboPointShape->currentIndex()+1) : ui->comboPointShape->currentIndex());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user