Skip to content

Commit

Permalink
Add option for data size unit
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanoHao committed Dec 9, 2024
1 parent 44e9e45 commit e706bc7
Show file tree
Hide file tree
Showing 12 changed files with 1,044 additions and 600 deletions.
3 changes: 3 additions & 0 deletions RedPandaIDE/RedPandaIDE.pro
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ SOURCES += \
settingsdialog/environmentperformancewidget.cpp \
settingsdialog/environmentprogramswidget.cpp \
settingsdialog/environmentshortcutwidget.cpp \
settingsdialog/environmentdatasizewidget.cpp \
settingsdialog/executorproblemsetwidget.cpp \
settingsdialog/formattergeneralwidget.cpp \
settingsdialog/formatterpathwidget.cpp \
Expand Down Expand Up @@ -289,6 +290,7 @@ HEADERS += \
settingsdialog/environmentperformancewidget.h \
settingsdialog/environmentprogramswidget.h \
settingsdialog/environmentshortcutwidget.h \
settingsdialog/environmentdatasizewidget.h \
settingsdialog/executorproblemsetwidget.h \
settingsdialog/formattergeneralwidget.h \
settingsdialog/formatterpathwidget.h \
Expand Down Expand Up @@ -389,6 +391,7 @@ FORMS += \
settingsdialog/environmentperformancewidget.ui \
settingsdialog/environmentprogramswidget.ui \
settingsdialog/environmentshortcutwidget.ui \
settingsdialog/environmentdatasizewidget.ui \
settingsdialog/executorproblemsetwidget.ui \
settingsdialog/formattergeneralwidget.ui \
settingsdialog/formatterpathwidget.ui \
Expand Down
3 changes: 2 additions & 1 deletion RedPandaIDE/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ void Compiler::run()
if (!mOutputFile.isEmpty()) {
log(tr("- Output Filename: %1").arg(mOutputFile));
QLocale locale = QLocale::system();
log(tr("- Output Size: %1").arg(locale.formattedDataSize(QFileInfo(mOutputFile).size())));
QLocale::DataSizeFormats dialect = pSettings->environment().qtDataSizeDialect();
log(tr("- Output Size: %1").arg(locale.formattedDataSize(QFileInfo(mOutputFile).size(), 2, dialect)));
}
log(tr("- Compilation Time: %1 secs").arg(timer.elapsed() / 1000.0));
} catch (CompileError e) {
Expand Down
32 changes: 32 additions & 0 deletions RedPandaIDE/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3809,6 +3809,7 @@ void Settings::Environment::doLoad()

mHideNonSupportFilesInFileView=boolValue("hide_non_support_files_file_view",true);
mOpenFilesInSingleInstance = boolValue("open_files_in_single_instance",false);
mDataSizeDialect = (DataSizeDialect)intValue("data_size_dialect", (int)DataSizeDialect::IecBinary);
}

int Settings::Environment::interfaceFontSize() const
Expand Down Expand Up @@ -3999,6 +4000,35 @@ QMap<QString, QString> Settings::Environment::terminalArgsPatternMagicVariables(
return mTerminalArgsPatternMagicVariables;
}

Settings::Environment::DataSizeDialect Settings::Environment::dataSizeDialect() const
{
return mDataSizeDialect;
}

void Settings::Environment::setDataSizeDialect(Settings::Environment::DataSizeDialect dataSizeDialect)
{
mDataSizeDialect = dataSizeDialect;
}

QLocale::DataSizeFormats Settings::Environment::qtDataSizeDialect(DataSizeDialect dataSizeDialect)
{
switch (dataSizeDialect) {
case DataSizeDialect::SiDecimal:
return QLocale::DataSizeSIFormat;
case DataSizeDialect::IecBinary:
return QLocale::DataSizeIecFormat;
case DataSizeDialect::JedecBinary:
return QLocale::DataSizeTraditionalFormat;
default:
return QLocale::DataSizeIecFormat;
}
}

QLocale::DataSizeFormats Settings::Environment::qtDataSizeDialect() const
{
return qtDataSizeDialect(mDataSizeDialect);
}

