Skip to content

Commit

Permalink
Feature: add float precision setting (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetkkn07 authored Jan 24, 2025
1 parent 377bdc7 commit 94dce8e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
4 changes: 3 additions & 1 deletion plotjuggler_app/curvelist_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ void CurveListPanel::refreshValues()
auto default_foreground = _custom_view->palette().foreground();

auto FormattedNumber = [](double value) {
QString num_text = QString::number(value, 'f', 3);
QSettings settings;
int prec = settings.value("Preferences::precision", 3).toInt();
QString num_text = QString::number(value, 'f', prec);
if (num_text.contains('.'))
{
int idx = num_text.length() - 1;
Expand Down
6 changes: 5 additions & 1 deletion plotjuggler_app/customtracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "qwt_text.h"
#include <qevent.h>
#include <QFontDatabase>
#include <QSettings>

struct compareX
{
Expand Down Expand Up @@ -155,13 +156,16 @@ void CurveTracker::setPosition(const QPointF& position)

QString line;

QSettings settings;
int prec = settings.value("Preferences::precision", 3).toInt();

if (_param == VALUE)
{
line = QString("<font color=%1>%2</font>").arg(color.name()).arg(val);
}
else if (_param == VALUE_NAME)
{
QString value = QString::number(val, 'f', 3);
QString value = QString::number(val, 'f', prec);
int whitespaces = 8 - value.length();
while (whitespaces-- > 0)
value.prepend("&nbsp;");
Expand Down
5 changes: 5 additions & 0 deletions plotjuggler_app/preferences_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ PreferencesDialog::PreferencesDialog(QWidget* parent)
ui->comboBoxTheme->setCurrentIndex(0);
}

int precision = settings.value("Preferences::precision", 3).toInt();
ui->comboBoxPrecision->setCurrentIndex(precision);

bool use_plot_color_index =
settings.value("Preferences::use_plot_color_index", false).toBool();
bool remember_color = settings.value("Preferences::remember_color", true).toBool();
Expand Down Expand Up @@ -95,6 +98,8 @@ void PreferencesDialog::on_buttonBox_accepted()
ui->checkBoxRememberColor->isChecked());
settings.setValue("Preferences::use_plot_color_index",
ui->radioLocalColorIndex->isChecked());
settings.setValue("Preferences::precision",
ui->comboBoxPrecision->currentIndex());
settings.setValue("Preferences::use_separator", ui->checkBoxSeparator->isChecked());
settings.setValue("Preferences::use_opengl", ui->checkBoxOpenGL->isChecked());
settings.setValue("Preferences::autozoom_visibility",
Expand Down
63 changes: 63 additions & 0 deletions plotjuggler_app/preferences_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,69 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Float Precision:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboBoxPrecision">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>0</string>
</property>
</item>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 94dce8e

Please sign in to comment.