Skip to content

Commit

Permalink
general: fix native dialog preference
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed Dec 19, 2024
1 parent 3b494ff commit e524fc3
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 61 deletions.
10 changes: 7 additions & 3 deletions gui/src/printplotmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QFileDialog>
#include <QDateTime>
#include <QCoreApplication>
#include <pluginbase/preferences.h>

using namespace scopy;

Expand All @@ -35,9 +36,12 @@ PrintPlotManager::PrintPlotManager(QObject *parent)
void PrintPlotManager::printPlots(QList<PlotWidget *> plotList, QString toolName)
{
// select folder where to save
QString folderPath = QFileDialog::getExistingDirectory(
nullptr, "Select Folder", "",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::DontUseNativeDialog);
bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString folderPath = QFileDialog::getExistingDirectory(nullptr, "Select Folder", "",
(useNativeDialogs ? QFileDialog::Options()
: QFileDialog::ShowDirsOnly |
QFileDialog::DontResolveSymlinks |
QFileDialog::DontUseNativeDialog));

if(!folderPath.isEmpty()) {
// use current date and tool name to crete the file name
Expand Down
4 changes: 3 additions & 1 deletion plugins/datalogger/src/menus/dataloggingmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <menusectionwidget.h>
#include <style.h>
#include <timemanager.hpp>
#include <pluginbase/preferences.h>

using namespace scopy;
using namespace datamonitor;
Expand Down Expand Up @@ -130,10 +131,11 @@ void DataLoggingMenu::chooseFile()
// turn off live data logging when switching files
liveDataLoggingButton->onOffswitch()->setChecked(false);

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString selectedFilter;
filename = QFileDialog::getSaveFileName(
this, tr("Export"), "", tr("Comma-separated values files (*.csv);;All Files(*)"), &selectedFilter,
QFileDialog::Options(QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
dataLoggingFilePath->getLineEdit()->setText(filename);
}

Expand Down
2 changes: 0 additions & 2 deletions plugins/m2k/m2k-gui/include/m2k-gui/printableplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ class SCOPY_M2K_GUI_EXPORT PrintablePlot : public BasicPlot
PrintablePlot(QWidget *parent);

void dropBackground(bool drop);
void setUseNativeDialog(bool nativeDialog);

public Q_SLOTS:
void printPlot(const QString &toolName = "");

private:
QwtPlotRenderer d_plotRenderer;
QwtLegend *legendDisplay;
bool d_useNativeDialog;
};
} // namespace scopy

Expand Down
7 changes: 3 additions & 4 deletions plugins/m2k/m2k-gui/src/printableplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
#include <QDateTime>
#include <QFileDialog>
#include <QImageWriter>
#include <pluginbase/preferences.h>

using namespace scopy;

PrintablePlot::PrintablePlot(QWidget *parent)
: BasicPlot(parent)
, d_plotRenderer(new QwtPlotRenderer(this))
, d_useNativeDialog(true)
{
dropBackground(true);
}
Expand All @@ -40,8 +40,6 @@ void PrintablePlot::dropBackground(bool drop)
d_plotRenderer.setDiscardFlag(QwtPlotRenderer::DiscardCanvasBackground, drop);
}

void PrintablePlot::setUseNativeDialog(bool nativeDialog) { d_useNativeDialog = nativeDialog; }

