├── CMakeLists.txt ├── README.md ├── application.qrc ├── browse_lineedit.cpp ├── browse_lineedit.h ├── dealii_parameter_gui.pro ├── images ├── logo_dealii.png ├── logo_dealii_64.png ├── logo_dealii_gui.png └── logo_dealii_gui_128.png ├── info_message.cpp ├── info_message.h ├── lgpl-2.1.txt ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── parameter_delegate.cpp ├── parameter_delegate.h ├── parameter_gui.png ├── parameters.xml ├── prm_parameter_writer.cpp ├── prm_parameter_writer.h ├── settings_dialog.cpp ├── settings_dialog.h ├── xml_parameter_reader.cpp ├── xml_parameter_reader.h ├── xml_parameter_writer.cpp └── xml_parameter_writer.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## --------------------------------------------------------------------- 2 | ## 3 | ## Copyright (C) 2012 - 2016 by Martin Steigemann and Wolfgang Bangerth 4 | ## 5 | ## This file is part of the deal.II library. 6 | ## 7 | ## The deal.II library is free software; you can use it, redistribute 8 | ## it, and/or modify it under the terms of the GNU Lesser General 9 | ## Public License as published by the Free Software Foundation; either 10 | ## version 2.1 of the License, or (at your option) any later version. 11 | ## The full text of the license can be found in the file LICENSE at 12 | ## the top level of the deal.II distribution. 13 | ## 14 | ## --------------------------------------------------------------------- 15 | 16 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 17 | PROJECT(parameter_gui) 18 | 19 | IF("${DEAL_II_EXECUTABLE_RELDIR}" STREQUAL "") 20 | SET(DEAL_II_EXECUTABLE_RELDIR "bin") 21 | ENDIF() 22 | 23 | FIND_PACKAGE(Qt5 QUIET COMPONENTS Core Gui Xml Widgets) 24 | 25 | IF(${Qt5_FOUND}) 26 | ELSE() 27 | FIND_PACKAGE(Qt4 REQUIRED QtCore QtGui QtXml) 28 | INCLUDE(${QT_USE_FILE}) 29 | ENDIF() 30 | 31 | MARK_AS_ADVANCED(QT_QMAKE_EXECUTABLE) 32 | 33 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) 34 | 35 | IF(${Qt5_FOUND}) 36 | QT5_WRAP_CPP(SOURCE_MOC 37 | browse_lineedit.h 38 | info_message.h 39 | settings_dialog.h 40 | mainwindow.h 41 | parameter_delegate.h 42 | ) 43 | 44 | QT5_ADD_RESOURCES(SOURCE_RCC 45 | application.qrc 46 | ) 47 | ELSE() 48 | QT4_WRAP_CPP(SOURCE_MOC 49 | browse_lineedit.h 50 | info_message.h 51 | settings_dialog.h 52 | mainwindow.h 53 | parameter_delegate.h 54 | ) 55 | 56 | QT4_ADD_RESOURCES(SOURCE_RCC 57 | application.qrc 58 | ) 59 | ENDIF() 60 | 61 | 62 | ADD_EXECUTABLE(parameter_gui_exe 63 | browse_lineedit.cpp 64 | info_message.cpp 65 | settings_dialog.cpp 66 | main.cpp 67 | mainwindow.cpp 68 | parameter_delegate.cpp 69 | xml_parameter_reader.cpp 70 | xml_parameter_writer.cpp 71 | prm_parameter_writer.cpp 72 | ${SOURCE_MOC} 73 | ${SOURCE_RCC} 74 | ) 75 | SET_TARGET_PROPERTIES(parameter_gui_exe 76 | PROPERTIES 77 | OUTPUT_NAME parameter_gui 78 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DEAL_II_EXECUTABLE_RELDIR}" 79 | ) 80 | TARGET_LINK_LIBRARIES(parameter_gui_exe ${QT_LIBRARIES}) 81 | 82 | INSTALL(TARGETS parameter_gui_exe 83 | RUNTIME DESTINATION ${DEAL_II_EXECUTABLE_RELDIR} 84 | COMPONENT parameter_gui 85 | ) 86 | EXPORT(TARGETS parameter_gui_exe 87 | FILE 88 | ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}/${DEAL_II_PROJECT_CONFIG_NAME}Targets.cmake 89 | APPEND 90 | ) 91 | 92 | IF(${Qt5_FOUND}) 93 | QT5_USE_MODULES(parameter_gui_exe Core Gui Xml Widgets) 94 | ENDIF() 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This repository contains the parameter_gui project. 2 | 3 | It is copyrighted by Martin Steigemann and Wolfgang Bangerth and 4 | distributed under the same license as the deal.II library, i.e. The GNU 5 | Lesser General Public License (LGPL) version 2.1 or later. 6 | 7 | Requirements: 8 | ============= 9 | 10 | - CMake 11 | - Qt toolkit 12 | 13 | Usage: 14 | ====== 15 | 16 | To use the parameter GUI you first need to write a description of all the 17 | parameters, their default values, patterns and documentation strings into a 18 | file in a format that the GUI can understand; this is done using the 19 | ParameterHandler::print_parameters() function with ParameterHandler::XML as 20 | second argument, as discussed in more detail below in the Representation 21 | of Parameters section. This file can then be loaded using the 22 | executable of this GUI. 23 | 24 | Once loaded, the GUI displays subsections and individual parameters in tree 25 | form (see also the discussion in the Representation of Parameters 26 | section below). Here is a screen shot with some sub-sections expanded and 27 | one parameter selected for editing: 28 | 29 | ![Paremeter GUI](parameter_gui.png) 30 | 31 | Using the GUI, you can edit the values of individual parameters and save 32 | the result in the same format as before. It can then be read in using the 33 | ParameterHandler::read_input_from_xml() function. 34 | -------------------------------------------------------------------------------- /application.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/logo_dealii_64.png 4 | images/logo_dealii_gui.png 5 | images/logo_dealii_gui_128.png 6 | 7 | 8 | -------------------------------------------------------------------------------- /browse_lineedit.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | #include "browse_lineedit.h" 17 | 18 | #include 19 | 20 | namespace dealii 21 | { 22 | namespace ParameterGui 23 | { 24 | BrowseLineEdit::BrowseLineEdit(const BrowseType type, QWidget *parent) 25 | : QFrame(parent, 0), 26 | browse_type(type) 27 | { 28 | line_editor = new QLineEdit; 29 | connect(line_editor, SIGNAL(editingFinished()), this, SLOT(editing_finished())); 30 | 31 | browse_button = new QPushButton("&Browse..."); 32 | connect(browse_button, SIGNAL(clicked()), this, SLOT(browse())); 33 | 34 | setFocusPolicy (Qt::StrongFocus); 35 | 36 | QHBoxLayout *layout = new QHBoxLayout; 37 | 38 | layout->setContentsMargins(1,1,1,1); 39 | layout->addWidget(line_editor); 40 | layout->addWidget(browse_button); 41 | setLayout(layout); 42 | 43 | setAutoFillBackground(true); 44 | setBackgroundRole(QPalette::Highlight); 45 | } 46 | 47 | 48 | 49 | 50 | QSize BrowseLineEdit::sizeHint() const 51 | { 52 | QSize size_line_editor = line_editor->sizeHint(), 53 | size_browse_button = browse_button->sizeHint(); 54 | 55 | int w = size_line_editor.rwidth() + size_browse_button.rwidth(), 56 | h = qMax(size_line_editor.rheight(), size_browse_button.rheight()); 57 | 58 | return QSize (w, h); 59 | } 60 | 61 | 62 | 63 | QSize BrowseLineEdit::minimumSizeHint() const 64 | { 65 | QSize size_line_editor = line_editor->minimumSizeHint(), 66 | size_browse_button = browse_button->minimumSizeHint(); 67 | 68 | int w = size_line_editor.rwidth() + size_browse_button.rwidth(), 69 | h = qMax(size_line_editor.rheight(), size_browse_button.rheight()); 70 | 71 | return QSize (w, h); 72 | } 73 | 74 | 75 | 76 | QString BrowseLineEdit::text() const 77 | { 78 | return line_editor->text(); 79 | } 80 | 81 | 82 | 83 | void BrowseLineEdit::setText(const QString &str) 84 | { 85 | line_editor->setText(str); 86 | } 87 | 88 | 89 | 90 | void BrowseLineEdit::editing_finished() 91 | { 92 | emit editingFinished(); 93 | } 94 | 95 | 96 | 97 | void BrowseLineEdit::browse() 98 | { 99 | QString name = ""; 100 | 101 | switch (browse_type) 102 | { 103 | case file: 104 | { 105 | name = QFileDialog::getOpenFileName(this, tr("Open File"), 106 | QDir::currentPath(), 107 | tr("All Files (*.*)")); 108 | break; 109 | }; 110 | 111 | case files: 112 | { 113 | QStringList names = QFileDialog::getOpenFileNames(this, tr("Open Files"), 114 | QDir::currentPath(), 115 | tr("All Files (*.*)")); 116 | name = names.join(","); 117 | break; 118 | }; 119 | 120 | case directory: 121 | { 122 | name = QFileDialog::getExistingDirectory(this, tr("Open Directory"), 123 | QDir::homePath(), 124 | QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); 125 | break; 126 | }; 127 | }; 128 | 129 | if (!name.isEmpty() && !name.isNull()) 130 | line_editor->setText(name); 131 | } 132 | } 133 | } 134 | 135 | -------------------------------------------------------------------------------- /browse_lineedit.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #ifndef BROWSELINEEDIT_H 18 | #define BROWSELINEEDIT_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | namespace dealii 27 | { 28 | /*! @addtogroup ParameterGui 29 | *@{ 30 | */ 31 | namespace ParameterGui 32 | { 33 | /** 34 | * The BrowseLineEdit class provides a special line editor for the parameterGUI. 35 | * While editing file- or directory names it is much more easier to have a file-dialog 36 | * and just click on existing files or directories. This editor provides a simple QLineEditor 37 | * and a browse-button which opens a file- or a directory dialog. Clicking on existing files or directories 38 | * copies the path to the line editor. Depending on the BrowseType given in the constructor 39 | * the browse button opens a file or a directory dialog. 40 | * 41 | * @note This class is used in the graphical user interface for the @ref ParameterHandler class. 42 | * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. 43 | * 44 | * @ingroup ParameterGui 45 | * @author Martin Steigemann, Wolfgang Bangerth, 2010 46 | */ 47 | class BrowseLineEdit : public QFrame 48 | { 49 | Q_OBJECT 50 | 51 | public: 52 | /** 53 | * The browse button opens a file or 54 | * a directory dialog. This can be specified 55 | * in the constructor by setting this flag BrowseType. 56 | */ 57 | enum BrowseType {file = 0, directory = 1, files = 2}; 58 | 59 | /** 60 | * Constructor. The type of the browse dialog can be specified 61 | * by the flag BrowseType, the default is file. 62 | */ 63 | BrowseLineEdit (const BrowseType type = file, 64 | QWidget *parent = 0); 65 | 66 | /** 67 | * Reimplemented from the QWidget class. 68 | * Returns the size of the editor. 69 | */ 70 | QSize sizeHint() const; 71 | 72 | /** 73 | * Reimplemented from the QWidget class. 74 | */ 75 | QSize minimumSizeHint() const; 76 | 77 | /** 78 | * Returns the text of the line editor. 79 | */ 80 | QString text() const; 81 | 82 | /** 83 | * This pattern stores the type of the browse dialog. 84 | */ 85 | BrowseType browse_type; 86 | 87 | public slots: 88 | /** 89 | * A slot to set @p str as text of the line editor. 90 | */ 91 | void setText(const QString &str); 92 | 93 | signals: 94 | /** 95 | * This signal will be emitted, if editing is finished. 96 | */ 97 | void editingFinished(); 98 | 99 | private slots: 100 | /** 101 | * This slot should be always called, if editing is finished. 102 | */ 103 | void editing_finished(); 104 | 105 | /** 106 | * This function opens a file- or a directory dialog as specified in the 107 | * constructor. 108 | */ 109 | void browse(); 110 | 111 | private: 112 | /** 113 | * The line editor. 114 | */ 115 | QLineEdit *line_editor; 116 | 117 | /** 118 | * The browse button. 119 | */ 120 | QPushButton *browse_button; 121 | }; 122 | } 123 | /**@}*/ 124 | } 125 | 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /dealii_parameter_gui.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (2.01a) So. Dez 12 15:30:12 2010 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = 7 | DEPENDPATH += . 8 | INCLUDEPATH += . 9 | DESTDIR = ../../lib/bin 10 | 11 | # Input 12 | HEADERS += browse_lineedit.h \ 13 | info_message.h \ 14 | settings_dialog.h \ 15 | mainwindow.h \ 16 | parameter_delegate.h \ 17 | xml_parameter_reader.h \ 18 | xml_parameter_writer.h \ 19 | prm_parameter_writer.h 20 | SOURCES += browse_lineedit.cpp \ 21 | info_message.cpp \ 22 | settings_dialog.cpp \ 23 | main.cpp \ 24 | mainwindow.cpp \ 25 | parameter_delegate.cpp \ 26 | xml_parameter_reader.cpp \ 27 | xml_parameter_writer.cpp \ 28 | prm_parameter_writer.cpp 29 | RESOURCES += application.qrc 30 | -------------------------------------------------------------------------------- /images/logo_dealii.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dealii/parameter_gui/b7c0251b57dfbcc3fe873b25a6eb604a11a63e1d/images/logo_dealii.png -------------------------------------------------------------------------------- /images/logo_dealii_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dealii/parameter_gui/b7c0251b57dfbcc3fe873b25a6eb604a11a63e1d/images/logo_dealii_64.png -------------------------------------------------------------------------------- /images/logo_dealii_gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dealii/parameter_gui/b7c0251b57dfbcc3fe873b25a6eb604a11a63e1d/images/logo_dealii_gui.png -------------------------------------------------------------------------------- /images/logo_dealii_gui_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dealii/parameter_gui/b7c0251b57dfbcc3fe873b25a6eb604a11a63e1d/images/logo_dealii_gui_128.png -------------------------------------------------------------------------------- /info_message.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #include "info_message.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace dealii 26 | { 27 | namespace ParameterGui 28 | { 29 | InfoMessage::InfoMessage(QSettings *parent_settings, 30 | QWidget *parent) 31 | : QDialog(parent, 0) 32 | { 33 | // this variable stores, if the 34 | // the info message should be shown again 35 | show_again = true; 36 | QGridLayout * grid = new QGridLayout(this); 37 | 38 | // set an icon 39 | icon = new QLabel(this); 40 | #ifndef QT_NO_MESSAGEBOX 41 | icon->setPixmap(QMessageBox::standardIcon(QMessageBox::Information)); 42 | icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop); 43 | #endif 44 | // add the icon in the upper left corner 45 | grid->addWidget(icon, 0, 0, Qt::AlignTop); 46 | 47 | // set the new message 48 | message = new QTextEdit(this); 49 | message->setReadOnly(true); 50 | 51 | // and add the message on the right 52 | grid->addWidget(message, 0, 1); 53 | 54 | // add a check box 55 | again = new QCheckBox(this); 56 | again->setChecked(true); 57 | again->setText(QErrorMessage::tr("&Show this message again")); 58 | grid->addWidget(again, 1, 1, Qt::AlignTop); 59 | 60 | // and finally a OK button 61 | ok = new QPushButton(this); 62 | ok->setText(QErrorMessage::tr("&OK")); 63 | #ifdef QT_SOFTKEYS_ENABLED 64 | // define the action for the button 65 | ok_action = new QAction(ok); 66 | ok_action->setSoftKeyRole(QAction::PositiveSoftKey); 67 | ok_action->setText(ok->text()); 68 | connect(ok_action, SIGNAL(triggered()), this, SLOT(accept())); 69 | addAction(ok_action); 70 | #endif 71 | connect(ok, SIGNAL(clicked()), this, SLOT(accept())); 72 | // and set the focus on the button 73 | ok->setFocus(); 74 | grid->addWidget(ok, 2, 0, 1, 2, Qt::AlignCenter); 75 | 76 | grid->setColumnStretch(1, 42); 77 | grid->setRowStretch(0, 42); 78 | 79 | settings = parent_settings; 80 | 81 | // we store settings of this class in the group infoMessage 82 | settings->beginGroup("infoMessage"); 83 | show_again = settings->value("showInformation", true).toBool(); 84 | settings->endGroup(); 85 | } 86 | 87 | 88 | 89 | void InfoMessage::setInfoMessage(const QString &message) 90 | { 91 | // set the message 92 | this->message->setText(message); 93 | } 94 | 95 | 96 | 97 | void InfoMessage::showMessage() 98 | { 99 | // and show the message 100 | if (show_again) 101 | show(); 102 | } 103 | 104 | 105 | 106 | void InfoMessage::done(int r) 107 | { 108 | // if the box is not checked, store this to settings 109 | if(!again->isChecked()) 110 | { 111 | settings->beginGroup("infoMessage"); 112 | settings->setValue("showInformation", false); 113 | settings->endGroup(); 114 | }; 115 | 116 | QDialog::done(r); 117 | } 118 | } 119 | } 120 | 121 | -------------------------------------------------------------------------------- /info_message.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #ifndef INFOMESSAGE_H 18 | #define INFOMESSAGE_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | namespace dealii 28 | { 29 | /*! @addtogroup ParameterGui 30 | *@{ 31 | */ 32 | namespace ParameterGui 33 | { 34 | /** 35 | * The InfoMessage class implements a special info message for the parameterGUI. 36 | * Besides showing a info message itself, the dialog shows a checkbox "Show this message again". 37 | * If the user unchecks this box, this is stored in the "settings.ini" file and will be reloaded 38 | * the next time the user opens the parameterGUI. The intention of such a info message is the following. 39 | * The user should have some information on how using the GUI "at hand" 40 | * such as "how to edit parameter values" for example. But after reading this message, the user knows 41 | * it and the message should not appear permanently. 42 | * 43 | * @note This class is used in the graphical user interface for the @ref ParameterHandler class. 44 | * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. 45 | * 46 | * @ingroup ParameterGui 47 | * @author Martin Steigemann, Wolfgang Bangerth, 2010 48 | */ 49 | class InfoMessage : public QDialog 50 | { 51 | Q_OBJECT 52 | 53 | public: 54 | /** 55 | * Constructor 56 | */ 57 | InfoMessage (QSettings *settings, 58 | QWidget *parent = 0); 59 | 60 | /** 61 | * With this function the @p message which will be shown in the 62 | * dialog can be set. 63 | */ 64 | void setInfoMessage(const QString &message); 65 | 66 | public slots: 67 | /** 68 | * Show the dialog with the message. 69 | */ 70 | void showMessage(); 71 | 72 | protected: 73 | /** 74 | * Reimplemented from QDialog. 75 | */ 76 | void done(int r); 77 | 78 | private: 79 | /** 80 | * This variable stores, if the message should be shown again the next time. 81 | */ 82 | bool show_again; 83 | 84 | /** 85 | * The Ok button. 86 | */ 87 | QPushButton *ok; 88 | 89 | /** 90 | * The checkboxShow this message again. 91 | */ 92 | QCheckBox *again; 93 | 94 | /** 95 | * The message editor. 96 | */ 97 | QTextEdit *message; 98 | 99 | /** 100 | * An icon for the dialog. 101 | */ 102 | QLabel *icon; 103 | 104 | #ifdef QT_SOFTKEYS_ENABLED 105 | /** 106 | * A action for pressing the Ok button. 107 | */ 108 | QAction *ok_action; 109 | #endif 110 | 111 | /** 112 | * An object for storing settings in a file. 113 | */ 114 | QSettings *settings; 115 | }; 116 | } 117 | /**@}*/ 118 | } 119 | 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /lgpl-2.1.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "mainwindow.h" 22 | 23 | /*! @addtogroup ParameterGui 24 | *@{ 25 | */ 26 | 27 | /** 28 | * Main function for the parameterGUI. 29 | * The parameterGUI is a graphical user interface for editing parameter files based on the XML format, 30 | * created by the ParameterHandler::print_parameters() function with ParameterHandler::XML as second argument. 31 | * 32 | * @image html logo_dealii_gui.png 33 | * 34 | * @note This class is used in the graphical user interface for the @ref ParameterHandler class. 35 | * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. 36 | * 37 | * 38 | *