QList<Settings::Environment::TerminalItem> Settings::Environment::loadTerminalList() const
{
#ifdef Q_OS_WINDOWS
Expand Down Expand Up @@ -4094,6 +4124,8 @@ void Settings::Environment::doSave()

saveValue("hide_non_support_files_file_view",mHideNonSupportFilesInFileView);
saveValue("open_files_in_single_instance",mOpenFilesInSingleInstance);

saveValue("data_size_dialect", (int)mDataSizeDialect);
}

QString Settings::Environment::interfaceFont() const
Expand Down
14 changes: 14 additions & 0 deletions RedPandaIDE/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ class Settings
QString param;
};

enum class DataSizeDialect {
/* UseKdeConfig = 0, */
SiDecimal = 1,
IecBinary = 2,
JedecBinary = 3,
};

explicit Environment(Settings * settings);
QString theme() const;
void setTheme(const QString &theme);
Expand Down Expand Up @@ -595,6 +602,12 @@ class Settings

static QMap<QString, QString> terminalArgsPatternMagicVariables();

DataSizeDialect dataSizeDialect() const;
void setDataSizeDialect(DataSizeDialect dataSizeDialect);

static QLocale::DataSizeFormats qtDataSizeDialect(DataSizeDialect dataSizeDialect);
QLocale::DataSizeFormats qtDataSizeDialect() const;

private:
bool isTerminalValid();
void checkAndSetTerminal();
Expand All @@ -617,6 +630,7 @@ class Settings
bool mUseCustomTerminal;
bool mHideNonSupportFilesInFileView;
bool mOpenFilesInSingleInstance;
DataSizeDialect mDataSizeDialect;

static const QMap<QString, QString> mTerminalArgsPatternMagicVariables;
// _Base interface
Expand Down
110 changes: 110 additions & 0 deletions RedPandaIDE/settingsdialog/environmentdatasizewidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2020-2022 Roy Qu ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "environmentdatasizewidget.h"
#include "ui_environmentdatasizewidget.h"
#include "../settings.h"
#include "../iconsmanager.h"
#include "../systemconsts.h"
#include "../compiler/executablerunner.h"
#include "utils.h"
#include "utils/escape.h"
#include "utils/font.h"

#include <QFileDialog>
#include <QMessageBox>

EnvironmentDataSizeWidget::EnvironmentDataSizeWidget(const QString& name, const QString& group, QWidget *parent) :
SettingsWidget(name,group,parent),
ui(new Ui::EnvironmentDataSizeWidget)
{
ui->setupUi(this);
updateScalePreview(pSettings->environment().dataSizeDialect());
}

EnvironmentDataSizeWidget::~EnvironmentDataSizeWidget()
{
delete ui;
}

