diff --git a/src/PlotDock.cpp b/src/PlotDock.cpp index 5cd3c9ec..7e37c1cc 100644 --- a/src/PlotDock.cpp +++ b/src/PlotDock.cpp @@ -72,8 +72,8 @@ PlotDock::~PlotDock() void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* settings, bool update, bool keepOrResetSelection) { // Each column has an id that we use internally, starting from 0. However, at the beginning of the columns list we want to add - // the virtual 'Row #' column which needs a separate unique id for internal use. This id is defined here as -1 in a 16bit integer. - const unsigned int RowNumId = 0xFFFF; + // the virtual 'Row #' column which needs a separate unique id for internal use. This id is defined here as -1. + const int RowNumId = -1; // add columns to x/y selection tree widget if(update) @@ -140,13 +140,11 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett columnitem->setText(PlotColumnType, "Label"); break; } - // maybe i make this more complicated than i should - // but store the model column index in the first 16 bit and the type - // in the other 16 bits - uint itemdata = 0; - itemdata = i << 16; - itemdata |= columntype; - columnitem->setData(PlotColumnField, Qt::UserRole, itemdata); + + // Store the model column index in the PlotColumnField and the type + // in the PlotColumnType, both using the User Role. + columnitem->setData(PlotColumnField, Qt::UserRole, i); + columnitem->setData(PlotColumnType, Qt::UserRole, static_cast(columntype)); columnitem->setText(PlotColumnField, model->headerData(i, Qt::Horizontal).toString()); // restore previous check state @@ -173,10 +171,10 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett { QTreeWidgetItem* columnitem = new QTreeWidgetItem(ui->treePlotColumns); - // Just set all bits in the user role information field here to somehow indicate what column this is - uint itemdata = -1; - columnitem->setData(PlotColumnField, Qt::UserRole, itemdata); + // Just set RowNumId in the user role information field here to somehow indicate what column this is + columnitem->setData(PlotColumnField, Qt::UserRole, RowNumId); columnitem->setText(PlotColumnField, tr("Row #")); + columnitem->setData(PlotColumnType, Qt::UserRole, static_cast(QVariant::Double)); columnitem->setText(PlotColumnType, "Numeric"); // restore previous check state @@ -223,11 +221,9 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett if(xitem) { // regain the model column index and the datatype - // leading 16 bit are column index, the other 16 bit are the datatype - // right now datatype is only important for X axis (date, non date) - uint xitemdata = xitem->data(PlotColumnField, Qt::UserRole).toUInt(); - int x = xitemdata >> 16; - int xtype = xitemdata & (uint)0xFF; + // right now datatype is only important for X axis (Y is always numeric) + int x = xitem->data(PlotColumnField, Qt::UserRole).toInt(); + int xtype = xitem->data(PlotColumnType, Qt::UserRole).toInt(); // check if we have a x axis with datetime data switch (xtype) { @@ -267,10 +263,8 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett QTreeWidgetItem* item = ui->treePlotColumns->topLevelItem(i); if(item->checkState((PlotColumnY)) == Qt::Checked) { - // regain the model column index and the datatype - // leading 16 bit are column index - uint itemdata = item->data(0, Qt::UserRole).toUInt(); - int column = itemdata >> 16; + // regain the model column index + int column = item->data(PlotColumnField, Qt::UserRole).toInt(); bool isSorted = true; @@ -348,7 +342,10 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett QCPBars* bars = new QCPBars(ui->plotWidget->xAxis, ui->plotWidget->yAxis); plottable = bars; bars->setData(xdata, ydata); - bars->setBrush(item->backgroundColor(PlotColumnY)); + QColor brush = item->backgroundColor(PlotColumnY); + if (ui->plotWidget->plottableCount() > 1) + brush.setAlpha(124); + bars->setBrush(brush); QSharedPointer ticker(new QCPAxisTickerText); ticker->addTicks(xdata, labels); ui->plotWidget->xAxis->setTicker(ticker); @@ -376,7 +373,7 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett } plottable->setPen(QPen(item->backgroundColor(PlotColumnY))); - plottable->setSelectable (QCP::stDataRange); + plottable->setSelectable(QCP::stDataRange); // gather Y label column names if(column == RowNumId) @@ -529,8 +526,7 @@ void PlotDock::on_treePlotColumns_itemDoubleClicked(QTreeWidgetItem* item, int c // disable change updates, or we get unwanted redrawing and weird behavior ui->treePlotColumns->blockSignals(true); - uint itemdata = item->data(PlotColumnField, Qt::UserRole).toUInt(); - int type = itemdata & (uint)0xFF; + int type = item->data(PlotColumnType, Qt::UserRole).toInt(); if(column == PlotColumnY && type == QVariant::Double) { diff --git a/src/PlotDock.ui b/src/PlotDock.ui index b9a7e553..d37703af 100644 --- a/src/PlotDock.ui +++ b/src/PlotDock.ui @@ -26,6 +26,9 @@ 2 + + <html><head/><body><p>This pane shows the list of columns of the currently browsed table or the just executed query. You can select the columns that you want to be used as X or Y axis for the plot pane below. The table shows detected axis type that will affect the resulting plot. For the Y axis you can only select numeric columns, but for the X axis you will be able to select:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Date/Time</span>: strings with format &quot;yyyy-MM-dd hh:mm:ss&quot; or &quot;yyyy-MM-ddThh:mm:ss&quot;</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Date</span>: strings with format &quot;yyyy-MM-dd&quot;</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Time</span>: strings with format &quot;hh:mm:ss&quot;</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Label</span>: other string formats. Selecting this column as X axis will produce a Bars plot with the column values as labels for the bars</li><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Numeric</span>: integer or real values</li></ul><p>Double-clicking the Y cells you can change the used color for that graph.</p></body></html> + true