2 * This file is part of the PulseView project.
4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include <boost/version.hpp>
25 #include <QApplication>
27 #include <QDialogButtonBox>
28 #include <QFileDialog>
29 #include <QFormLayout>
31 #include <QHBoxLayout>
33 #include <QMainWindow>
34 #include <QMessageBox>
35 #include <QPushButton>
39 #include <QTextBrowser>
40 #include <QTextDocument>
41 #include <QTextStream>
42 #include <QVBoxLayout>
44 #include "settings.hpp"
46 #include "pv/devicemanager.hpp"
47 #include "pv/globalsettings.hpp"
48 #include "pv/logging.hpp"
50 #include <libsigrokcxx/libsigrokcxx.hpp>
53 #include <libsigrokdecode/libsigrokdecode.h>
56 using std::shared_ptr;
62 * Special version of a QListView that has the width of the first column as minimum size.
64 * @note Inspired by https://github.com/qt-creator/qt-creator/blob/master/src/plugins/coreplugin/dialogs/settingsdialog.cpp
66 class PageListWidget: public QListWidget
72 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
75 QSize sizeHint() const final
77 int width = sizeHintForColumn(0) + frameWidth() * 2 + 5;
78 if (verticalScrollBar()->isVisible())
79 width += verticalScrollBar()->width();
80 return QSize(width, 100);
84 Settings::Settings(DeviceManager &device_manager, QWidget *parent) :
85 QDialog(parent, nullptr),
86 device_manager_(device_manager)
91 log_view_ = create_log_view();
94 page_list = new PageListWidget();
95 page_list->setViewMode(QListView::ListMode);
96 page_list->setMovement(QListView::Static);
97 page_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
99 pages = new QStackedWidget;
101 page_list->setCurrentIndex(page_list->model()->index(0, 0));
103 // Create the rest of the dialog
104 QHBoxLayout *tab_layout = new QHBoxLayout;
105 tab_layout->addWidget(page_list);
106 tab_layout->addWidget(pages, Qt::AlignLeft);
108 QDialogButtonBox *button_box = new QDialogButtonBox(
109 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
111 QVBoxLayout* root_layout = new QVBoxLayout(this);
112 root_layout->addLayout(tab_layout);
113 root_layout->addWidget(button_box);
115 connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
116 connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
117 connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
118 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
120 // Start to record changes
121 GlobalSettings settings;
122 settings.start_tracking();
125 void Settings::create_pages()
128 pages->addWidget(get_view_settings_form(pages));
130 QListWidgetItem *viewButton = new QListWidgetItem(page_list);
131 viewButton->setIcon(QIcon(":/icons/settings-views.svg"));
132 viewButton->setText(tr("Views"));
133 viewButton->setTextAlignment(Qt::AlignVCenter);
134 viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
138 pages->addWidget(get_decoder_settings_form(pages));
140 QListWidgetItem *decoderButton = new QListWidgetItem(page_list);
141 decoderButton->setIcon(QIcon(":/icons/add-decoder.svg"));
142 decoderButton->setText(tr("Decoders"));
143 decoderButton->setTextAlignment(Qt::AlignVCenter);
144 decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
148 pages->addWidget(get_about_page(pages));
150 QListWidgetItem *aboutButton = new QListWidgetItem(page_list);
151 aboutButton->setIcon(QIcon(":/icons/information.svg"));
152 aboutButton->setText(tr("About"));
153 aboutButton->setTextAlignment(Qt::AlignVCenter);
154 aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
157 pages->addWidget(get_logging_page(pages));
159 QListWidgetItem *loggingButton = new QListWidgetItem(page_list);
160 loggingButton->setIcon(QIcon(":/icons/information.svg"));
161 loggingButton->setText(tr("Logging"));
162 loggingButton->setTextAlignment(Qt::AlignVCenter);
163 loggingButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
166 QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const
168 GlobalSettings settings;
170 QCheckBox *cb = new QCheckBox();
171 cb->setChecked(settings.value(key).toBool());
172 connect(cb, SIGNAL(stateChanged(int)), this, slot);
176 QPlainTextEdit *Settings::create_log_view() const
178 GlobalSettings settings;
180 QPlainTextEdit *log_view = new QPlainTextEdit();
182 log_view->setReadOnly(true);
183 log_view->setWordWrapMode(QTextOption::NoWrap);
184 log_view->setCenterOnScroll(true);
186 log_view->appendHtml(logging.get_log());
187 connect(&logging, SIGNAL(logged_text(QString)),
188 log_view, SLOT(appendHtml(QString)));
193 QWidget *Settings::get_view_settings_form(QWidget *parent) const
195 GlobalSettings settings;
198 QWidget *form = new QWidget(parent);
199 QVBoxLayout *form_layout = new QVBoxLayout(form);
201 // Trace view settings
202 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
203 form_layout->addWidget(trace_view_group);
205 QFormLayout *trace_view_layout = new QFormLayout();
206 trace_view_group->setLayout(trace_view_layout);
208 cb = create_checkbox(GlobalSettings::Key_View_ColoredBG,
209 SLOT(on_view_coloredBG_changed(int)));
210 trace_view_layout->addRow(tr("Use colored trace &background"), cb);
212 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq,
213 SLOT(on_view_zoomToFitDuringAcq_changed(int)));
214 trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb);
216 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq,
217 SLOT(on_view_zoomToFitAfterAcq_changed(int)));
218 trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb);
220 cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime,
221 SLOT(on_view_triggerIsZero_changed(int)));
222 trace_view_layout->addRow(tr("Show time zero at the trigger"), cb);
224 cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling,
225 SLOT(on_view_stickyScrolling_changed(int)));
226 trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb);
228 cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints,
229 SLOT(on_view_showSamplingPoints_changed(int)));
230 trace_view_layout->addRow(tr("Show data &sampling points"), cb);
232 cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid,
233 SLOT(on_view_showAnalogMinorGrid_changed(int)));
234 trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb);
236 cb = create_checkbox(GlobalSettings::Key_View_ShowHoverMarker,
237 SLOT(on_view_showHoverMarker_changed(int)));
238 trace_view_layout->addRow(tr("Highlight mouse cursor using a vertical marker line"), cb);
240 QComboBox *thr_disp_mode_cb = new QComboBox();
241 thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
242 thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
243 thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots);
244 thr_disp_mode_cb->setCurrentIndex(
245 settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt());
246 connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)),
247 this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
248 trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb);
250 QSpinBox *default_div_height_sb = new QSpinBox();
251 default_div_height_sb->setRange(20, 1000);
252 default_div_height_sb->setSuffix(tr(" pixels"));
253 default_div_height_sb->setValue(
254 settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt());
255 connect(default_div_height_sb, SIGNAL(valueChanged(int)), this,
256 SLOT(on_view_defaultDivHeight_changed(int)));
257 trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb);
259 QSpinBox *default_logic_height_sb = new QSpinBox();
260 default_logic_height_sb->setRange(5, 1000);
261 default_logic_height_sb->setSuffix(tr(" pixels"));
262 default_logic_height_sb->setValue(
263 settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt());
264 connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this,
265 SLOT(on_view_defaultLogicHeight_changed(int)));
266 trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb);
271 QWidget *Settings::get_decoder_settings_form(QWidget *parent)
274 GlobalSettings settings;
277 QWidget *form = new QWidget(parent);
278 QVBoxLayout *form_layout = new QVBoxLayout(form);
281 QGroupBox *decoder_group = new QGroupBox(tr("Decoders"));
282 form_layout->addWidget(decoder_group);
284 QFormLayout *decoder_layout = new QFormLayout();
285 decoder_group->setLayout(decoder_layout);
287 cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable,
288 SLOT(on_dec_initialStateConfigurable_changed(int)));
289 decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
291 // Annotation export settings
292 ann_export_format_ = new QLineEdit();
293 ann_export_format_->setText(
294 settings.value(GlobalSettings::Key_Dec_ExportFormat).toString());
295 connect(ann_export_format_, SIGNAL(textChanged(const QString&)),
296 this, SLOT(on_dec_exportFormat_changed(const QString&)));
297 decoder_layout->addRow(tr("Annotation export format"), ann_export_format_);
298 QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %c: row name; %q: use quotations marks"));
299 description_1->setAlignment(Qt::AlignRight);
300 decoder_layout->addRow(description_1);
301 QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts"));
302 description_2->setAlignment(Qt::AlignRight);
303 decoder_layout->addRow(description_2);
313 static gint sort_pds(gconstpointer a, gconstpointer b)
315 const struct srd_decoder *sda, *sdb;
317 sda = (const struct srd_decoder *)a;
318 sdb = (const struct srd_decoder *)b;
319 return strcmp(sda->id, sdb->id);
323 QWidget *Settings::get_about_page(QWidget *parent) const
326 struct srd_decoder *dec;
329 QLabel *icon = new QLabel();
330 icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg")));
332 /* Setup the license field, with the project homepage link. */
333 QLabel *gpl_home_info = new QLabel();
334 gpl_home_info->setText(tr("%1<br /><a href=\"http://%2\">%2</a>").arg(
335 tr("GNU GPL, version 3 or later"),
336 QApplication::organizationDomain()));
337 gpl_home_info->setOpenExternalLinks(true);
339 shared_ptr<sigrok::Context> context = device_manager_.context();
343 s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
347 /* Version, library, and feature info */
348 s.append("<tr><td colspan=\"2\"><b>" +
349 tr("Versions, libraries and features:") + "</b></td></tr>");
351 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
352 .arg(QApplication::applicationName(),
353 QApplication::applicationVersion()));
354 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
355 .arg(QString("Qt"), qVersion()));
356 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
357 .arg(QString("glibmm"), PV_GLIBMM_VERSION));
358 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
359 .arg(QString("Boost"), BOOST_LIB_VERSION));
361 s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
362 .arg(QString("libsigrok"), SR_PACKAGE_VERSION_STRING,
363 SR_LIB_VERSION_STRING, sr_package_version_string_get(),
364 sr_lib_version_string_get()));
366 GSList *l_orig = sr_buildinfo_libs_get();
367 for (GSList *l = l_orig; l; l = l->next) {
368 GSList *m = (GSList *)l->data;
369 const char *lib = (const char *)m->data;
370 const char *version = (const char *)m->next->data;
371 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
372 .arg(QString(lib), QString(version)));
373 g_slist_free_full(m, g_free);
375 g_slist_free(l_orig);
377 char *host = sr_buildinfo_host_get();
378 s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
379 .arg(QString(host)));
382 char *scpi_backends = sr_buildinfo_scpi_backends_get();
383 s.append(QString("<tr><td><i>- SCPI backends</i></td><td>%1</td></tr>")
384 .arg(QString(scpi_backends)));
385 g_free(scpi_backends);
388 s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
389 .arg(QString("libsigrokdecode"), SRD_PACKAGE_VERSION_STRING,
390 SRD_LIB_VERSION_STRING, srd_package_version_string_get(),
391 srd_lib_version_string_get()));
393 l_orig = srd_buildinfo_libs_get();
394 for (GSList *l = l_orig; l; l = l->next) {
395 GSList *m = (GSList *)l->data;
396 const char *lib = (const char *)m->data;
397 const char *version = (const char *)m->next->data;
398 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
399 .arg(QString(lib), QString(version)));
400 g_slist_free_full(m, g_free);
402 g_slist_free(l_orig);
404 host = srd_buildinfo_host_get();
405 s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
406 .arg(QString(host)));
410 s.append("<tr><td colspan=\"2\"></td></tr>");
411 s.append("<tr><td colspan=\"2\"><b>" +
412 tr("Firmware search paths:") + "</b></td></tr>");
414 l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE);
415 for (GSList *l = l_orig; l; l = l->next)
416 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(
417 QString((char*)l->data)));
418 g_slist_free_full(l_orig, g_free);
421 s.append("<tr><td colspan=\"2\"></td></tr>");
422 s.append("<tr><td colspan=\"2\"><b>" +
423 tr("Protocol decoder search paths:") + "</b></td></tr>");
425 l_orig = srd_searchpaths_get();
426 for (GSList *l = l_orig; l; l = l->next)
427 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(
428 QString((char*)l->data)));
429 g_slist_free_full(l_orig, g_free);
432 /* Set up the supported field */
433 s.append("<tr><td colspan=\"2\"></td></tr>");
434 s.append("<tr><td colspan=\"2\"><b>" +
435 tr("Supported hardware drivers:") + "</b></td></tr>");
436 for (auto entry : context->drivers()) {
437 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
438 .arg(QString::fromUtf8(entry.first.c_str()),
439 QString::fromUtf8(entry.second->long_name().c_str())));
442 s.append("<tr><td colspan=\"2\"></td></tr>");
443 s.append("<tr><td colspan=\"2\"><b>" +
444 tr("Supported input formats:") + "</b></td></tr>");
445 for (auto entry : context->input_formats()) {
446 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
447 .arg(QString::fromUtf8(entry.first.c_str()),
448 QString::fromUtf8(entry.second->description().c_str())));
451 s.append("<tr><td colspan=\"2\"></td></tr>");
452 s.append("<tr><td colspan=\"2\"><b>" +
453 tr("Supported output formats:") + "</b></td></tr>");
454 for (auto entry : context->output_formats()) {
455 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
456 .arg(QString::fromUtf8(entry.first.c_str()),
457 QString::fromUtf8(entry.second->description().c_str())));
461 s.append("<tr><td colspan=\"2\"></td></tr>");
462 s.append("<tr><td colspan=\"2\"><b>" +
463 tr("Supported protocol decoders:") + "</b></td></tr>");
464 GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
465 sl = g_slist_sort(sl, sort_pds);
466 for (const GSList *l = sl; l; l = l->next) {
467 dec = (struct srd_decoder *)l->data;
468 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
469 .arg(QString::fromUtf8(dec->id),
470 QString::fromUtf8(dec->longname)));
475 s.append("</table>");
477 QTextDocument *supported_doc = new QTextDocument();
478 supported_doc->setHtml(s);
480 QTextBrowser *support_list = new QTextBrowser();
481 support_list->setDocument(supported_doc);
483 QHBoxLayout *h_layout = new QHBoxLayout();
484 h_layout->setAlignment(Qt::AlignLeft);
485 h_layout->addWidget(icon);
486 h_layout->addWidget(gpl_home_info);
488 QVBoxLayout *layout = new QVBoxLayout();
489 layout->addLayout(h_layout);
490 layout->addWidget(support_list);
492 QWidget *page = new QWidget(parent);
493 page->setLayout(layout);
498 QWidget *Settings::get_logging_page(QWidget *parent) const
500 GlobalSettings settings;
503 QSpinBox *loglevel_sb = new QSpinBox();
504 loglevel_sb->setMaximum(SR_LOG_SPEW);
505 loglevel_sb->setValue(logging.get_log_level());
506 connect(loglevel_sb, SIGNAL(valueChanged(int)), this,
507 SLOT(on_log_logLevel_changed(int)));
509 QHBoxLayout *loglevel_layout = new QHBoxLayout();
510 loglevel_layout->addWidget(new QLabel(tr("Log level:")));
511 loglevel_layout->addWidget(loglevel_sb);
513 // Background buffer size
514 QSpinBox *buffersize_sb = new QSpinBox();
515 buffersize_sb->setSuffix(tr(" lines"));
516 buffersize_sb->setMinimum(Logging::MIN_BUFFER_SIZE);
517 buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE);
518 buffersize_sb->setValue(
519 settings.value(GlobalSettings::Key_Log_BufferSize).toInt());
520 connect(buffersize_sb, SIGNAL(valueChanged(int)), this,
521 SLOT(on_log_bufferSize_changed(int)));
523 QHBoxLayout *buffersize_layout = new QHBoxLayout();
524 buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:")));
525 buffersize_layout->addWidget(buffersize_sb);
528 QPushButton *save_log_pb = new QPushButton(
529 QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")),
530 tr("&Save to File"));
531 connect(save_log_pb, SIGNAL(clicked(bool)),
532 this, SLOT(on_log_saveToFile_clicked(bool)));
535 QPushButton *pop_out_pb = new QPushButton(
536 QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")),
538 connect(pop_out_pb, SIGNAL(clicked(bool)),
539 this, SLOT(on_log_popOut_clicked(bool)));
541 QHBoxLayout *control_layout = new QHBoxLayout();
542 control_layout->addLayout(loglevel_layout);
543 control_layout->addLayout(buffersize_layout);
544 control_layout->addWidget(save_log_pb);
545 control_layout->addWidget(pop_out_pb);
547 QVBoxLayout *root_layout = new QVBoxLayout();
548 root_layout->addLayout(control_layout);
549 root_layout->addWidget(log_view_);
551 QWidget *page = new QWidget(parent);
552 page->setLayout(root_layout);
557 void Settings::accept()
559 GlobalSettings settings;
560 settings.stop_tracking();
565 void Settings::reject()
567 GlobalSettings settings;
568 settings.undo_tracked_changes();
573 void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
578 pages->setCurrentIndex(page_list->row(current));
581 void Settings::on_view_zoomToFitDuringAcq_changed(int state)
583 GlobalSettings settings;
584 settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false);
587 void Settings::on_view_zoomToFitAfterAcq_changed(int state)
589 GlobalSettings settings;
590 settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false);
593 void Settings::on_view_triggerIsZero_changed(int state)
595 GlobalSettings settings;
596 settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false);
599 void Settings::on_view_coloredBG_changed(int state)
601 GlobalSettings settings;
602 settings.setValue(GlobalSettings::Key_View_ColoredBG, state ? true : false);
605 void Settings::on_view_stickyScrolling_changed(int state)
607 GlobalSettings settings;
608 settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
611 void Settings::on_view_showSamplingPoints_changed(int state)
613 GlobalSettings settings;
614 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
617 void Settings::on_view_showAnalogMinorGrid_changed(int state)
619 GlobalSettings settings;
620 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
623 void Settings::on_view_showHoverMarker_changed(int state)
625 GlobalSettings settings;
626 settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, state ? true : false);
629 void Settings::on_view_conversionThresholdDispMode_changed(int state)
631 GlobalSettings settings;
632 settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state);
635 void Settings::on_view_defaultDivHeight_changed(int value)
637 GlobalSettings settings;
638 settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value);
641 void Settings::on_view_defaultLogicHeight_changed(int value)
643 GlobalSettings settings;
644 settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value);
648 void Settings::on_dec_initialStateConfigurable_changed(int state)
650 GlobalSettings settings;
651 settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
654 void Settings::on_dec_exportFormat_changed(const QString &text)
656 GlobalSettings settings;
657 settings.setValue(GlobalSettings::Key_Dec_ExportFormat, text);
661 void Settings::on_log_logLevel_changed(int value)
663 logging.set_log_level(value);
666 void Settings::on_log_bufferSize_changed(int value)
668 GlobalSettings settings;
669 settings.setValue(GlobalSettings::Key_Log_BufferSize, value);
672 void Settings::on_log_saveToFile_clicked(bool checked)
676 const QString file_name = QFileDialog::getSaveFileName(
677 this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)"));
679 if (file_name.isEmpty())
682 QFile file(file_name);
683 if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
684 QTextStream out_stream(&file);
685 out_stream << log_view_->toPlainText();
687 if (out_stream.status() == QTextStream::Ok) {
688 QMessageBox msg(this);
689 msg.setText(tr("Success"));
690 msg.setInformativeText(tr("Log saved to %1.").arg(file_name));
691 msg.setStandardButtons(QMessageBox::Ok);
692 msg.setIcon(QMessageBox::Information);
699 QMessageBox msg(this);
700 msg.setText(tr("Error"));
701 msg.setInformativeText(tr("File %1 could not be written to.").arg(file_name));
702 msg.setStandardButtons(QMessageBox::Ok);
703 msg.setIcon(QMessageBox::Warning);
707 void Settings::on_log_popOut_clicked(bool checked)
711 // Create the window as a sub-window so it closes when the main window closes
712 QMainWindow *window = new QMainWindow(nullptr, Qt::SubWindow);
714 window->setObjectName(QString::fromUtf8("Log Window"));
715 window->setWindowTitle(tr("%1 Log").arg(PV_TITLE));
717 // Use same width/height as the settings dialog
718 window->resize(width(), height());
720 window->setCentralWidget(create_log_view());
724 } // namespace dialogs