Simplify the axis type storing, translucent additional bars and What's This

Now that we have a proper type column in the plot selection widget, the
internal type storing can be simplified.

If the plot has more than one Y selections for one X of label type (bar
charts) the first bar is opaque, but the additional are translucent in
order to be seen, since they will overlap.

What's This information added to explain all the possible selections for
plotting.
This commit is contained in:
mgrojo
2018-01-20 18:28:03 +01:00
parent aa680622c0
commit 175407645b
2 changed files with 24 additions and 25 deletions

View File

@@ -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<int>(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<int>(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<QCPAxisTickerText> 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)
{

View File

@@ -26,6 +26,9 @@
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;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:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Date/Time&lt;/span&gt;: strings with format &amp;quot;yyyy-MM-dd hh:mm:ss&amp;quot; or &amp;quot;yyyy-MM-ddThh:mm:ss&amp;quot;&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Date&lt;/span&gt;: strings with format &amp;quot;yyyy-MM-dd&amp;quot;&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Time&lt;/span&gt;: strings with format &amp;quot;hh:mm:ss&amp;quot;&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Label&lt;/span&gt;: other string formats. Selecting this column as X axis will produce a Bars plot with the column values as labels for the bars&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Numeric&lt;/span&gt;: integer or real values&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Double-clicking the Y cells you can change the used color for that graph.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>