QT4_WRAP_CPP(SOURCE_MOC
browse_lineedit.h
info_message.h
+ settings_dialog.h
mainwindow.h
parameter_delegate.h
)
ADD_EXECUTABLE(parameter_gui_exe
browse_lineedit.cpp
info_message.cpp
+ settings_dialog.cpp
main.cpp
mainwindow.cpp
parameter_delegate.cpp
# Input
HEADERS += browse_lineedit.h \
info_message.h \
+ settings_dialog.h \
mainwindow.h \
parameter_delegate.h \
xml_parameter_reader.h \
- xml_parameter_writer.h
+ xml_parameter_writer.h \
+ prm_parameter_writer.h
SOURCES += browse_lineedit.cpp \
info_message.cpp \
+ settings_dialog.cpp \
main.cpp \
mainwindow.cpp \
parameter_delegate.cpp \
xml_parameter_reader.cpp \
- xml_parameter_writer.cpp
+ xml_parameter_writer.cpp \
+ prm_parameter_writer.cpp
RESOURCES += application.qrc
QString settings_file = QDir::currentPath() + "/settings.ini"; // a file for user settings
gui_settings = new QSettings (settings_file, QSettings::IniFormat); // load settings
- // Up to now, we do not read any settings,
- // but this can be used in the future for customizing the GUI.
tree_widget = new QTreeWidget; // tree for showing XML tags
create_actions(); // create window actions as "Open",...
create_menus(); // and menus
+ create_toolbar();
+
statusBar()->showMessage(tr("Ready, start editing by double-clicking or hitting F2!"));
setWindowTitle(tr("[*]parameterGUI")); // set window title
if (filename.size() > 3) // if there is a file_name, try to load the file.
load_file(filename); // a vliad file has the xml extension, so we require size() > 3
+
+ apply_settings();
}
QFont font = item->font(1);
font.setWeight(QFont::Normal);
item->setFont(1,font);
+
+ const bool hide_default_items = gui_settings->value("Settings/hideDefault", false).toBool();
+ if (hide_default_items)
+ item->setHidden(true);
}
else
{
+ void MainWindow::show_settings ()
+ {
+ settings_dialog = new SettingsDialog(gui_settings,this);
+
+ connect(settings_dialog, SIGNAL(accepted()), this, SLOT(apply_settings()));
+ settings_dialog->exec();
+ disconnect(settings_dialog, SIGNAL(accepted()), this, SLOT(apply_settings()));
+ }
+
+
+
+ void MainWindow::apply_settings ()
+ {
+ update_visible_items();
+ update_font();
+ }
+
+
+
+ void MainWindow::toggle_visible_default_items()
+ {
+ const bool hide_default_values = gui_settings->value("Settings/hideDefault", false).toBool();
+ gui_settings->setValue("Settings/hideDefault", !hide_default_values);
+ update_visible_items();
+ }
+
+
+
+ void MainWindow::update_visible_items()
+ {
+ const bool hide_default_values = gui_settings->value("Settings/hideDefault", false).toBool();
+
+ if (hide_default_values)
+ {
+ for (int i = 0; i < tree_widget->topLevelItemCount(); ++i)
+ hide_default_item(tree_widget->topLevelItem(i));
+ hide_default->setChecked(true);
+ }
+ else
+ {
+ QTreeWidgetItemIterator it(tree_widget,QTreeWidgetItemIterator::Hidden);
+ while (*it)
+ {
+ (*it)->setHidden(false);
+ ++it;
+ }
+ hide_default->setChecked(false);
+ }
+ }
+
+
+
+ bool MainWindow::hide_default_item(QTreeWidgetItem *item)
+ {
+ bool has_default_value = true;
+
+ if (item->childCount() == 0)
+ {
+ if (item->text(5).startsWith("[Double"))
+ has_default_value = item->data(1,Qt::DisplayRole).toReal() == item->data(2,Qt::DisplayRole).toReal();
+ else
+ has_default_value = item->data(1,Qt::DisplayRole).toString() == item->data(2,Qt::DisplayRole).toString();
+ }
+ else
+ {
+ for (int i = 0; i < item->childCount(); ++i)
+ {
+ const bool child_has_default_value = hide_default_item(item->child(i));
+ has_default_value = has_default_value & child_has_default_value;
+ }
+ }
+
+ if (has_default_value)
+ item->setHidden(true);
+
+ return has_default_value;
+ }
+
+
+
void MainWindow::closeEvent(QCloseEvent *event)
{
if (maybe_save()) // reimplement the closeEvent from the QMainWindow class
about_qt_act->setStatusTip(tr("Show the Qt library's About box"));
connect(about_qt_act, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+ settings_act = new QAction(tr("Settings"), this);
+ settings_act->setStatusTip(tr("Show the Settings Dialog"));
+ connect(settings_act, SIGNAL(triggered()), this, SLOT(show_settings()));
+
set_to_default_act = new QAction("Set to default",context_menu);
tree_widget->addAction(set_to_default_act);
connect(set_to_default_act, SIGNAL(triggered()), this, SLOT(set_to_default()));
file_menu->addAction(open_act); // and add actions
file_menu->addAction(save_act);
file_menu->addAction(save_as_act);
+ file_menu->addSeparator();
+ file_menu->addAction(settings_act);
+ file_menu->addSeparator();
file_menu->addAction(exit_act);
menuBar()->addSeparator();
+ void MainWindow::create_toolbar()
+ {
+ QToolBar *toolbar = new QToolBar(tr("Toolbar"),this);
+
+ toolbar->addAction(open_act); // and add actions
+ toolbar->addAction(save_act);
+ toolbar->addAction(save_as_act);
+
+ toolbar->addSeparator();
+
+ hide_default = new QToolButton(toolbar);
+ hide_default->setText(tr("Hide default values"));
+ hide_default->setCheckable(true);
+ connect(hide_default, SIGNAL(clicked()), this, SLOT(toggle_visible_default_items()));
+ QAction *hide_default_act = toolbar->addWidget(hide_default);
+
+ QToolButton *change_font = new QToolButton(toolbar);
+ change_font->setText(tr("Change font"));
+ connect(change_font, SIGNAL(clicked()), this, SLOT(select_font()));
+ QAction *change_font_act = toolbar->addWidget(change_font);
+
+ addToolBar(toolbar);
+ }
+
+
+
bool MainWindow::maybe_save()
{
if (isWindowModified()) // if content was modified
setWindowTitle(tr(win_title.c_str())); // set the window title
setWindowModified(false); // and reset window modified
}
+
+
+
+ void MainWindow::update_font()
+ {
+ QString current_font_string = gui_settings->value("Settings/Font", QFont().toString()).toString();
+ QFont current_font;
+ current_font.fromString(current_font_string);
+ setFont(current_font);
+ }
+
+
+
+ void MainWindow::select_font()
+ {
+ QString current_font_string = gui_settings->value("Settings/Font", QFont().toString()).toString();
+ QFont current_font;
+ current_font.fromString(current_font_string);
+
+ bool ok;
+ QFont new_font = QFontDialog::getFont(
+ &ok, current_font, this);
+ if (ok) {
+ gui_settings->setValue("Settings/Font", new_font.toString());
+ setFont(new_font);
+ }
+ }
}
}
#include <QTreeWidget>
#include <QDialog>
#include <QSettings>
+#include <QToolBar>
+#include <QToolButton>
#include "info_message.h"
+#include "settings_dialog.h"
namespace dealii
*/
void item_changed(QTreeWidgetItem *item,
int column);
+
+ /**
+ * Show an information dialog, how
+ * parameters can be edited.
+ */
+ void show_settings ();
+
+ /**
+ * Apply the new settings to this window.
+ */
+ void apply_settings ();
+
+ /**
+ * Hide all default items in tree_widget if set in gui_settings.
+ * Otherwise restores all default values.
+ */
+ void update_visible_items();
+
+ /**
+ * Reads the font from gui_settings and applies it.
+ */
+ void update_font();
+
+ /**
+ * Changes whether default items should be displayed in the tree widget
+ * and calls update_visible_items() to apply the changes.
+ */
+ void toggle_visible_default_items();
+
+ /**
+ * Function that displays a font selection dialog, stores the result
+ * in gui_settings, and displays the new font.
+ */
+ void select_font();
private:
/**
* Show an information dialog, how
* This function creates all menus.
*/
void create_menus();
+
+ /**
+ * This function creates the toolbar.
+ */
+ void create_toolbar();
/**
* This function checks, if parameters were changed
* and show a dialog, if changes should be saved.
*/
void set_current_file (const QString &filename);
+ /**
+ * Determine if the item and all of its children have the default value,
+ * and hide all default items. Returns true if the item and all of its
+ * children have default values.
+ */
+ bool hide_default_item(QTreeWidgetItem *item);
+
/**
* This is the tree structure in which we store all parameters.
*/
* This is the documentation text area.
*/
QTextEdit *documentation_text_widget;
+
+ /** A tool button that allows to toggle between showing/hiding parameters
+ * with default values.
+ */
+ QToolButton *hide_default;
/**
* This menu provides all file actions as <tt>open</tt>, <tt>save</tt>, <tt>save as</tt>
* and <tt>exit</tt>
* QAction <tt>save as</tt> a file.
*/
QAction * save_as_act;
+ /**
+ * QAction <tt>save as</tt> a file.
+ */
+ QAction * settings_act;
/**
* QAction <tt>exit</tt> the GUI.
*/
* This dialog shows a short information message after loading a file.
*/
InfoMessage * info_message;
+
+ SettingsDialog * settings_dialog;
+
/**
* An object for storing user settings.
*/
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 by Martin Steigemann and Wolfgang Bangerth
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include <QtGui>
+
+#include "settings_dialog.h"
+
+
+namespace dealii
+{
+ namespace ParameterGui
+ {
+ SettingsDialog::SettingsDialog(QSettings *gui_settings,
+ QWidget *parent)
+ : QDialog(parent, 0)
+ {
+ setWindowTitle("Settings");
+
+ settings = gui_settings;
+ loadSettings();
+
+ QFormLayout * grid = new QFormLayout(this);
+
+ // add a choose font button
+ change_font = new QPushButton(this);
+ change_font->setText(QErrorMessage::tr("Change font"));
+ connect(change_font, SIGNAL(clicked()), this, SLOT(selectFont()));
+ grid->addRow("Change Font",change_font);
+
+ // add a checkbox
+ hide_default = new QCheckBox(this);
+ hide_default->setChecked(hide_default_values);
+ connect(hide_default, SIGNAL(stateChanged(int)), this, SLOT(changeHideDefault(int)));
+ grid->addRow("Hide default values",hide_default);
+
+ // add an OK button
+ ok = new QPushButton(this);
+ ok->setText(QErrorMessage::tr("&OK"));
+ connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
+
+ // add a Cancel button
+ cancel = new QPushButton(this);
+ cancel->setText(QErrorMessage::tr("&Cancel"));
+ connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
+ grid->addRow(ok,cancel);
+
+ connect(this, SIGNAL(accepted()), this, SLOT(writeSettings()));
+ }
+
+
+
+ void SettingsDialog::selectFont()
+ {
+ bool ok;
+ QFont new_font = QFontDialog::getFont(
+ &ok, selected_font, this);
+ if (ok) {
+ selected_font = new_font;
+ }
+ }
+
+
+
+ void SettingsDialog::changeHideDefault(int state)
+ {
+ hide_default_values = state;
+ }
+
+
+
+ void SettingsDialog::loadSettings()
+ {
+ settings->beginGroup("Settings");
+ hide_default_values = settings->value("hideDefault", false).toBool();
+
+ QString stored_font_string = settings->value("Font", QFont().toString()).toString();
+ selected_font.fromString(stored_font_string);
+ settings->endGroup();
+ }
+
+
+
+ void SettingsDialog::writeSettings()
+ {
+ settings->beginGroup("Settings");
+
+ settings->setValue("hideDefault", hide_default_values);
+ settings->setValue("Font", selected_font.toString());
+
+ settings->endGroup();
+ }
+ }
+}
+
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 by Martin Steigemann and Wolfgang Bangerth
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#ifndef SETTINGSDIALOG_H
+#define SETTINGSDIALOG_H
+
+#include <QDialog>
+#include <QSettings>
+#include <QCheckBox>
+
+
+namespace dealii
+{
+/*! @addtogroup ParameterGui
+ *@{
+ */
+ namespace ParameterGui
+ {
+/**
+ * The SettingsDialog class implements a settings dialog for the parameterGUI.
+ * The dialog shows all available settings, and when the user clicks on 'OK'
+ * stores them in the QSettings object handed over in the constructor (which
+ * in turn stores them on disk to allow persistent settings).
+ *
+ * @ingroup ParameterGui
+ * @author Rene Gassmoeller, 2017
+ */
+ class SettingsDialog : public QDialog
+ {
+ Q_OBJECT
+
+ public:
+ /**
+ * Constructor
+ */
+ SettingsDialog (QSettings *settings,
+ QWidget *parent = 0);
+
+ public slots:
+ /**
+ * Function that displays a font selection dialog and stores the result.
+ */
+ void selectFont();
+
+ /**
+ * Function that stores the checked state of the "Hide default" checkbox.
+ */
+ void changeHideDefault(int state);
+
+ /**
+ * Function that stores the new settings in the settings object
+ * (i.e. on disk).
+ */
+ void writeSettings();
+
+ /**
+ * Function that loads the settings from the settings file.
+ */
+ void loadSettings();
+
+ private:
+ /**
+ * This variable stores if the default values should be hidden. This
+ * might seem duplicative, since it is also stored in <tt>settings</tt>,
+ * but this variable stores the 'current' state of the checkbox,
+ * while <tt>settings</tt> is only updated after clicking OK.
+ */
+ bool hide_default_values;
+
+ /**
+ * The selected font as shown in the Change Font dialog.
+ */
+ QFont selected_font;
+
+ /**
+ * The <tt>Ok</tt> button.
+ */
+ QPushButton * ok;
+
+ /**
+ * The <tt>Cancel</tt> button.
+ */
+ QPushButton * cancel;
+
+ /**
+ * The <tt>Change font</tt> button.
+ */
+ QPushButton * change_font;
+
+ /**
+ * The checkbox<tt>Hide default values</tt>.
+ */
+ QCheckBox * hide_default;
+
+ /**
+ * An object for storing <tt>settings</tt> in a file.
+ */
+ QSettings * settings;
+ };
+ }
+/**@}*/
+}
+
+
+#endif