From 7d0410209203cb59c248b268f1e75df4a0362162 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sat, 5 Dec 2020 17:21:33 +0100 Subject: [PATCH] Allow selecting fixed format for big integer numbers The default format changes to scientific format when the width of the number would be longer. The user will be able to select fixed format for integer numbers in the contextual menu. Note that precision is set to 0, because in the fixed format trailing zeros are not omitted. See issue #2498 --- src/PlotDock.cpp | 28 +++++++++++++++++++++++++++- src/PlotDock.h | 2 ++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/PlotDock.cpp b/src/PlotDock.cpp index f9d71944..27b6eaf6 100644 --- a/src/PlotDock.cpp +++ b/src/PlotDock.cpp @@ -34,7 +34,8 @@ PlotDock::PlotDock(QWidget* parent) m_currentPlotModel(nullptr), m_currentTableSettings(nullptr), m_showLegend(false), - m_stackedBars(false) + m_stackedBars(false), + m_fixedFormat(false) { ui->setupUi(this); @@ -97,6 +98,17 @@ PlotDock::PlotDock(QWidget* parent) connect(stackedBarsAction, &QAction::toggled, this, &PlotDock::toggleStackedBars); + QAction* fixedFormatsAction = new QAction(tr("Fixed number format"), m_contextMenu); + fixedFormatsAction->setCheckable(true); + m_contextMenu->addAction(fixedFormatsAction); + + connect(fixedFormatsAction, &QAction::toggled, this, + [=](bool fixed) { + m_fixedFormat = fixed; + adjustAxisFormat(); + ui->plotWidget->replot(); + }); + connect(ui->plotWidget, &QTableView::customContextMenuRequested, [=](const QPoint& pos) { // Show menu @@ -540,6 +552,7 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett } adjustBars(); + adjustAxisFormat(); ui->plotWidget->replot(); // Warn user if not all data has been fetched and hint about the button for loading all the data @@ -973,6 +986,19 @@ void PlotDock::adjustBars() } } +void PlotDock::adjustAxisFormat() +{ + const QString format = m_fixedFormat? "f" : "gb"; + ui->plotWidget->xAxis->setNumberFormat(format); + ui->plotWidget->yAxis->setNumberFormat(format); + ui->plotWidget->yAxis2->setNumberFormat(format); + + const int precision = m_fixedFormat? 0 : 6; + ui->plotWidget->xAxis->setNumberPrecision(precision); + ui->plotWidget->yAxis->setNumberPrecision(precision); + ui->plotWidget->yAxis2->setNumberPrecision(precision); +} + void PlotDock::toggleStackedBars(bool stacked) { m_stackedBars = stacked; diff --git a/src/PlotDock.h b/src/PlotDock.h index 2c3276b0..85cc88ef 100644 --- a/src/PlotDock.h +++ b/src/PlotDock.h @@ -96,6 +96,7 @@ private: QMenu* m_contextMenu; bool m_showLegend; bool m_stackedBars; + bool m_fixedFormat; Palette m_graphPalette; std::vector yAxes; std::vector PlotColumnY; @@ -108,6 +109,7 @@ private: */ QVariant::Type guessDataType(SqliteTableModel* model, int column) const; void adjustBars(); + void adjustAxisFormat(); private slots: void on_treePlotColumns_itemChanged(QTreeWidgetItem* item, int column);