void EnvironmentDataSizeWidget::updateScalePreview(DataSizeDialect dialect)
{
QLocale locale = QLocale::system();
QLocale::DataSizeFormats qtDialect = Settings::Environment::qtDataSizeDialect(dialect);
QString previewText;
auto append = [&] (QString display1, qint64 size1, QString display2, qint64 size2) {
previewText += display1;
previewText += " B = ";
previewText += locale.formattedDataSize(size1, 2, qtDialect);
previewText += ", ";
previewText += display2;
previewText += " B = ";
previewText += locale.formattedDataSize(size2, 2, qtDialect);
previewText += "\n";
};
append("10³", 1'000, "2¹⁰", 1LL << 10);
append("10⁶", 1'000'000, "2²⁰", 1LL << 20);
append("10⁹", 1'000'000'000, "2³⁰", 1LL << 30);
append("10¹²", 1'000'000'000'000, "2⁴⁰", 1LL << 40);
append("10¹⁵", 1'000'000'000'000'000, "2⁵⁰", 1LL << 50);
append("10¹⁸", 1'000'000'000'000'000'000, "2⁶⁰", 1LL << 60);
ui->tbScalePreview->setText(previewText);
}

void EnvironmentDataSizeWidget::doLoad()
{
switch (pSettings->environment().dataSizeDialect()) {
case DataSizeDialect::SiDecimal:
ui->rbSiDecimal->setChecked(true);
break;
case DataSizeDialect::IecBinary:
ui->rbIecBinary->setChecked(true);
break;
case DataSizeDialect::JedecBinary:
ui->rbJedecBinary->setChecked(true);
break;
}
}

void EnvironmentDataSizeWidget::doSave()
{
if (ui->rbSiDecimal->isChecked())
pSettings->environment().setDataSizeDialect(DataSizeDialect::SiDecimal);
else if (ui->rbIecBinary->isChecked())
pSettings->environment().setDataSizeDialect(DataSizeDialect::IecBinary);
else if (ui->rbJedecBinary->isChecked())
pSettings->environment().setDataSizeDialect(DataSizeDialect::JedecBinary);
pSettings->environment().save();
}

void EnvironmentDataSizeWidget::updateIcons(const QSize &)
{
}

void EnvironmentDataSizeWidget::on_rbSiDecimal_clicked()
{
updateScalePreview(DataSizeDialect::SiDecimal);
}

void EnvironmentDataSizeWidget::on_rbIecBinary_clicked()
{
updateScalePreview(DataSizeDialect::IecBinary);
}

void EnvironmentDataSizeWidget::on_rbJedecBinary_clicked()
{
updateScalePreview(DataSizeDialect::JedecBinary);
}
56 changes: 56 additions & 0 deletions RedPandaIDE/settingsdialog/environmentdatasizewidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2020-2022 Roy Qu ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef ENVIRONMENTDATASIZEWIDGET_H
#define ENVIRONMENTDATASIZEWIDGET_H

#include "settings.h"
#include "settingswidget.h"
#include "utils.h"

namespace Ui {
class EnvironmentDataSizeWidget;
}

class EnvironmentDataSizeWidget : public SettingsWidget
{
Q_OBJECT

using DataSizeDialect = Settings::Environment::DataSizeDialect;

public:
explicit EnvironmentDataSizeWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
~EnvironmentDataSizeWidget();

private:
void updateScalePreview(DataSizeDialect dialect);

private:
Ui::EnvironmentDataSizeWidget *ui;

private slots:
void on_rbSiDecimal_clicked();
void on_rbIecBinary_clicked();
void on_rbJedecBinary_clicked();

// SettingsWidget interface
protected:
void doLoad() override;
void doSave() override;
void updateIcons(const QSize &size) override;
};

#endif // ENVIRONMENTDATASIZEWIDGET_H
64 changes: 64 additions & 0 deletions RedPandaIDE/settingsdialog/environmentdatasizewidget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EnvironmentDataSizeWidget</class>
<widget class="QWidget" name="EnvironmentDataSizeWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="grpDataSize">
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0">
<widget class="QRadioButton" name="rbIecBinary">
<property name="text">
<string>IEC binary</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="rbJedecBinary">
<property name="text">
<string>JEDEC binary extrapolated</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QTextBrowser" name="tbScalePreview"/>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="rbSiDecimal">
<property name="text">
<string>SI decimal</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<tabstops>
<tabstop>grpDataSize</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
4 changes: 4 additions & 0 deletions RedPandaIDE/settingsdialog/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "environmentfolderswidget.h"
#include "environmentperformancewidget.h"
#include "environmentprogramswidget.h"
#include "environmentdatasizewidget.h"
#include "executorgeneralwidget.h"
#include "executorproblemsetwidget.h"
#include "debuggeneralwidget.h"
Expand Down Expand Up @@ -166,6 +167,9 @@ PSettingsDialog SettingsDialog::optionDialog(QWidget *parent)
&SettingsDialog::closeAndQuit);
dialog->addWidget(widget);

widget = new EnvironmentDataSizeWidget(tr("Data Size Unit"), tr("Environment"));
dialog->addWidget(widget);

widget = new CompilerSetOptionWidget(tr("Compiler Set"),tr("Compiler"));
dialog->addWidget(widget);

Expand Down
Loading

0 comments on commit e706bc7

Please sign in to comment.