void PrintablePlot::printPlot(const QString &toolName)
{
legendDisplay = new QwtLegend(this);
Expand Down Expand Up @@ -71,10 +69,11 @@ void PrintablePlot::printPlot(const QString &toolName)
}
}

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString selectedFilter = QString("PDF ") + tr("Documents") + " (*.pdf)";
fileName = QFileDialog::getSaveFileName(
nullptr, tr("Export File Name"), fileName, filter.join(";;"), &selectedFilter,
(d_useNativeDialog ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.split(".").size() <= 1) {
// file name w/o extension. Let's append it
Expand Down
6 changes: 4 additions & 2 deletions plugins/m2k/src/old/logicanalyzer/decoder_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ void DecoderTable::exportData()

filter += QString(tr("Comma-separated row per sample (*.csv)"));
filter += QString(tr("Tab-delimited row per annotation (*.txt)"));
QString fileName = QFileDialog::getSaveFileName(this, tr("Export"), "", filter.join(";;"), &selectedFilter,
QFileDialog::DontUseNativeDialog);
bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getSaveFileName(
this, tr("Export"), "", filter.join(";;"), &selectedFilter,
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.isEmpty()) {
return;
Expand Down
9 changes: 2 additions & 7 deletions plugins/m2k/src/old/logicanalyzer/logic_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,6 @@ LogicAnalyzer::~LogicAnalyzer()
delete ui;
}

void LogicAnalyzer::setNativeDialogs(bool nativeDialogs)
{
M2kTool::setNativeDialogs(nativeDialogs);
m_plot.setUseNativeDialog(nativeDialogs);
}

void LogicAnalyzer::setData(const uint16_t *const data, int size)
{

Expand Down Expand Up @@ -2825,9 +2819,10 @@ void LogicAnalyzer::exportData()
filter += QString(tr("Value Change Dump(*.vcd)"));
filter += QString(tr("All Files(*)"));

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getSaveFileName(
this, tr("Export"), "", filter.join(";;"), &selectedFilter,
(m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.isEmpty()) {
return;
Expand Down
1 change: 0 additions & 1 deletion plugins/m2k/src/old/logicanalyzer/logic_analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class LogicAnalyzer : public M2kTool
explicit LogicAnalyzer(libm2k::context::M2k *m2k, Filter *filt, ToolMenuEntry *toolMenuItem, QJSEngine *engine,
QWidget *parent, bool offline_mode_ = 0);
~LogicAnalyzer();
void setNativeDialogs(bool nativeDialogs) override;

public: // Mixed Signal View Interface
// enable mixed signal view
Expand Down
6 changes: 0 additions & 6 deletions plugins/m2k/src/old/m2ktool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,11 @@ void M2kTool::setName(const QString &name) { this->name = name; }

void M2kTool::settingsLoaded() {}

/* Tools that use file dialogs should overload this method
to ensure their file dialogs are configured correspondingly */
void M2kTool::setNativeDialogs(bool nativeDialogs) { m_useNativeDialogs = nativeDialogs; }

ApiObject *M2kTool::getApi() { return api; }

void M2kTool::readPreferences()
{
saveOnExit = p->get("general_save_on_exit").toBool();
m_useNativeDialogs = p->get("general_native_dialogs").toBool();
;
}

ToolMenuEntry *M2kTool::getTme() const { return tme; }
Expand Down
2 changes: 0 additions & 2 deletions plugins/m2k/src/old/m2ktool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class M2kTool : public QWidget, public ResourceUser
const QString &getName();
void setName(const QString &name);
virtual void settingsLoaded();
virtual void setNativeDialogs(bool nativeDialogs);

ApiObject *getApi();

Expand All @@ -83,7 +82,6 @@ public Q_SLOTS:
QMainWindow *window;
ToolMenuEntry *tme;
Preferences *p;
bool m_useNativeDialogs;
QWidget *m_centralWidget;
};
} // namespace m2k
Expand Down
3 changes: 2 additions & 1 deletion plugins/m2k/src/old/manualcalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,11 @@ void ManualCalibration::on_saveButton_clicked()
QString fileName;
QString selectedFilter;

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
if(calibrationFilePath == "") {
fileName = QFileDialog::getSaveFileName(
this, tr("Save file"), "", tr("Ini files (*.ini)"), &selectedFilter,
(m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
} else {
fileName = calibrationFilePath;
}
Expand Down
9 changes: 6 additions & 3 deletions plugins/m2k/src/old/network_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,11 @@ NetworkAnalyzer::NetworkAnalyzer(libm2k::context::M2k *m2k, QString uri, Filter
}
}

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString selectedFilter = filter[0];
QString fileName = QFileDialog::getSaveFileName(
this, tr("Save to"), fileNameHint, filter.join(";;"), &selectedFilter,
(m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.split(".").size() <= 1) {
// file name w/o extension. Let's append it
Expand Down Expand Up @@ -679,11 +680,12 @@ NetworkAnalyzer::NetworkAnalyzer(libm2k::context::M2k *m2k, QString uri, Filter
});

connect(ui->importBtn, &QPushButton::clicked, [=]() {
bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getOpenFileName(
this, tr("Import"), "",
tr("Comma-separated values files (*.csv);;"
"Tab-delimited values files (*.txt)"),
nullptr, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
nullptr, (useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

FileManager fm("Network Analyzer");

Expand Down Expand Up @@ -850,9 +852,10 @@ void NetworkAnalyzer::on_btnExport_clicked()

QString selectedFilter = filter[0];

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getSaveFileName(
this, tr("Export"), "", filter.join(";;"), &selectedFilter,
(m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.split(".").size() <= 1) {
// file name w/o extension. Let's append it
Expand Down
15 changes: 6 additions & 9 deletions plugins/m2k/src/old/oscilloscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,6 @@ void Oscilloscope::remove_ref_waveform(QString name)
}
}

void Oscilloscope::setNativeDialogs(bool nativeDialogs)
{
M2kTool::setNativeDialogs(nativeDialogs);
plot.setUseNativeDialog(nativeDialogs);
}

void Oscilloscope::setLogicAnalyzer(logic::LogicAnalyzer *la)
{
qDebug() << "Logic Analyzer: " << la;
Expand Down Expand Up @@ -1506,9 +1500,10 @@ void Oscilloscope::init_channel_settings()

QString selectedFilter = filter[0];

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getSaveFileName(
this, tr("Export"), "", filter.join(";;"), &selectedFilter,
(m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.split(".").size() <= 1) {
// file name w/o extension. Let's append it
Expand Down Expand Up @@ -1933,9 +1928,10 @@ void Oscilloscope::btnExport_clicked()

QString selectedFilter = filter[0];

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getSaveFileName(
this, tr("Export"), "", filter.join(";;"), &selectedFilter,
(m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.split(".").size() <= 1) {
// file name w/o extension. Let's append it
Expand Down Expand Up @@ -2246,11 +2242,12 @@ void Oscilloscope::create_add_channel_panel()

void Oscilloscope::import()
{
bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getOpenFileName(
this, tr("Import"), "",
tr("Comma-separated values files (*.csv);;"
"Tab-delimited values files (*.txt)"),
nullptr, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
nullptr, (useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

FileManager fm("Oscilloscope");

Expand Down
1 change: 0 additions & 1 deletion plugins/m2k/src/old/oscilloscope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class Oscilloscope : public M2kTool

void add_ref_waveform(QString name, QVector<double> xData, QVector<double> yData, unsigned int sampleRate);
void remove_ref_waveform(QString name);
void setNativeDialogs(bool nativeDialogs) override;

void setLogicAnalyzer(logic::LogicAnalyzer *la);

Expand Down
6 changes: 0 additions & 6 deletions plugins/m2k/src/old/patterngenerator/pattern_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,6 @@ PatternGenerator::~PatternGenerator()
delete m_ui;
}

void PatternGenerator::setNativeDialogs(bool nativeDialogs)
{
M2kTool::setNativeDialogs(nativeDialogs);
m_plot.setUseNativeDialog(nativeDialogs);
}

void PatternGenerator::setupUi()
{
m_ui->setupUi(this);
Expand Down
1 change: 0 additions & 1 deletion plugins/m2k/src/old/patterngenerator/pattern_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class PatternGenerator : public M2kTool
explicit PatternGenerator(libm2k::context::M2k *m2k, Filter *filt, ToolMenuEntry *tme, QJSEngine *engine,
DIOManager *diom, QWidget *parent);
~PatternGenerator();
void setNativeDialogs(bool nativeDialogs) override;

Q_SIGNALS:
void dataAvailable(uint64_t, uint64_t, uint16_t *data);
Expand Down
3 changes: 2 additions & 1 deletion plugins/m2k/src/old/signal_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,13 +1291,14 @@ void SignalGenerator::loadFileFromPath(QString filename)

void SignalGenerator::loadFile()
{
bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getOpenFileName(
this, tr("Open File"), "",
tr("Comma-separated values files (*.csv);;"
"Tab-delimited values files (*.txt);;"
"Waveform Audio File Format (*.wav);;"
"Matlab files (*.mat)"),
nullptr, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
nullptr, (useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.isEmpty()) { // user hit cancel
return;
Expand Down
16 changes: 6 additions & 10 deletions plugins/m2k/src/old/spectrum_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,10 @@ SpectrumAnalyzer::SpectrumAnalyzer(libm2k::context::M2k *m2k, QString uri, Filte

QString selectedFilter = filter[0];

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getSaveFileName(
this, tr("Export"), "", filter.join(";;"), &selectedFilter,
(m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.split(".").size() <= 1) {
// file name w/o extension. Let's append it
Expand Down Expand Up @@ -831,13 +832,6 @@ SpectrumAnalyzer::~SpectrumAnalyzer()

QPushButton *SpectrumAnalyzer::getRunButton() { return ui->runSingleWidget->getRunButton(); }

void SpectrumAnalyzer::setNativeDialogs(bool nativeDialogs)
{
M2kTool::setNativeDialogs(nativeDialogs);
fft_plot->setUseNativeDialog(nativeDialogs);
waterfall_plot->setUseNativeDialog(nativeDialogs);
}

void SpectrumAnalyzer::readPreferences()
{
Preferences *p = Preferences::GetInstance();
Expand All @@ -859,9 +853,10 @@ void SpectrumAnalyzer::btnExportClicked()

QString selectedFilter = filter[0];

bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getSaveFileName(
this, tr("Export"), "", filter.join(";;"), &selectedFilter,
(m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
(useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

if(fileName.split(".").size() <= 1) {
// file name w/o extension. Let's append it
Expand Down Expand Up @@ -1464,11 +1459,12 @@ void SpectrumAnalyzer::on_btnAddRef_toggled(bool checked)

void SpectrumAnalyzer::on_btnBrowseFile_clicked()
{
bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool();
QString fileName = QFileDialog::getOpenFileName(
this, tr("Export"), "",
tr("Comma-separated values files (*.csv);;"
"Tab-delimited values files (*.txt)"),
nullptr, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
nullptr, (useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));

FileManager fm("Spectrum Analyzer");

Expand Down
1 change: 0 additions & 1 deletion plugins/m2k/src/old/spectrum_analyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class SpectrumAnalyzer : public M2kTool
m2k_iio_manager *m2k_man, QJSEngine *engine, QWidget *parent);
~SpectrumAnalyzer();
QPushButton *getRunButton();
void setNativeDialogs(bool nativeDialogs) override;
void setCurrentAverageIndexLabel(uint chnIdx);
public Q_SLOTS:
void readPreferences();
Expand Down

0 comments on commit e524fc3

Please sign in to comment.