This program uses Qt version > 4.3. Qt is licensed under the GNU General Public License 39 | * version 3.0. Please see http://qt.nokia.com/products/licensing for an overview of Qt licensing. 40 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). Qt is a Nokia product. 41 | * See http://qt.nokia.com/ for more information.

42 | * 43 | * 44 | * @ingroup ParameterGui 45 | * @author Martin Steigemann, Wolfgang Bangerth, 2010 46 | */ 47 | int main(int argc, char *argv[]) 48 | { 49 | // init resources such as icons or graphics 50 | Q_INIT_RESOURCE(application); 51 | 52 | QApplication app(argc, argv); 53 | 54 | // setup a splash screen 55 | QSplashScreen * splash = new QSplashScreen; 56 | splash->setPixmap(QPixmap(":/images/logo_dealii_gui.png")); 57 | splash->show(); 58 | 59 | // and close it after 3000 ms 60 | QTimer::singleShot(3000, splash, SLOT(close())); 61 | 62 | // setup the application name 63 | app.setApplicationName("parameterGUI for deal.II"); 64 | 65 | // give command line arguments to main_win 66 | // if a parameter file is specified at the 67 | // command line, give it to the MainWindow. 68 | dealii::ParameterGui::MainWindow * main_win = 69 | new dealii::ParameterGui::MainWindow (argv[1]); 70 | 71 | // show the main window with a short delay 72 | // so we can see the splash screen 73 | QTimer::singleShot(1500, main_win, SLOT(show())); 74 | 75 | return app.exec(); 76 | } 77 | /**@}*/ 78 | 79 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #include "mainwindow.h" 18 | #include "parameter_delegate.h" 19 | #include "xml_parameter_reader.h" 20 | #include "xml_parameter_writer.h" 21 | #include "prm_parameter_writer.h" 22 | 23 | #include 24 | #if QT_VERSION >= 0x050000 25 | #include 26 | #else 27 | #include 28 | #endif 29 | 30 | namespace dealii 31 | { 32 | namespace ParameterGui 33 | { 34 | MainWindow::MainWindow(const QString &filename) 35 | { 36 | // load settings 37 | gui_settings = new QSettings ("deal.II", "parameterGUI"); 38 | 39 | // tree for showing XML tags 40 | tree_widget = new QTreeWidget; 41 | 42 | // Setup the tree and the window first: 43 | #if QT_VERSION >= 0x050000 44 | tree_widget->header()->setSectionResizeMode(QHeaderView::ResizeToContents); 45 | #else 46 | tree_widget->header()->setResizeMode(QHeaderView::ResizeToContents); 47 | #endif 48 | tree_widget->setHeaderLabels(QStringList() << tr("(Sub)Sections/Parameters") 49 | << tr("Value")); 50 | 51 | // enables mouse events e.g. showing ToolTips 52 | // and documentation in the StatusLine 53 | tree_widget->setMouseTracking(true); 54 | tree_widget->setEditTriggers(QAbstractItemView::DoubleClicked| 55 | QAbstractItemView::SelectedClicked| 56 | QAbstractItemView::EditKeyPressed); 57 | 58 | //Enable right click menu in tree 59 | tree_widget->setContextMenuPolicy(Qt::ActionsContextMenu); 60 | context_menu = new QMenu(tree_widget); 61 | 62 | // set the delegate for editing items 63 | tree_widget->setItemDelegate(new ParameterDelegate(1)); 64 | 65 | setCentralWidget(tree_widget); 66 | 67 | connect(tree_widget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(set_documentation_text(QTreeWidgetItem *, QTreeWidgetItem *))); 68 | // connect: if the tree changes, the window will know 69 | connect(tree_widget, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(item_changed(QTreeWidgetItem *, int))); 70 | connect(tree_widget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(tree_was_modified())); 71 | 72 | QDockWidget *documentation_widget = new QDockWidget(tr("Parameter documentation:"), this); 73 | documentation_text_widget = new QTextEdit(QString (""), documentation_widget); 74 | documentation_text_widget->setReadOnly(true); 75 | 76 | documentation_widget->setAllowedAreas(Qt::AllDockWidgetAreas); 77 | documentation_widget->setWidget(documentation_text_widget); 78 | 79 | addDockWidget(Qt::BottomDockWidgetArea, documentation_widget); 80 | 81 | // create window actions as "Open",... 82 | create_actions(); 83 | // and menus 84 | create_menus(); 85 | // and the toolbar 86 | create_toolbar(); 87 | 88 | statusBar()->showMessage(tr("Ready, start editing by double-clicking or hitting F2!")); 89 | setWindowTitle(tr("[*]parameterGUI")); 90 | 91 | gui_settings->beginGroup("MainWindow"); 92 | resize(gui_settings->value("size", QSize(800, 600)).toSize()); 93 | move(gui_settings->value("pos", QPoint(0, 0)).toPoint()); 94 | gui_settings->endGroup(); 95 | 96 | // if there is a file_name, try to load the file. 97 | // a valid file has the xml extension, so we require size() > 3 98 | if (filename.size() > 3) 99 | load_file(filename); 100 | 101 | apply_settings(); 102 | } 103 | 104 | 105 | 106 | void MainWindow::set_documentation_text(QTreeWidgetItem *selected_item, 107 | QTreeWidgetItem *previous_item) 108 | { 109 | documentation_text_widget->clear(); 110 | documentation_text_widget->insertPlainText(selected_item->text(3)); 111 | } 112 | 113 | 114 | 115 | void MainWindow::item_changed(QTreeWidgetItem *item, 116 | int column) 117 | { 118 | if (column != 1) 119 | return; 120 | 121 | bool has_default_value; 122 | 123 | if (item->text(5).startsWith("[Double")) 124 | has_default_value = item->data(1,Qt::DisplayRole).toReal() == item->data(2,Qt::DisplayRole).toReal(); 125 | else 126 | has_default_value = item->data(1,Qt::DisplayRole).toString() == item->data(2,Qt::DisplayRole).toString(); 127 | 128 | if (has_default_value) 129 | { 130 | QFont font = item->font(1); 131 | font.setWeight(QFont::Normal); 132 | item->setFont(1,font); 133 | 134 | const bool hide_items_with_default_value = gui_settings->value("Settings/hideDefault", false).toBool(); 135 | if (hide_items_with_default_value) 136 | item->setHidden(true); 137 | } 138 | else 139 | { 140 | QFont font = item->font(1); 141 | font.setWeight(QFont::Bold); 142 | item->setFont(1,font); 143 | } 144 | } 145 | 146 | 147 | 148 | void MainWindow::set_to_default() 149 | { 150 | QTreeWidgetItem * current_item = tree_widget->currentItem(); 151 | current_item->setText(1,current_item->text(2)); 152 | } 153 | 154 | 155 | 156 | void MainWindow::open() 157 | { 158 | // check, if the content was modified 159 | if (maybe_save()) 160 | { 161 | // open a file dialog 162 | QString file_name = 163 | QFileDialog::getOpenFileName(this, tr("Open XML Parameter File"), 164 | QDir::currentPath(), 165 | tr("XML Files (*.xml)")); 166 | 167 | // if a file was selected, load the content 168 | if (!file_name.isEmpty()) 169 | load_file(file_name); 170 | } 171 | } 172 | 173 | 174 | 175 | bool MainWindow::save() 176 | { 177 | // if there is no file to save changes, open a dialog 178 | if (current_file.isEmpty()) 179 | return save_as(); 180 | else 181 | return save_file(current_file); 182 | } 183 | 184 | 185 | 186 | bool MainWindow::save_as() 187 | { 188 | const QString default_save_format = gui_settings->value("Settings/DefaultSaveFormat").toString(); 189 | 190 | QString filters; 191 | if (default_save_format == "prm") 192 | filters = tr("PRM Files (*.prm);;XML Files (*.xml)"); 193 | else 194 | filters = tr("XML Files (*.xml);;PRM Files (*.prm)"); 195 | 196 | // open a file dialog 197 | QString file_name = 198 | QFileDialog::getSaveFileName(this, tr("Save Parameter File"), 199 | QDir::currentPath() + QDir::separator() + current_file, 200 | filters); 201 | 202 | // return if a file was saved 203 | if (file_name.isEmpty()) 204 | return false; 205 | else 206 | return save_file(file_name); 207 | } 208 | 209 | 210 | 211 | void MainWindow::about() 212 | { 213 | #ifdef Q_WS_MAC 214 | static QPointer old_msg_box; 215 | 216 | if (old_msg_box) 217 | { 218 | old_msg_box->show(); 219 | old_msg_box->raise(); 220 | old_msg_box->activateWindow(); 221 | return; 222 | }; 223 | #endif 224 | 225 | QString title = "About parameterGUI"; 226 | 227 | QString trAboutparameterGUIcaption; 228 | trAboutparameterGUIcaption = QMessageBox::tr( 229 | "

parameterGUI: A GraphicalUserInterface for parameter handling in deal.II

" 230 | "

This program uses Qt version %1.

" 231 | ).arg(QLatin1String(QT_VERSION_STR)); 232 | 233 | QString trAboutparameterGUItext; 234 | trAboutparameterGUItext = QMessageBox::tr( 235 | "

The parameterGUI is a graphical user interface for editing XML parameter files " 236 | "created by the ParameterHandler class of deal.II. Please see " 237 | "dealii.org/doc for more information. " 238 | "The parameterGUI parses XML files into a tree structure and provides " 239 | " special editors for different types of parameters.

" 240 | 241 | "

Editing parameter values:
" 242 | "Parameters can be edited by (double-)clicking on the value or " 243 | "by pressing the platform edit key (F2 on Linux) over an parameter item.

" 244 | 245 | "

Editors for parameter values:
" 246 | "Editor fields are aware of the type of the parameter, and show reasonable " 247 | "input fields including (where possible) error checking." 248 | "

" 249 | 250 | "

Please see dealii.org for more information

" 251 | "

Authors:
" 252 | "Martin Steigemann, martin.steigemann@mathematik.uni-kassel.de
" 253 | "Rene Gassmoeller, rene.gassmoeller@mailbox.org
" 254 | "Wolfgang Bangerth, bangerth@colostate.edu
" 255 | "

" 256 | ); 257 | 258 | QMessageBox *msg_box = new QMessageBox; 259 | msg_box->setAttribute(Qt::WA_DeleteOnClose); 260 | msg_box->setWindowTitle(title); 261 | msg_box->setText(trAboutparameterGUIcaption); 262 | msg_box->setInformativeText(trAboutparameterGUItext); 263 | 264 | QPixmap pm(QLatin1String(":/images/logo_dealii_gui_128.png")); 265 | 266 | if (!pm.isNull()) 267 | msg_box->setIconPixmap(pm); 268 | 269 | #ifdef Q_WS_MAC 270 | old_msg_box = msg_box; 271 | msg_box->show(); 272 | #else 273 | msg_box->exec(); 274 | #endif 275 | } 276 | 277 | 278 | 279 | void MainWindow::tree_was_modified() 280 | { 281 | // store, that the window was modified 282 | // this is a function from the QMainWindow class 283 | // and we use the windowModified mechanism to show a "*" 284 | // in the window title, if content was modified 285 | setWindowModified(true); 286 | } 287 | 288 | 289 | 290 | void MainWindow::show_message () 291 | { 292 | QString title = "parameterGUI"; 293 | 294 | info_message = new InfoMessage(gui_settings,this); 295 | 296 | info_message->setWindowTitle(title); 297 | info_message->setInfoMessage(tr("Start Editing by double-clicking on the parameter value or" 298 | " by hitting the platform edit key. For example, on Linux this is the F2-key!")); 299 | info_message->showMessage(); 300 | } 301 | 302 | 303 | 304 | void MainWindow::show_settings () 305 | { 306 | settings_dialog = new SettingsDialog(gui_settings,this); 307 | 308 | connect(settings_dialog, SIGNAL(accepted()), this, SLOT(apply_settings())); 309 | settings_dialog->exec(); 310 | disconnect(settings_dialog, SIGNAL(accepted()), this, SLOT(apply_settings())); 311 | } 312 | 313 | 314 | 315 | void MainWindow::apply_settings () 316 | { 317 | update_visible_items(); 318 | update_font(); 319 | } 320 | 321 | 322 | 323 | void MainWindow::toggle_visible_default_items() 324 | { 325 | const bool hide_default_values = gui_settings->value("Settings/hideDefault", false).toBool(); 326 | gui_settings->setValue("Settings/hideDefault", !hide_default_values); 327 | update_visible_items(); 328 | } 329 | 330 | 331 | 332 | void MainWindow::update_visible_items() 333 | { 334 | const bool hide_default_values = gui_settings->value("Settings/hideDefault", false).toBool(); 335 | 336 | if (hide_default_values) 337 | { 338 | for (int i = 0; i < tree_widget->topLevelItemCount(); ++i) 339 | hide_item_with_default_value(tree_widget->topLevelItem(i)); 340 | hide_default->setChecked(true); 341 | } 342 | else 343 | { 344 | QTreeWidgetItemIterator it(tree_widget,QTreeWidgetItemIterator::Hidden); 345 | while (*it) 346 | { 347 | (*it)->setHidden(false); 348 | ++it; 349 | } 350 | hide_default->setChecked(false); 351 | } 352 | } 353 | 354 | 355 | 356 | bool MainWindow::hide_item_with_default_value(QTreeWidgetItem *item) 357 | { 358 | bool has_default_value = true; 359 | 360 | if (item->childCount() == 0) 361 | { 362 | if (item->text(5).startsWith("[Double")) 363 | has_default_value = item->data(1,Qt::DisplayRole).toReal() == item->data(2,Qt::DisplayRole).toReal(); 364 | else 365 | has_default_value = item->data(1,Qt::DisplayRole).toString() == item->data(2,Qt::DisplayRole).toString(); 366 | } 367 | else 368 | { 369 | // If this element has children recurse into them and check for default values 370 | for (int i = 0; i < item->childCount(); ++i) 371 | { 372 | const bool child_has_default_value = hide_item_with_default_value(item->child(i)); 373 | has_default_value = has_default_value & child_has_default_value; 374 | } 375 | } 376 | 377 | if (has_default_value) 378 | item->setHidden(true); 379 | 380 | return has_default_value; 381 | } 382 | 383 | 384 | 385 | void MainWindow::closeEvent(QCloseEvent *event) 386 | { 387 | // Reimplement the closeEvent from the QMainWindow class. 388 | // First check, if we have to save modified content. 389 | // If not, or the content was saved, accept the event, otherwise ignore it 390 | if (maybe_save()) 391 | { 392 | gui_settings->beginGroup("MainWindow"); 393 | gui_settings->setValue("size", size()); 394 | gui_settings->setValue("pos", pos()); 395 | gui_settings->endGroup(); 396 | 397 | event->accept(); 398 | } 399 | else 400 | event->ignore(); 401 | } 402 | 403 | 404 | 405 | void MainWindow::create_actions() 406 | { 407 | QStyle * style = tree_widget->style(); 408 | 409 | // Create actions, and set icons, shortcuts, status tip and connect to 410 | // activate the action. 411 | open_act = new QAction(tr("&Open..."), this); 412 | open_act->setIcon(style->standardPixmap(QStyle::SP_DialogOpenButton)); 413 | open_act->setShortcut(Qt::CTRL + Qt::Key_O); 414 | open_act->setStatusTip(tr("Open a XML file")); 415 | connect(open_act, SIGNAL(triggered()), this, SLOT(open())); 416 | 417 | save_act = new QAction(tr("&Save ..."), this); 418 | save_act->setIcon(style->standardPixmap(QStyle::SP_DialogSaveButton)); 419 | save_act->setShortcut(Qt::CTRL + Qt::Key_S); 420 | save_act->setStatusTip(tr("Save the current XML file")); 421 | connect(save_act, SIGNAL(triggered()), this, SLOT(save())); 422 | 423 | save_as_act = new QAction(tr("&Save As..."), this); 424 | save_as_act->setIcon(style->standardPixmap(QStyle::SP_DialogSaveButton)); 425 | save_as_act->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Q); 426 | save_as_act->setStatusTip(tr("Save the current XML file as")); 427 | connect(save_as_act, SIGNAL(triggered()), this, SLOT(save_as())); 428 | 429 | exit_act = new QAction(tr("E&xit"), this); 430 | exit_act->setIcon(style->standardPixmap(QStyle::SP_DialogCloseButton)); 431 | exit_act->setShortcut(Qt::CTRL + Qt::Key_Q); 432 | exit_act->setStatusTip(tr("Exit the parameterGUI application")); 433 | connect(exit_act, SIGNAL(triggered()), this, SLOT(close())); 434 | 435 | about_act = new QAction(tr("&About"), this); 436 | about_act->setIcon(style->standardPixmap(QStyle::SP_FileDialogInfoView)); 437 | about_act->setStatusTip(tr("Show the parameterGUI About box")); 438 | connect(about_act, SIGNAL(triggered()), this, SLOT(about())); 439 | 440 | about_qt_act = new QAction(tr("About &Qt"), this); 441 | about_qt_act->setStatusTip(tr("Show the Qt library's About box")); 442 | connect(about_qt_act, SIGNAL(triggered()), qApp, SLOT(aboutQt())); 443 | 444 | settings_act = new QAction(tr("Settings"), this); 445 | settings_act->setStatusTip(tr("Show the Settings Dialog")); 446 | connect(settings_act, SIGNAL(triggered()), this, SLOT(show_settings())); 447 | 448 | set_to_default_act = new QAction("Set to default",context_menu); 449 | tree_widget->addAction(set_to_default_act); 450 | connect(set_to_default_act, SIGNAL(triggered()), this, SLOT(set_to_default())); 451 | } 452 | 453 | 454 | 455 | void MainWindow::create_menus() 456 | { 457 | // create a file menu, and add the entries 458 | file_menu = menuBar()->addMenu(tr("&File")); 459 | file_menu->addAction(open_act); 460 | file_menu->addAction(save_act); 461 | file_menu->addAction(save_as_act); 462 | file_menu->addSeparator(); 463 | file_menu->addAction(settings_act); 464 | file_menu->addSeparator(); 465 | file_menu->addAction(exit_act); 466 | 467 | menuBar()->addSeparator(); 468 | 469 | // create a help menu 470 | help_menu = menuBar()->addMenu(tr("&Help")); 471 | help_menu->addAction(about_act); 472 | help_menu->addAction(about_qt_act); 473 | } 474 | 475 | 476 | 477 | void MainWindow::create_toolbar() 478 | { 479 | QToolBar *toolbar = new QToolBar(tr("Toolbar"),this); 480 | 481 | // add entries 482 | toolbar->addAction(open_act); 483 | toolbar->addAction(save_act); 484 | toolbar->addAction(save_as_act); 485 | 486 | toolbar->addSeparator(); 487 | 488 | hide_default = new QToolButton(toolbar); 489 | hide_default->setText(tr("Hide default values")); 490 | hide_default->setCheckable(true); 491 | connect(hide_default, SIGNAL(clicked()), this, SLOT(toggle_visible_default_items())); 492 | QAction *hide_default_act = toolbar->addWidget(hide_default); 493 | 494 | QToolButton *change_font = new QToolButton(toolbar); 495 | change_font->setText(tr("Change font")); 496 | connect(change_font, SIGNAL(clicked()), this, SLOT(select_font())); 497 | QAction *change_font_act = toolbar->addWidget(change_font); 498 | 499 | addToolBar(toolbar); 500 | } 501 | 502 | 503 | 504 | bool MainWindow::maybe_save() 505 | { 506 | // if content was modified, ask if content should be saved 507 | if (isWindowModified()) 508 | { 509 | QMessageBox::StandardButton ret; 510 | ret = QMessageBox::warning(this, tr("parameterGUI"), 511 | tr("The content has been modified.\n" 512 | "Do you want to save your changes?"), 513 | QMessageBox::Save | QMessageBox::Discard |QMessageBox::Cancel); 514 | 515 | if (ret == QMessageBox::Save) 516 | return save(); 517 | else if (ret == QMessageBox::Cancel) 518 | return false; 519 | }; 520 | 521 | return true; 522 | } 523 | 524 | 525 | 526 | bool MainWindow::save_file(const QString &filename) 527 | { 528 | QFile file(filename); 529 | 530 | // open a file dialog 531 | if (!file.open(QFile::WriteOnly | QFile::Text)) 532 | { 533 | QMessageBox::warning(this, tr("parameterGUI"), 534 | tr("Cannot write file %1:\n%2.") 535 | .arg(filename) 536 | .arg(file.errorString())); 537 | return false; 538 | }; 539 | 540 | if (filename.endsWith(".xml",Qt::CaseInsensitive)) 541 | { 542 | // create a xml writer and write the xml file 543 | XMLParameterWriter writer(tree_widget); 544 | if (!writer.write_xml_file(&file)) 545 | return false; 546 | 547 | gui_settings->setValue("Settings/DefaultSaveFormat", "xml"); 548 | } 549 | else if (filename.endsWith(".prm",Qt::CaseInsensitive)) 550 | { 551 | // create a prm writer and write the prm file 552 | PRMParameterWriter writer(tree_widget); 553 | if (!writer.write_prm_file(&file)) 554 | return false; 555 | 556 | gui_settings->setValue("Settings/DefaultSaveFormat", "prm"); 557 | } 558 | else 559 | { 560 | QMessageBox::warning(this, tr("parameterGUI"), 561 | tr("Unknown output format: %1.") 562 | .arg(filename)); 563 | file.remove(); 564 | 565 | return false; 566 | } 567 | 568 | // if we succeed, show a message and reset the window 569 | statusBar()->showMessage(tr("File saved"), 2000); 570 | set_current_file(filename); 571 | 572 | return true; 573 | } 574 | 575 | 576 | 577 | void MainWindow::load_file(const QString &filename) 578 | { 579 | QFile file(filename); 580 | 581 | // open the file 582 | if (!file.open(QFile::ReadOnly | QFile::Text)) 583 | { 584 | QMessageBox::warning(this, tr("parameterGUI"), 585 | tr("Cannot read file %1:\n%2.") 586 | .arg(filename) 587 | .arg(file.errorString())); 588 | return; 589 | }; 590 | 591 | // clear the tree and read the xml file 592 | tree_widget->clear(); 593 | XMLParameterReader xml_reader(tree_widget); 594 | 595 | if (!xml_reader.read_xml_file(&file)) 596 | { 597 | QMessageBox::warning(this, tr("parameterGUI"), 598 | tr("Parse error in file %1:\n\n%2") 599 | .arg(filename) 600 | .arg(xml_reader.error_string())); 601 | } 602 | else 603 | { 604 | // show a message and set current file 605 | statusBar()->showMessage(tr("File loaded - Start editing by double-clicking or hitting F2"), 25000); 606 | set_current_file(filename); 607 | 608 | // show some informations how values can be edited 609 | show_message (); 610 | }; 611 | } 612 | 613 | 614 | 615 | void MainWindow::set_current_file(const QString &filename) 616 | { 617 | // We use the windowModified mechanism from the 618 | // QMainWindow class to indicate in the window title, 619 | // if the content was modified. 620 | // If there is "[*]" in the window title, a * will 621 | // added automatically at this position, if the 622 | // window was modified. 623 | // We set the window title to 624 | // file_name[*] - XMLParameterHandler 625 | 626 | // set the (global) current file to file_name 627 | current_file = filename; 628 | 629 | // and create the window title, 630 | std::string win_title = (filename.toStdString()); 631 | 632 | // if file_name is empty set the title to our application name 633 | if (current_file.isEmpty()) 634 | win_title = "[*]parameterGUI"; 635 | else 636 | { 637 | // if there is a file_name, add the 638 | // the file_name and a minus to the title 639 | win_title += "[*] - parameterGUI"; 640 | } 641 | 642 | // set the window title and reset window modified 643 | setWindowTitle(tr(win_title.c_str())); 644 | setWindowModified(false); 645 | } 646 | 647 | 648 | 649 | void MainWindow::update_font() 650 | { 651 | QString current_font_string = gui_settings->value("Settings/Font", QFont().toString()).toString(); 652 | QFont current_font; 653 | current_font.fromString(current_font_string); 654 | setFont(current_font); 655 | } 656 | 657 | 658 | 659 | void MainWindow::select_font() 660 | { 661 | QString current_font_string = gui_settings->value("Settings/Font", QFont().toString()).toString(); 662 | QFont current_font; 663 | current_font.fromString(current_font_string); 664 | 665 | bool ok; 666 | QFont new_font = QFontDialog::getFont( 667 | &ok, current_font, this); 668 | if (ok) { 669 | gui_settings->setValue("Settings/Font", new_font.toString()); 670 | setFont(new_font); 671 | } 672 | } 673 | } 674 | } 675 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #ifndef MAINWINDOW_H 18 | #define MAINWINDOW_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "info_message.h" 28 | #include "settings_dialog.h" 29 | 30 | 31 | namespace dealii 32 | { 33 | /*! @addtogroup ParameterGui 34 | *@{ 35 | */ 36 | namespace ParameterGui 37 | { 38 | /** 39 | * The MainWindow class of the the parameterGUI. 40 | * The parameterGUI is a graphical user interface for editing parameter files based on the XML format, 41 | * created by the @ref ParameterHandler::print_parameters() function with @ref ParameterHandler::XML as second argument. 42 | * Please see Representation of Parameters in the documentation of the @ref ParameterHandler class for more details. 43 | * The MainWindow class provides the basic functionality of the GUI as save- and load-file-actions and documentation. 44 | * The parameterGUI provides special editors for the different types of parameters defined in the ParameterHandler class. 45 | * 46 | * @note This class is used in the graphical user interface for the @ref ParameterHandler class. 47 | * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. 48 | * 49 | * @ingroup ParameterGui 50 | * @author Martin Steigemann, Wolfgang Bangerth, 2010 51 | */ 52 | class MainWindow : public QMainWindow 53 | { 54 | Q_OBJECT 55 | 56 | public: 57 | /** 58 | * Constructor. 59 | * If a @p filename is given, 60 | * the MainWindow tries to open 61 | * and parse the file. 62 | */ 63 | MainWindow(const QString &filename = ""); 64 | 65 | protected: 66 | /** 67 | * Reimplemented from QMainWindow. 68 | * We ask, if changes should be saved. 69 | */ 70 | void closeEvent(QCloseEvent *event); 71 | 72 | private slots: 73 | 74 | /** 75 | * Open a parameter file. 76 | */ 77 | void open(); 78 | 79 | /** 80 | * Save the parameter file. 81 | */ 82 | bool save(); 83 | 84 | /** 85 | * Open a file dialog to save the parameter file. 86 | */ 87 | bool save_as(); 88 | 89 | /** 90 | * Show some information on the parameterGUI 91 | */ 92 | void about(); 93 | 94 | /** 95 | * A slot that should be always called, 96 | * if parameter values were changed. 97 | */ 98 | void tree_was_modified(); 99 | 100 | /** 101 | * A slot that is called when the active 102 | * item has changed. It updates the documentation 103 | * text in the documentation panel. 104 | */ 105 | void set_documentation_text(QTreeWidgetItem *selected_item, 106 | QTreeWidgetItem *previous_item); 107 | 108 | /** 109 | * A slot that is called when the active 110 | * tree item should be set to its default value. 111 | */ 112 | void set_to_default(); 113 | 114 | /** 115 | * A slot that is called when any 116 | * item value has changed. It updates the font depending 117 | * on whether the item has a default value or not. 118 | */ 119 | void item_changed(QTreeWidgetItem *item, 120 | int column); 121 | 122 | /** 123 | * Show an information dialog, how 124 | * parameters can be edited. 125 | */ 126 | void show_settings (); 127 | 128 | /** 129 | * Apply the new settings to this window. 130 | */ 131 | void apply_settings (); 132 | 133 | /** 134 | * Hide all default items in tree_widget if set in gui_settings. 135 | * Otherwise restores all default values. 136 | */ 137 | void update_visible_items(); 138 | 139 | /** 140 | * Reads the font from gui_settings and applies it. 141 | */ 142 | void update_font(); 143 | 144 | /** 145 | * Changes whether default items should be displayed in the tree widget 146 | * and calls update_visible_items() to apply the changes. 147 | */ 148 | void toggle_visible_default_items(); 149 | 150 | /** 151 | * Function that displays a font selection dialog, stores the result 152 | * in gui_settings, and displays the new font. 153 | */ 154 | void select_font(); 155 | private: 156 | /** 157 | * Show an information dialog, how 158 | * parameters can be edited. 159 | */ 160 | void show_message (); 161 | 162 | /** 163 | * This function creates all actions. 164 | */ 165 | void create_actions(); 166 | 167 | /** 168 | * This function creates all menus. 169 | */ 170 | void create_menus(); 171 | 172 | 173 | /** 174 | * This function creates the toolbar. 175 | */ 176 | void create_toolbar(); 177 | 178 | /** 179 | * This function checks, if parameters were changed 180 | * and show a dialog, if changes should be saved. 181 | * This function should be always called, 182 | * before open a new parameter file or before closing the GUI 183 | */ 184 | bool maybe_save (); 185 | 186 | /** 187 | * Save parameters to @p filename in XML format. 188 | */ 189 | bool save_file (const QString &filename); 190 | 191 | /** 192 | * Load parameters from @p filename in XML format. 193 | */ 194 | void load_file (const QString &filename); 195 | 196 | /** 197 | * This functions writes the current @p filename to the window title. 198 | */ 199 | void set_current_file (const QString &filename); 200 | 201 | /** 202 | * Determine if the item and all of its children have the default value, 203 | * and hide all default items. Returns true if the item and all of its 204 | * children have default values. 205 | */ 206 | bool hide_item_with_default_value(QTreeWidgetItem *item); 207 | 208 | /** 209 | * This is the tree structure in which we store all parameters. 210 | */ 211 | QTreeWidget *tree_widget; 212 | 213 | /** 214 | * This is the documentation text area. 215 | */ 216 | QTextEdit *documentation_text_widget; 217 | 218 | 219 | /** A tool button that allows to toggle between showing/hiding parameters 220 | * with default values. 221 | */ 222 | QToolButton *hide_default; 223 | 224 | /** 225 | * This menu provides all file actions as open, save, save as 226 | * and exit 227 | */ 228 | QMenu *file_menu; 229 | 230 | /** 231 | * This menu provides some informations about the parameterGUI 232 | * and about Qt 233 | */ 234 | QMenu *help_menu; 235 | 236 | /** 237 | * This menu provides context menu options for the active tree item. 238 | */ 239 | QMenu *context_menu; 240 | 241 | /** 242 | * QAction open a file. 243 | */ 244 | QAction *open_act; 245 | 246 | /** 247 | * QAction save a file. 248 | */ 249 | QAction *save_act; 250 | 251 | /** 252 | * QAction save as a file. 253 | */ 254 | QAction *save_as_act; 255 | 256 | /** 257 | * QAction save as a file. 258 | */ 259 | QAction *settings_act; 260 | 261 | /** 262 | * QAction exit the GUI. 263 | */ 264 | QAction *exit_act; 265 | 266 | /** 267 | * QAction about the parameterGUI. 268 | */ 269 | QAction *about_act; 270 | 271 | /** 272 | * QAction about Qt. 273 | */ 274 | QAction *about_qt_act; 275 | 276 | /** 277 | * QAction set_to_default. 278 | */ 279 | QAction *set_to_default_act; 280 | 281 | /** 282 | * This value stores the current filename we work on. 283 | */ 284 | QString current_file; 285 | 286 | /** 287 | * This dialog shows a short information message after loading a file. 288 | */ 289 | InfoMessage *info_message; 290 | 291 | /** 292 | * This dialog shows the available settings. 293 | */ 294 | SettingsDialog *settings_dialog; 295 | 296 | /** 297 | * An object for storing user settings. 298 | */ 299 | QSettings *gui_settings; 300 | }; 301 | } 302 | /**@}*/ 303 | } 304 | 305 | 306 | #endif 307 | -------------------------------------------------------------------------------- /parameter_delegate.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #include "parameter_delegate.h" 18 | 19 | #include 20 | 21 | namespace dealii 22 | { 23 | namespace ParameterGui 24 | { 25 | ParameterDelegate::ParameterDelegate(const int value_column, QObject *parent) 26 | : QItemDelegate(parent) 27 | { 28 | this->value_column = value_column; 29 | } 30 | 31 | 32 | 33 | QSize ParameterDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const 34 | { 35 | if (index.column() == value_column) 36 | { 37 | // we increase the height of all lines to show editors 38 | return QSize(400,30); 39 | 40 | /* 41 | QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description 42 | // stored in the StatusLine 43 | QRegExp rx_string("\\b(FileName|DirectoryName)\\b"); 44 | 45 | if (rx_string.indexIn (pattern_description) != -1) 46 | { 47 | return QSize(400,35); // we increase the height for FileName and 48 | } // DirectoryName to show a "browse" button 49 | else 50 | return QItemDelegate::sizeHint(option, index); 51 | */ 52 | 53 | } 54 | else 55 | return QItemDelegate::sizeHint(option, index); 56 | } 57 | 58 | 59 | 60 | void ParameterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const 61 | { 62 | if (index.column() == value_column) 63 | { 64 | // load pattern description stored in the StatusLine 65 | QString pattern_description = index.data(Qt::StatusTipRole).toString(); 66 | 67 | QRegExp rx_string("\\b(FileName|DirectoryName)\\b"); 68 | 69 | // if the type is Filename or DirectoryName 70 | if (rx_string.indexIn (pattern_description) != -1) 71 | { 72 | QString value = index.model()->data(index, Qt::DisplayRole).toString(); 73 | 74 | QStyleOptionViewItem my_option = option; 75 | my_option.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; 76 | 77 | // print the text in the display 78 | drawDisplay(painter, my_option, my_option.rect, value); 79 | // if the line has the focus, print a rectangle 80 | drawFocus(painter, my_option, my_option.rect); 81 | } 82 | else 83 | { 84 | // for all other types use the standard delegate 85 | QItemDelegate::paint(painter, option, index); 86 | } 87 | } 88 | else 89 | QItemDelegate::paint(painter, option, index); 90 | } 91 | 92 | 93 | 94 | QWidget *ParameterDelegate::createEditor(QWidget *parent, 95 | const QStyleOptionViewItem &option, 96 | const QModelIndex &index) const 97 | { 98 | if (index.column() == value_column) 99 | { 100 | // load pattern description stored in the StatusLine 101 | QString pattern_description = index.data(Qt::StatusTipRole).toString(); 102 | 103 | QRegExp rx_string("\\b(Anything|MultipleSelection|Map)\\b"), 104 | rx_list("\\b(List)\\b"), 105 | rx_filename("\\b(FileName)\\b"), 106 | rx_dirname("\\b(DirectoryName)\\b"), 107 | rx_integer("\\b(Integer)\\b"), 108 | rx_double("\\b(Double|Float|Floating)\\b"), 109 | rx_selection("\\b(Selection)\\b"), 110 | rx_bool("\\b(Bool)\\b"); 111 | 112 | // if the type is "Anything" choose a LineEditor 113 | if (rx_string.indexIn (pattern_description) != -1) 114 | { 115 | QLineEdit * line_editor = new QLineEdit(parent); 116 | connect(line_editor, SIGNAL(editingFinished()), 117 | this, SLOT(commit_and_close_editor())); 118 | 119 | return line_editor; 120 | } 121 | else if (rx_list.indexIn (pattern_description) != -1) 122 | { 123 | // if the type is "List" of files/directories choose a BrowseLineEditor 124 | if (rx_filename.indexIn (pattern_description) != -1) 125 | { 126 | BrowseLineEdit * filename_editor = 127 | new BrowseLineEdit(BrowseLineEdit::files, parent); 128 | 129 | connect(filename_editor, SIGNAL(editingFinished()), 130 | this, SLOT(commit_and_close_editor())); 131 | 132 | return filename_editor; 133 | } 134 | // if the type is "List" of something else choose a LineEditor 135 | else 136 | { 137 | QLineEdit * line_editor = new QLineEdit(parent); 138 | 139 | connect(line_editor, SIGNAL(editingFinished()), 140 | this, SLOT(commit_and_close_editor())); 141 | 142 | return line_editor; 143 | } 144 | } 145 | // if the type is "FileName" choose a BrowseLineEditor 146 | else if (rx_filename.indexIn (pattern_description) != -1) 147 | { 148 | BrowseLineEdit * filename_editor = 149 | new BrowseLineEdit(BrowseLineEdit::file, parent); 150 | 151 | connect(filename_editor, SIGNAL(editingFinished()), 152 | this, SLOT(commit_and_close_editor())); 153 | 154 | return filename_editor; 155 | } 156 | // if the type is "DirectoryName" choose a BrowseLineEditor 157 | else if (rx_dirname.indexIn (pattern_description) != -1) 158 | { 159 | BrowseLineEdit * dirname_editor = 160 | new BrowseLineEdit(BrowseLineEdit::directory, parent); 161 | 162 | connect(dirname_editor, SIGNAL(editingFinished()), 163 | this, SLOT(commit_and_close_editor())); 164 | 165 | return dirname_editor; 166 | } 167 | // if the type is "Integer" choose a LineEditor with appropriate bounds 168 | else if (rx_integer.indexIn (pattern_description) != -1) 169 | { 170 | const QStringList default_pattern = pattern_description.split(" ").filter("..."); 171 | const QStringList default_values = default_pattern[0].split("..."); 172 | 173 | QLineEdit * line_edit = new QLineEdit(parent); 174 | line_edit->setValidator(new QIntValidator(default_values[0].toInt(), default_values[1].toInt(), line_edit)); 175 | 176 | connect(line_edit, SIGNAL(editingFinished()), 177 | this, SLOT(commit_and_close_editor())); 178 | 179 | return line_edit; 180 | } 181 | // if the type is "Double" choose a LineEditor with appropriate bounds 182 | else if (rx_double.indexIn (pattern_description) != -1) 183 | { 184 | const QStringList default_pattern = pattern_description.split(" ").filter("..."); 185 | QStringList default_values = default_pattern[0].split("..."); 186 | 187 | // Unfortunately conversion of MAX_DOUBLE to string and back fails 188 | // sometimes, therefore use MAX_DOUBLE/2 to make sure we are below. 189 | // In practice MAX_DOUBLE just means VERY large, it is normally not 190 | // important how large. 191 | const double max_double = std::numeric_limits::max()/2; 192 | default_values = default_values.replaceInStrings("MAX_DOUBLE", 193 | QVariant(max_double).toString()); 194 | 195 | const unsigned int number_of_decimals = 14; 196 | 197 | QLineEdit * line_edit = new QLineEdit(parent); 198 | line_edit->setValidator(new QDoubleValidator(default_values[0].toDouble(), 199 | default_values[1].toDouble(), 200 | number_of_decimals, 201 | line_edit)); 202 | 203 | connect(line_edit, SIGNAL(editingFinished()), 204 | this, SLOT(commit_and_close_editor())); 205 | 206 | return line_edit; 207 | } 208 | // if the type is "Selection" choose a ComboBox 209 | else if (rx_selection.indexIn (pattern_description) != -1) 210 | { 211 | QComboBox * combo_box = new QComboBox(parent); 212 | 213 | // we assume, that pattern_description is of the form 214 | // "Type: [Selection item1|item2| ....|item ]". 215 | // Find the first space after the first '[', 216 | // which indicates the start of the first option 217 | int begin_pattern = pattern_description.indexOf("["); 218 | begin_pattern = pattern_description.indexOf(" ",begin_pattern) + 1; 219 | 220 | // Find the last ']', which signals the end of the options 221 | const int end_pattern = pattern_description.lastIndexOf("]"); 222 | 223 | // Extract the options from the string 224 | QString pattern = pattern_description.mid(begin_pattern,end_pattern-begin_pattern); 225 | 226 | // Remove trailing whitespaces 227 | while (pattern.endsWith(' ')) 228 | pattern.chop(1); 229 | 230 | // Split the list 231 | const QStringList choices = pattern.split("|"); 232 | combo_box->addItems(choices); 233 | 234 | combo_box->setEditable(false); 235 | 236 | connect(combo_box, SIGNAL(currentIndexChanged(int)), 237 | this, SLOT(commit_and_close_editor())); 238 | 239 | return combo_box; 240 | } 241 | // if the type is "Bool" choose a ComboBox 242 | else if (rx_bool.indexIn (pattern_description) != -1) 243 | { 244 | QComboBox * combo_box = new QComboBox(parent); 245 | 246 | std::vector choices; 247 | choices.push_back(std::string("true")); 248 | choices.push_back(std::string("false")); 249 | 250 | // add items to the combo box 251 | for (unsigned int i=0; iaddItem (tr(choices[i].c_str()), tr(choices[i].c_str())); 253 | 254 | combo_box->setEditable(false); 255 | 256 | connect(combo_box, SIGNAL(currentIndexChanged(int)), 257 | this, SLOT(commit_and_close_editor())); 258 | 259 | return combo_box; 260 | } 261 | else 262 | { 263 | return QItemDelegate::createEditor(parent, option, index); 264 | }; 265 | }; 266 | 267 | // if it is not the column "parameter values", do nothing 268 | return 0; 269 | } 270 | 271 | 272 | 273 | void ParameterDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const 274 | { 275 | if (index.column() == value_column) 276 | { 277 | if (BrowseLineEdit * filename_editor = qobject_cast(editor)) 278 | { 279 | QString file_name = index.data(Qt::DisplayRole).toString(); 280 | filename_editor->setText(file_name); 281 | } 282 | else if (QComboBox * combo_box = qobject_cast(editor)) 283 | { 284 | QRegExp rx(index.data(Qt::DisplayRole).toString()); 285 | 286 | // Preset ComboBox to the current selection 287 | for (int i=0; icount(); ++i) 288 | if (rx.exactMatch(combo_box->itemText(i))) 289 | combo_box->setCurrentIndex(i); 290 | } 291 | else 292 | QItemDelegate::setEditorData(editor, index); 293 | } 294 | } 295 | 296 | 297 | 298 | void ParameterDelegate::commit_and_close_editor() 299 | { 300 | QWidget * editor = qobject_cast(sender()); 301 | emit commitData(editor); 302 | emit closeEditor(editor); 303 | } 304 | 305 | 306 | 307 | void ParameterDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, 308 | const QModelIndex &index) const 309 | { 310 | if (index.column() == value_column) 311 | { 312 | if (QLineEdit * line_edit = qobject_cast(editor)) 313 | { 314 | QString line_edit_content = line_edit->text(); 315 | int position = 0; 316 | 317 | // If the editor has a validator, only accept the content if it contains 318 | // correct input. Otherwise bad cases 319 | // can happen, when some unfinished number violates the bounds, and 320 | // the user clicks elsewhere to lose the focus of the editor. 321 | if (line_edit->validator()) 322 | { 323 | if (line_edit->validator()->validate(line_edit_content,position) == QValidator::Acceptable) 324 | model->setData(index, line_edit_content); 325 | } 326 | else 327 | model->setData(index, line_edit_content); 328 | } 329 | else if (BrowseLineEdit * filename_editor = qobject_cast(editor)) 330 | { 331 | QString value = filename_editor->text(); 332 | model->setData(index, value); 333 | } 334 | else if (QComboBox * combo_box = qobject_cast(editor)) 335 | { 336 | QString value = combo_box->currentText(); 337 | model->setData(index, value); 338 | } 339 | else 340 | QItemDelegate::setModelData(editor, model, index); 341 | } 342 | } 343 | } 344 | } 345 | 346 | -------------------------------------------------------------------------------- /parameter_delegate.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #ifndef PARAMETERDELEGATE_H 18 | #define PARAMETERDELEGATE_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "browse_lineedit.h" 28 | 29 | 30 | namespace dealii 31 | { 32 | /*! @addtogroup ParameterGui 33 | *@{ 34 | */ 35 | namespace ParameterGui 36 | { 37 | /** 38 | * The ParameterDelegate class implements special delegates for the QTreeWidget class used in the parameterGUI. 39 | * The QTreeWidget class provides some different standard delegates for editing parameters shown in the 40 | * tree structure. The ParameterDelegate class provides special editors for the different types of parameters defined in 41 | * the ParameterHandler class. For all parameter types based on strings as "Anything", "MultipleSelection" "Map" and 42 | * "List" a simple line editor will be shown up. In the case of integer and double type parameters the editor is a spin box and for 43 | * "Selection" type parameters a combo box will be shown up. For parameters of type "FileName" and "DirectoryName" 44 | * the delegate shows a @ref BrowseLineEdit editor. The column of the tree structure with the parameter values has to be set 45 | * in the constructor. 46 | * 47 | * @note This class is used in the graphical user interface for the @ref ParameterHandler class. 48 | * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. 49 | * 50 | * @ingroup ParameterGui 51 | * @author Martin Steigemann, Wolfgang Bangerth, 2010 52 | */ 53 | class ParameterDelegate : public QItemDelegate 54 | { 55 | Q_OBJECT 56 | 57 | public: 58 | /** 59 | * Constructor, @p value_column specifies the column 60 | * of the parameter tree this delegate will be used on. 61 | */ 62 | ParameterDelegate (const int value_column, QObject *parent = 0); 63 | 64 | /** 65 | * This function creates the appropriate editor for the parameter 66 | * based on the index. 67 | */ 68 | QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, 69 | const QModelIndex &index) const; 70 | 71 | /** 72 | * Reimplemented from QItemDelegate. 73 | */ 74 | QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; 75 | 76 | /** 77 | * Reimplemented from QItemDelegate. 78 | */ 79 | void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; 80 | 81 | /** 82 | * Reimplemented from QItemDelegate. 83 | */ 84 | void setEditorData(QWidget *editor, const QModelIndex &index) const; 85 | 86 | /** 87 | * Reimplemented from QItemDelegate. 88 | */ 89 | void setModelData(QWidget *editor, QAbstractItemModel *model, 90 | const QModelIndex &index) const; 91 | 92 | private slots: 93 | /** 94 | * Reimplemented from QItemDelegate. 95 | */ 96 | void commit_and_close_editor(); 97 | 98 | private: 99 | /** 100 | * The column this delegate will be used on. 101 | */ 102 | int value_column; 103 | }; 104 | } 105 | /**@}*/ 106 | } 107 | 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /parameter_gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dealii/parameter_gui/b7c0251b57dfbcc3fe873b25a6eb604a11a63e1d/parameter_gui.png -------------------------------------------------------------------------------- /parameters.xml: -------------------------------------------------------------------------------- 1 | 2 | ElasticityElasticityBasic equation to solve0[Anything]CtsSpecimenSpecimenDomain1[Selection CtSpecimen|CtsSpecimen|SENBeam ]52Use this number of terms in asymptotic decompositions2[Selection 2|3|5 ]falsefalseOutput grids in eps format3[Bool]falsefalseOutput solutions in vtk format4[Bool]falsetrueOutput crack path data5[Bool]falsefalseOutput detailed flat quad data6[Bool]AluminiumAlloy7075T651AluminiumAlloy7075T651Description of the material: MaterialName|ReadMaterial7[Selection AluminiumAlloy7075T651|PlexiGlas|SuperAlloyPWA14801493|SihParisIrwinMaterialOne|SihParisIrwinMaterialTwo|CorticalBone|Beton|TestMaterial|ReadMaterial ]HomogeneousHomogeneousType of material: Homogeneous|Composite|FGM8[Selection Homogeneous|Composite|FGM ]0.0.Material angle with respect to the basic coordinate system9[Double -1.79769e+308...1.79769e+308 (inclusive)]plane_strainplain_strainPlane state: plane_strain|plane_stress10[Selection plane_strain|plain_stress ]falsefalseScale elastic moduli to a11 = 1 and a22 = 111[Bool]TestMaterialPropertiesReadedMaterialPropertiesDescription of ReadMaterial12[Anything]108752.23881.Elastic constant13[Double -1.79769e+308...1.79769e+308 (inclusive)]56023.88061.Elastic constant14[Double -1.79769e+308...1.79769e+308 (inclusive)]108752.23881.Elastic constant15[Double -1.79769e+308...1.79769e+308 (inclusive)]0.1.Elastic constant16[Double -1.79769e+308...1.79769e+308 (inclusive)]0.1.Elastic constant17[Double -1.79769e+308...1.79769e+308 (inclusive)]26364.17911.Elastic constant18[Double -1.79769e+308...1.79769e+308 (inclusive)]AluminiumAlloy7075T651AluminiumAlloy7075T651Description of the material: MaterialName|ReadMaterial19[Selection AluminiumAlloy7075T651|PlexiGlas|SuperAlloyPWA14801493|SihParisIrwinMaterialOne|SihParisIrwinMaterialTwo|CorticalBone|Beton|TestMaterial|ReadMaterial ]108752.23881.Elastic constant20[Double -1.79769e+308...1.79769e+308 (inclusive)]56023.88061.Elastic constant21[Double -1.79769e+308...1.79769e+308 (inclusive)]108752.23881.Elastic constant22[Double -1.79769e+308...1.79769e+308 (inclusive)]0.1.Elastic constant23[Double -1.79769e+308...1.79769e+308 (inclusive)]0.1.Elastic constant24[Double -1.79769e+308...1.79769e+308 (inclusive)]26364.17911.Elastic constant25[Double -1.79769e+308...1.79769e+308 (inclusive)]0.0.Material angle with respect to the basic coordinate system26[Double -1.79769e+308...1.79769e+308 (inclusive)]0.50.Perturbation parameter27[Double -1.79769e+308...1.79769e+308 (inclusive)]100004500Applied force value in Newton28[Double -1.79769e+308...1.79769e+308 (inclusive)]0.0If the specimen allows different forces, this parameter can be used to control them29[Double -1.79769e+308...1.79769e+308 (inclusive)]da/dN-curveda/dN-curve30[Selection da/dN-curve|Paris-law|Forman-Mettu-equation ]104.2510031[Double -1.79769e+308...1.79769e+308 (inclusive)]972.100032[Double -1.79769e+308...1.79769e+308 (inclusive)]0.10.133[Double -1.79769e+308...1.79769e+308 (inclusive)]3.134[Double -1.79769e+308...1.79769e+308 (inclusive)]0.0000000000212135[Double -1.79769e+308...1.79769e+308 (inclusive)]2.1136[Double -1.79769e+308...1.79769e+308 (inclusive)]0.0000000000212137[Double -1.79769e+308...1.79769e+308 (inclusive)]2.885138[Double -1.79769e+308...1.79769e+308 (inclusive)]

0.5139[Double -1.79769e+308...1.79769e+308 (inclusive)]

1.0140[Double -1.79769e+308...1.79769e+308 (inclusive)]
21.41[Double -1.79769e+308...1.79769e+308 (inclusive)]1242[Integer range -2147483648...2147483647 (inclusive)]0.5143[Double -1.79769e+308...1.79769e+308 (inclusive)]0.250.2544[Double -1.79769e+308...1.79769e+308 (inclusive)]25010045[Double -1.79769e+308...1.79769e+308 (inclusive)]110.110.46[Double -1.79769e+308...1.79769e+308 (inclusive)]-110.-110.47[Double -1.79769e+308...1.79769e+308 (inclusive)]180.180.48[Double -1.79769e+308...1.79769e+308 (inclusive)]-180.-180.49[Double -1.79769e+308...1.79769e+308 (inclusive)]222250[Integer range -2147483648...2147483647 (inclusive)]363651[Integer range -2147483648...2147483647 (inclusive)]1152[Integer range -2147483648...2147483647 (inclusive)]31053[Integer range -2147483648...2147483647 (inclusive)]falsetrue54[Bool]truefalse55[Bool]falsefalse56[Bool]falsefalse57[Bool]2500001000058[Integer range -2147483648...2147483647 (inclusive)]ParaSailsBoomerAMG59[Selection BoomerAMG|Euclid|ParaSails ]0.20.2560[Double -1.79769e+308...1.79769e+308 (inclusive)]0.90.961[Double -1.79769e+308...1.79769e+308 (inclusive)]0062[Integer range -2147483648...2147483647 (inclusive)]falsefalse63[Bool]4164[Integer range -2147483648...2147483647 (inclusive)]2065[Selection 0|1|2 ]1166[Integer range -2147483648...2147483647 (inclusive)]0.10.167[Double -1.79769e+308...1.79769e+308 (inclusive)]0.050.0568[Double -1.79769e+308...1.79769e+308 (inclusive)]0.0.69[Double -1.79769e+308...1.79769e+308 (inclusive)]/home/masteige/projects/mcrack/mcrack2d/examples/test/meshes/mesh.ucd/home/masteige/mcrack2d/examples//meshes/mesh.ucd70[FileName (Type: input)]/home/masteige/projects/mcrack/mcrack2d/examples/test/meshes/crack_path_out_T=001_tip=P1.data/home/masteige/mcrack2d/examples/crack_path_in.data71[FileName (Type: input)]/home/masteige/projects/mcrack/mcrack2d/examples/test/meshes/crack_path_out.data/home/masteige/mcrack2d/examples/crack_path_out.data72[FileName (Type: input)]/home/masteige/projects/mcrack/mcrack2d/examples/test/matrix_M.data/home/masteige/mcrack2d/examples/Matrix_M_in.data73[FileName (Type: input)]/home/masteige/projects/mcrack/mcrack2d/examples/test/matrix_M_out.data/home/masteige/mcrack2d/examples/Matrix_M_out.data74[FileName (Type: input)]/home/masteige/projects/mcrack/mcrack2d/examples/test/da_dN_curve.data/home/masteige/mcrack2d/examples/da_dN_curve.data75[FileName (Type: input)]/home/masteige/projects/mcrack/mcrack2d/examples/test/results.data/home/masteige/mcrack2d/examples/results/results.data76[FileName (Type: input)]/home/masteige/projects/mcrack/mcrack2d/common/scripts/extract_mesh.py/home/masteige/mcrack2d/common/scripts/extract_mesh.py77[FileName (Type: input)]/home/masteige/projects/mcrack/mcrack2d/common/material_database//home/masteige/mcrack2d/common/material_database78[DirectoryName]/home/masteige/projects/mcrack/mcrack2d/examples/test//home/masteige/mcrack2d/examples79[DirectoryName]/home/masteige/projects/mcrack/mcrack2d/examples/test/graphics//home/masteige/mcrack2d/examples/graphics80[DirectoryName]/home/masteige/projects/mcrack/mcrack2d/examples/test/meshes//home/masteige/mcrack2d/examples/meshes81[DirectoryName]/home/masteige/projects/mcrack/mcrack2d/examples/test/results/home/masteige/mcrack2d/examples/results82[DirectoryName]
-------------------------------------------------------------------------------- /prm_parameter_writer.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2017 by Rene Gassmoeller 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #include "prm_parameter_writer.h" 18 | 19 | namespace dealii 20 | { 21 | namespace ParameterGui 22 | { 23 | PRMParameterWriter::PRMParameterWriter(QTreeWidget *tree_widget) 24 | : tree_widget(tree_widget) 25 | { 26 | } 27 | 28 | 29 | 30 | bool PRMParameterWriter::write_prm_file(QIODevice *device) 31 | { 32 | // loop over the elements 33 | for (int i = 0; i < tree_widget->topLevelItemCount(); ++i) 34 | { 35 | const QString item_string = item_to_string(tree_widget->topLevelItem(i),0); 36 | device->write(item_string.toLatin1()); 37 | } 38 | 39 | return true; 40 | } 41 | 42 | 43 | 44 | QString PRMParameterWriter::item_to_string(const QTreeWidgetItem *item, 45 | const unsigned int indentation_level) 46 | { 47 | QString item_string; 48 | 49 | // if the entry has no children we have a parameter 50 | if (item->childCount() == 0) 51 | { 52 | bool non_default_value; 53 | 54 | if (item->text(5).startsWith("[Double")) 55 | non_default_value = item->data(1,Qt::DisplayRole).toReal() != item->data(2,Qt::DisplayRole).toReal(); 56 | else 57 | non_default_value = item->data(1,Qt::DisplayRole).toString() != item->data(2,Qt::DisplayRole).toString(); 58 | 59 | 60 | if (non_default_value) 61 | { 62 | for (unsigned int i=0; itext(0) + " = " + item->data(1,Qt::EditRole).toString() + "\n"); 66 | } 67 | } 68 | else 69 | { 70 | for (int i = 0; i < item->childCount(); ++i) 71 | item_string.push_back(item_to_string(item->child(i),indentation_level+1)); 72 | 73 | if (!item_string.isEmpty()) 74 | { 75 | item_string.push_front("subsection " + item->text(0).toLatin1() + "\n"); 76 | for (unsigned int i=0; i 21 | #include 22 | 23 | 24 | namespace dealii 25 | { 26 | /*! @addtogroup ParameterGui 27 | *@{ 28 | */ 29 | namespace ParameterGui 30 | { 31 | /** 32 | * The PRMParameterWriter class provides an interface to write parameters 33 | * stored in a QTreeWidget to a file in deal.II's PRM format. 34 | * This class only writes parameters that deviate from their default values to 35 | * improve the readability of the created file. 36 | * 37 | * @note This class is used in the graphical user interface for the 38 | * @ref ParameterHandler class. 39 | * It is not compiled into the deal.II libraries and can not be used by 40 | * applications using deal.II. 41 | * 42 | * @ingroup ParameterGui 43 | * @author Rene Gassmoeller, 2017 44 | */ 45 | class PRMParameterWriter 46 | { 47 | public: 48 | /** 49 | * Constructor. 50 | * Parameter values from @p tree_widget will be written. 51 | */ 52 | PRMParameterWriter (QTreeWidget *tree_widget); 53 | 54 | /** 55 | * This function writes the parameter values stored in tree_widget 56 | * to @p device in the PRM format. 57 | */ 58 | bool write_prm_file (QIODevice *device); 59 | 60 | private: 61 | /** 62 | * This function creates a string that corresponds to the data written 63 | * to a prm file for a given @p item of tree_widget. 64 | * If the @p item is a parameter it is only written if its value differs 65 | * from its default value. If the @p item is a subsection, a start element 66 | * subsection is written and write_item is called 67 | * recursively to write the next item. 68 | * If no items in this subsection differ from their default values then 69 | * the subsection is not written. 70 | * @p indentation_level describes the level the current item belongs to. 71 | * 0 describes a top level item and each subsection increases the level 72 | * by one. 73 | * 74 | */ 75 | QString item_to_string (const QTreeWidgetItem *item, 76 | const unsigned int indentation_level); 77 | 78 | /** 79 | * A pointer to the QTreeWidget structure 80 | * which stores the parameters. 81 | */ 82 | QTreeWidget *tree_widget; 83 | }; 84 | } 85 | /**@}*/ 86 | } 87 | 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /settings_dialog.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2017 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #include "settings_dialog.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace dealii 25 | { 26 | namespace ParameterGui 27 | { 28 | SettingsDialog::SettingsDialog(QSettings *gui_settings, 29 | QWidget *parent) 30 | : QDialog(parent, 0) 31 | { 32 | setWindowTitle("Settings"); 33 | 34 | settings = gui_settings; 35 | loadSettings(); 36 | 37 | QFormLayout * grid = new QFormLayout(this); 38 | 39 | // add a choose font button 40 | change_font = new QPushButton(this); 41 | change_font->setText(QErrorMessage::tr("Change font")); 42 | connect(change_font, SIGNAL(clicked()), this, SLOT(selectFont())); 43 | grid->addRow("Change Font",change_font); 44 | 45 | // add a checkbox 46 | hide_default = new QCheckBox(this); 47 | hide_default->setChecked(hide_default_values); 48 | connect(hide_default, SIGNAL(stateChanged(int)), this, SLOT(changeHideDefault(int))); 49 | grid->addRow("Hide default values",hide_default); 50 | 51 | // add an OK button 52 | ok = new QPushButton(this); 53 | ok->setText(QErrorMessage::tr("&OK")); 54 | connect(ok, SIGNAL(clicked()), this, SLOT(accept())); 55 | 56 | // add a Cancel button 57 | cancel = new QPushButton(this); 58 | cancel->setText(QErrorMessage::tr("&Cancel")); 59 | connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); 60 | grid->addRow(ok,cancel); 61 | 62 | connect(this, SIGNAL(accepted()), this, SLOT(writeSettings())); 63 | } 64 | 65 | 66 | 67 | void SettingsDialog::selectFont() 68 | { 69 | bool ok; 70 | QFont new_font = QFontDialog::getFont( 71 | &ok, selected_font, this); 72 | if (ok) { 73 | selected_font = new_font; 74 | } 75 | } 76 | 77 | 78 | 79 | void SettingsDialog::changeHideDefault(int state) 80 | { 81 | hide_default_values = state; 82 | } 83 | 84 | 85 | 86 | void SettingsDialog::loadSettings() 87 | { 88 | settings->beginGroup("Settings"); 89 | hide_default_values = settings->value("hideDefault", false).toBool(); 90 | 91 | QString stored_font_string = settings->value("Font", QFont().toString()).toString(); 92 | selected_font.fromString(stored_font_string); 93 | settings->endGroup(); 94 | } 95 | 96 | 97 | 98 | void SettingsDialog::writeSettings() 99 | { 100 | settings->beginGroup("Settings"); 101 | 102 | settings->setValue("hideDefault", hide_default_values); 103 | settings->setValue("Font", selected_font.toString()); 104 | 105 | settings->endGroup(); 106 | } 107 | } 108 | } 109 | 110 | -------------------------------------------------------------------------------- /settings_dialog.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2017 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #ifndef SETTINGSDIALOG_H 18 | #define SETTINGSDIALOG_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | namespace dealii 26 | { 27 | /*! @addtogroup ParameterGui 28 | *@{ 29 | */ 30 | namespace ParameterGui 31 | { 32 | /** 33 | * The SettingsDialog class implements a settings dialog for the parameterGUI. 34 | * The dialog shows all available settings, and when the user clicks on 'OK' 35 | * stores them in the QSettings object handed over in the constructor (which 36 | * in turn stores them on disk to allow persistent settings). 37 | * 38 | * @ingroup ParameterGui 39 | * @author Rene Gassmoeller, 2017 40 | */ 41 | class SettingsDialog : public QDialog 42 | { 43 | Q_OBJECT 44 | 45 | public: 46 | /** 47 | * Constructor 48 | */ 49 | SettingsDialog (QSettings *settings, 50 | QWidget *parent = 0); 51 | 52 | public slots: 53 | /** 54 | * Function that displays a font selection dialog and stores the result. 55 | */ 56 | void selectFont(); 57 | 58 | /** 59 | * Function that stores the checked state of the "Hide default" checkbox. 60 | */ 61 | void changeHideDefault(int state); 62 | 63 | /** 64 | * Function that stores the new settings in the settings object 65 | * (i.e. on disk). 66 | */ 67 | void writeSettings(); 68 | 69 | /** 70 | * Function that loads the settings from the settings file. 71 | */ 72 | void loadSettings(); 73 | 74 | private: 75 | /** 76 | * This variable stores if the default values should be hidden. This 77 | * might seem duplicative, since it is also stored in settings, 78 | * but this variable stores the 'current' state of the checkbox, 79 | * while settings is only updated after clicking OK. 80 | */ 81 | bool hide_default_values; 82 | 83 | /** 84 | * The selected font as shown in the Change Font dialog. 85 | */ 86 | QFont selected_font; 87 | 88 | /** 89 | * The Ok button. 90 | */ 91 | QPushButton *ok; 92 | 93 | /** 94 | * The Cancel button. 95 | */ 96 | QPushButton *cancel; 97 | 98 | /** 99 | * The Change font button. 100 | */ 101 | QPushButton *change_font; 102 | 103 | /** 104 | * The checkboxHide default values. 105 | */ 106 | QCheckBox *hide_default; 107 | 108 | /** 109 | * An object for storing settings in a file. 110 | */ 111 | QSettings *settings; 112 | }; 113 | } 114 | /**@}*/ 115 | } 116 | 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /xml_parameter_reader.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #include "xml_parameter_reader.h" 18 | 19 | namespace dealii 20 | { 21 | namespace ParameterGui 22 | { 23 | XMLParameterReader::XMLParameterReader(QTreeWidget *tree_widget) 24 | : tree_widget(tree_widget) 25 | { 26 | QStyle * style = tree_widget->style(); 27 | 28 | subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off); 29 | subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); 30 | 31 | parameter_icon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); 32 | } 33 | 34 | 35 | 36 | bool XMLParameterReader::read_xml_file(QIODevice *device) 37 | { 38 | xml.setDevice(device); 39 | 40 | // We look for a StartElement "ParameterHandler" 41 | // and start parsing after this. 42 | // 43 | // 44 | // ... 45 | // 46 | // 47 | 48 | while (xml.readNext() != QXmlStreamReader::Invalid) 49 | { 50 | if (xml.isStartElement()) 51 | if (xml.name() == "ParameterHandler") 52 | { 53 | parse_parameters(); 54 | 55 | return !xml.error();; 56 | }; 57 | }; 58 | 59 | xml.raiseError(QObject::tr("The file is not an ParameterHandler XML file.")); 60 | 61 | return !xml.error(); 62 | } 63 | 64 | 65 | 66 | QString XMLParameterReader::error_string() const 67 | { 68 | return QObject::tr("%1\nLine %2, column %3") 69 | .arg(xml.errorString()) 70 | .arg(xml.lineNumber()) 71 | .arg(xml.columnNumber()); 72 | } 73 | 74 | 75 | 76 | void XMLParameterReader::parse_parameters() 77 | { 78 | Q_ASSERT(xml.isStartElement() && xml.name() == "ParameterHandler"); 79 | 80 | // go to the next 81 | while (xml.readNext() != QXmlStreamReader::Invalid) 82 | { 83 | // if it is the closing element of ParameterHandler, break the loop 84 | if (xml.isEndElement() && xml.name() == "ParameterHandler") 85 | break; 86 | 87 | // if it is a start element it must be a subsection or a parameter 88 | if (xml.isStartElement()) 89 | read_subsection_element(0); 90 | }; 91 | } 92 | 93 | 94 | 95 | void XMLParameterReader::read_subsection_element(QTreeWidgetItem *parent) 96 | { 97 | // The structure of the parameter file is assumed to be of the form 98 | // 99 | // 100 | // 101 | // ... 102 | // 103 | // ... 104 | // ... 105 | // ... 106 | // 107 | // 108 | // ... 109 | // 110 | // ... 111 | // 112 | // 113 | // ... 114 | // 115 | // ... 116 | // 117 | // 118 | // Any subsection has a user-specified name also any parameter, but we do not know 119 | // the userspecified names and we can not assume anything. So, when parsing the file, 120 | // we do not know, if the actual is a or a 121 | // in a subsection. To decide, if the element is a subsection- or a parameter-name, 122 | // we assume, that if the next is , we have a 123 | // and a parameter has the entries , , , 124 | // and 125 | 126 | // the actual element is 127 | Q_ASSERT(xml.isStartElement()); 128 | 129 | // create a new subsection in the tree 130 | QTreeWidgetItem * subsection = create_child_item(parent); 131 | 132 | subsection->setIcon(0, subsection_icon); 133 | subsection->setText(0, demangle(xml.name().toString())); 134 | 135 | // the folder is not expanded 136 | tree_widget->setItemExpanded(subsection, 0); 137 | 138 | // read the next element 139 | while (xml.readNext() != QXmlStreamReader::Invalid) 140 | { 141 | // if the next element is , break the loop 142 | if (xml.isEndElement()) 143 | break; 144 | 145 | if (xml.isStartElement()) 146 | { 147 | // it can be , then we have found a parameter, 148 | if (xml.name() == "value") 149 | { 150 | // values can be edited 151 | subsection->setFlags(subsection->flags() | Qt::ItemIsEditable); 152 | read_parameter_element (subsection); 153 | } 154 | // or it can be a new 155 | else 156 | { 157 | // subsections can not be edited 158 | subsection->setFlags(subsection->flags() | Qt::NoItemFlags); 159 | read_subsection_element (subsection); 160 | }; 161 | }; 162 | }; 163 | } 164 | 165 | 166 | 167 | void XMLParameterReader::read_parameter_element(QTreeWidgetItem *parent) 168 | { 169 | // the actual element is , 170 | // then we have found a parameter-item 171 | Q_ASSERT(xml.isStartElement() && xml.name() == "value"); 172 | 173 | QString value = xml.readElementText(); 174 | // store as text to the item 175 | parent->setText(1, value); 176 | // change the icon of parent 177 | parent->setIcon(0, parameter_icon); 178 | 179 | // go to the next 180 | while (xml.readNext() != QXmlStreamReader::Invalid) 181 | { 182 | if (xml.isStartElement()) 183 | { 184 | // if it is store it 185 | if (xml.isStartElement() && xml.name() == "default_value") 186 | { 187 | QString default_value = xml.readElementText(); 188 | parent->setText(2, default_value); 189 | } 190 | // if it is store it 191 | else if (xml.isStartElement() && xml.name() == "documentation") 192 | { 193 | QString documentation = xml.readElementText(); 194 | parent->setText(3, documentation); 195 | } 196 | // if it is store it as text, 197 | // we only need this value for writing back to XML later 198 | else if (xml.isStartElement() && xml.name() == "pattern") 199 | { 200 | QString pattern = xml.readElementText(); 201 | parent->setText(4, pattern); 202 | } 203 | // if it is store it as text 204 | else if (xml.isStartElement() && xml.name() == "pattern_description") 205 | { 206 | QString pattern_description = xml.readElementText(); 207 | 208 | // show the type and default 209 | // in the StatusLine when 210 | // hovering over column 0 or 1 211 | parent->setText(5, pattern_description); 212 | parent->setStatusTip(0, "Type: " + pattern_description + " Default: " + parent->text(2)); 213 | parent->setStatusTip(1, "Type: " + pattern_description + " Default: " + parent->text(2)); 214 | 215 | // in order to store values as correct data types, 216 | // we check the following types in the pattern_description: 217 | QRegExp rx_string("\\b(Anything|FileName|DirectoryName|Selection|List|MultipleSelection)\\b"), 218 | rx_integer("\\b(Integer)\\b"), 219 | rx_double("\\b(Float|Floating|Double)\\b"), 220 | rx_bool("\\b(Bool)\\b"); 221 | 222 | // store the type "Anything" or "Filename" as a QString 223 | if (rx_string.indexIn (pattern_description) != -1) 224 | { 225 | QString value = parent->text(1); 226 | 227 | parent->setData(1, Qt::EditRole, value); 228 | parent->setData(1, Qt::DisplayRole, value); 229 | } 230 | // store the type "Integer" as an int 231 | else if (rx_integer.indexIn (pattern_description) != -1) 232 | { 233 | QString text = parent->text(1); 234 | 235 | bool ok = true; 236 | int value = text.toInt(&ok); 237 | 238 | if (ok) 239 | { 240 | parent->setData(1, Qt::EditRole, value); 241 | parent->setData(1, Qt::DisplayRole, value); 242 | } 243 | else 244 | xml.raiseError(QObject::tr("Cannot convert integer type to integer!")); 245 | } 246 | // store the type "Double" as an double 247 | else if (rx_double.indexIn (pattern_description) != -1) 248 | { 249 | QString text = parent->text(1); 250 | 251 | bool ok = true; 252 | 253 | double value = text.toDouble(&ok); 254 | 255 | if (ok) 256 | { 257 | parent->setData(1, Qt::EditRole, value); 258 | parent->setData(1, Qt::DisplayRole, value); 259 | } 260 | else 261 | xml.raiseError(QObject::tr("Cannot convert double type to double!")); 262 | } 263 | 264 | // store the type "Bool" as an boolean 265 | if (rx_bool.indexIn (pattern_description) != -1) 266 | { 267 | QRegExp test(parent->text(1)); 268 | 269 | bool value = true; 270 | 271 | if (test.exactMatch("true")) 272 | value = true; 273 | else if (test.exactMatch("false")) 274 | value = false; 275 | else 276 | xml.raiseError(QObject::tr("Cannot convert boolean type to boolean!")); 277 | 278 | // this is needed because we use for booleans the standard delegate 279 | parent->setText(1, ""); 280 | parent->setData(1, Qt::EditRole, value); 281 | parent->setData(1, Qt::DisplayRole, value); 282 | } 283 | 284 | break; 285 | } 286 | // if there is any other element, raise an error 287 | else 288 | { 289 | xml.raiseError(QObject::tr("Incomplete or unknown Parameter!")); 290 | break; 291 | } 292 | } 293 | } 294 | } 295 | 296 | 297 | 298 | QTreeWidgetItem *XMLParameterReader::create_child_item(QTreeWidgetItem *item) 299 | { 300 | // create a new child-item 301 | QTreeWidgetItem * child_item; 302 | 303 | // if item is not empty, append the new item as a child 304 | if (item) 305 | child_item = new QTreeWidgetItem(item); 306 | // otherwise create a new item in the tree 307 | else 308 | child_item = new QTreeWidgetItem(tree_widget); 309 | 310 | // set xml.tag_name as data 311 | child_item->setData(0, Qt::DisplayRole, xml.name().toString()); 312 | child_item->setText(0, xml.name().toString()); 313 | 314 | return child_item; 315 | } 316 | 317 | 318 | 319 | QString XMLParameterReader::demangle (const QString &s) 320 | { 321 | // this function is copied from the ParameterHandler class 322 | std::string s_temp (s.toStdString()); 323 | 324 | std::string u; 325 | u.reserve (s_temp.size()); 326 | 327 | for (unsigned int i=0; i(c)); 379 | 380 | // skip the two characters 381 | i += 2; 382 | } 383 | 384 | QString v (u.c_str()); 385 | 386 | return v; 387 | } 388 | } 389 | } 390 | 391 | -------------------------------------------------------------------------------- /xml_parameter_reader.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #ifndef XMLPARAMETERREADER_H 18 | #define XMLPARAMETERREADER_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | namespace dealii 27 | { 28 | /*! @addtogroup ParameterGui 29 | *@{ 30 | */ 31 | namespace ParameterGui 32 | { 33 | /** 34 | * The XMLParameterReader class provides an interface to parse parameters from XML files to a QTreeWidget. 35 | * This class makes extensive use of the QXmlStreamReader class, which implements the basic functionalities 36 | * for parsing XML files. 37 | * 38 | * @note This class is used in the graphical user interface for the @ref ParameterHandler class. 39 | * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. 40 | * 41 | * @ingroup ParameterGui 42 | * @author Martin Steigemann, Wolfgang Bangerth, 2010 43 | */ 44 | class XMLParameterReader 45 | { 46 | public: 47 | /** 48 | * Constructor. 49 | * The parameter values will be stored in @p tree_widget. 50 | */ 51 | XMLParameterReader (QTreeWidget *tree_widget); 52 | 53 | /** 54 | * This function reads the parameters from @p device into the tree_widget. 55 | * We use the QXmlStreamReader class for this. 56 | * There must be a start element 57 | * <ParameterHandler> 58 | * and an end element </ParameterHandler> 59 | * otherwise an exception is thrown. 60 | */ 61 | bool read_xml_file (QIODevice *device); 62 | 63 | /** 64 | * This function returns an error message. 65 | */ 66 | QString error_string () const; 67 | 68 | private: 69 | /** 70 | * This function implements a loop over the XML file 71 | * and parses XML elements. It calls @ref read_subsection_element 72 | * till the </ParameterHandler> element is found 73 | * or the end of the file is reached. In this case, an exception is thrown. 74 | */ 75 | void parse_parameters (); 76 | 77 | /** 78 | * This functions parses a subsection. 79 | * and adds it as a child to @p parent. 80 | * If the next element is <value>, 81 | * this functions calls @ref read_parameter_element 82 | * otherwise the function itself recursively. 83 | */ 84 | void read_subsection_element (QTreeWidgetItem *parent); 85 | 86 | /** 87 | * This function parses a parameter and 88 | * and adds it as a child to @p parent. 89 | * A parameter description consists of five elements: 90 | * @code 91 | * value 92 | * default_value 93 | * documentation 94 | * pattern 95 | * [pattern_description] 96 | * @endcode 97 | * If a parameter description is incomplete, an exception 98 | * is thrown. 99 | */ 100 | void read_parameter_element (QTreeWidgetItem *parent); 101 | 102 | /** 103 | * Reimplemented from the @ref ParameterHandler class. 104 | * Unmangle a string @p s into its original form. 105 | */ 106 | QString demangle (const QString &s); 107 | 108 | /** 109 | * This helper function creates a new child of @p item in the tree. 110 | */ 111 | QTreeWidgetItem *create_child_item(QTreeWidgetItem *item); 112 | 113 | /** 114 | * The QXmlStreamReader object for reading XML elements. 115 | */ 116 | QXmlStreamReader xml; 117 | 118 | /** 119 | * A pointer to the tree structure. 120 | */ 121 | QTreeWidget *tree_widget; 122 | 123 | /** 124 | * An icon for subsections in the tree structure. 125 | */ 126 | QIcon subsection_icon; 127 | 128 | /** 129 | * An icon for parameters in the tree structure. 130 | */ 131 | QIcon parameter_icon; 132 | }; 133 | } 134 | /**@}*/ 135 | } 136 | 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /xml_parameter_writer.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #include "xml_parameter_writer.h" 18 | 19 | namespace dealii 20 | { 21 | namespace ParameterGui 22 | { 23 | XMLParameterWriter::XMLParameterWriter(QTreeWidget *tree_widget) 24 | : tree_widget(tree_widget) 25 | { 26 | xml.setAutoFormatting(true); 27 | } 28 | 29 | 30 | 31 | bool XMLParameterWriter::write_xml_file(QIODevice *device) 32 | { 33 | xml.setDevice(device); 34 | 35 | // write the head 36 | xml.writeStartDocument(); 37 | 38 | // write the root element 39 | xml.writeStartElement("ParameterHandler"); 40 | 41 | // loop over the elements and write them 42 | for (int i = 0; i < tree_widget->topLevelItemCount(); ++i) 43 | write_item(tree_widget->topLevelItem(i)); 44 | 45 | // close the first element 46 | xml.writeEndDocument(); 47 | 48 | return true; 49 | } 50 | 51 | 52 | 53 | void XMLParameterWriter::write_item(QTreeWidgetItem *item) 54 | { 55 | // store the element name 56 | QString tag_name = mangle(item->text(0)); 57 | 58 | // and write to the file 59 | xml.writeStartElement(tag_name); 60 | 61 | // if the "value"-entry of this item is not empty, write a parameter 62 | if (!item->text(1).isEmpty()) 63 | { 64 | xml.writeTextElement("value", item->data(1,Qt::EditRole).toString()); 65 | xml.writeTextElement("default_value", item->text(2)); 66 | xml.writeTextElement("documentation", item->text(3)); 67 | xml.writeTextElement("pattern", item->text(4)); 68 | xml.writeTextElement("pattern_description", item->text(5)); 69 | }; 70 | 71 | // go over the childrens recursively 72 | for (int i = 0; i < item->childCount(); ++i) 73 | write_item(item->child(i)); 74 | 75 | // write closing 76 | xml.writeEndElement(); 77 | } 78 | 79 | 80 | 81 | QString XMLParameterWriter::mangle (const QString &s) 82 | { 83 | // this function is copied from the ParameterHandler class and adapted to mangle QString 84 | std::string s_temp (s.toStdString()); 85 | 86 | std::string u; 87 | u.reserve (s_temp.size()); 88 | 89 | static const std::string allowed_characters 90 | ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); 91 | 92 | // for all parts of the string, see if it is an allowed character or not 93 | for (unsigned int i=0; i(s_temp[i])/16]); 102 | u.push_back (hex[static_cast(s_temp[i])%16]); 103 | } 104 | 105 | QString v (u.c_str()); 106 | 107 | return v; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /xml_parameter_writer.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------- 2 | // 3 | // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth 4 | // 5 | // This file is part of the deal.II library. 6 | // 7 | // The deal.II library is free software; you can use it, redistribute 8 | // it, and/or modify it under the terms of the GNU Lesser General 9 | // Public License as published by the Free Software Foundation; either 10 | // version 2.1 of the License, or (at your option) any later version. 11 | // The full text of the license can be found in the file LICENSE at 12 | // the top level of the deal.II distribution. 13 | // 14 | // --------------------------------------------------------------------- 15 | 16 | 17 | #ifndef XMLPARAMETERWRITER_H 18 | #define XMLPARAMETERWRITER_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | namespace dealii 26 | { 27 | /*! @addtogroup ParameterGui 28 | *@{ 29 | */ 30 | namespace ParameterGui 31 | { 32 | /** 33 | * The XMLParameterWriter class provides an interface to write parameters stored in a QTreeWidget to a file in XML format. 34 | * This class makes extensive use of the QXmlStreamWriter class, which implements the basic functionalities for writing 35 | * XML files. 36 | * 37 | * @note This class is used in the graphical user interface for the @ref ParameterHandler class. 38 | * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. 39 | * 40 | * @ingroup ParameterGui 41 | * @author Martin Steigemann, Wolfgang Bangerth, 2010 42 | */ 43 | class XMLParameterWriter 44 | { 45 | public: 46 | /** 47 | * Constructor. 48 | * Parameter values from @p tree_widget will be written. 49 | */ 50 | XMLParameterWriter (QTreeWidget *tree_widget); 51 | 52 | /** 53 | * This function writes the parameter values stored in tree_widget 54 | * to @p device in XML format. We use the QXmlStreamWriter class 55 | * for this. The root element is 56 | * <ParameterHandler> 57 | */ 58 | bool write_xml_file (QIODevice *device); 59 | 60 | private: 61 | /** 62 | * This function writes a given @p item of tree_widget 63 | * to a file in XML format. For this the QXmlStreamWriter class is used. 64 | * If the @p item is a parameter, the elements that describes this parameter 65 | * are written: 66 | * @code 67 | * value 68 | * default_value 69 | * documentation 70 | * pattern 71 | * [pattern_description] 72 | * @endcode 73 | * If the @p item is a subsection, a start element this_subsection is written 74 | * and write_item is called recursively to write the next item. 75 | */ 76 | void write_item (QTreeWidgetItem *item); 77 | 78 | /** 79 | * Reimplemented from the @ref ParameterHandler class. 80 | * Mangle a string @p s so that it 81 | * doesn't contain any special 82 | * characters or spaces. 83 | */ 84 | QString mangle (const QString &s); 85 | 86 | /** 87 | * An QXmlStreamWriter object 88 | * which implements the functionalities 89 | * we need for writing parameters to XML files. 90 | */ 91 | QXmlStreamWriter xml; 92 | 93 | /** 94 | * A pointer to the QTreeWidget structure 95 | * which stores the parameters. 96 | */ 97 | QTreeWidget *tree_widget; 98 | }; 99 | } 100 | /**@}*/ 101 | } 102 | 103 | 104 | #endif 105 | --------------------------------------------------------------------------------