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);