From: steigemann Date: Wed, 23 Feb 2011 23:32:17 +0000 (+0000) Subject: put all classes for the parameterGUI in a namespace and add parameterGUI documentatio... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b7089653365140d907d3e72afa8f6831fb6388a;p=dealii-svn.git put all classes for the parameterGUI in a namespace and add parameterGUI documentation to the doxygen flow git-svn-id: https://svn.dealii.org/trunk@23441 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/contrib/parameter_gui/browse_lineedit.cpp b/deal.II/contrib/parameter_gui/browse_lineedit.cpp index f6aaa3c983..33e89864c1 100644 --- a/deal.II/contrib/parameter_gui/browse_lineedit.cpp +++ b/deal.II/contrib/parameter_gui/browse_lineedit.cpp @@ -1,105 +1,121 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #include #include "browse_lineedit.h" -BrowseLineEdit::BrowseLineEdit(const BrowseType type, QWidget *parent) - : QFrame(parent, 0), - browse_type(type) +namespace dealii { - line_editor = new QLineEdit; - connect(line_editor, SIGNAL(editingFinished()), this, SLOT(editing_finished())); + namespace ParameterGui + { + BrowseLineEdit::BrowseLineEdit(const BrowseType type, QWidget *parent) + : QFrame(parent, 0), + browse_type(type) + { + line_editor = new QLineEdit; + connect(line_editor, SIGNAL(editingFinished()), this, SLOT(editing_finished())); - browse_button = new QPushButton("&Browse..."); - connect(browse_button, SIGNAL(clicked()), this, SLOT(browse())); + browse_button = new QPushButton("&Browse..."); + connect(browse_button, SIGNAL(clicked()), this, SLOT(browse())); - setFocusPolicy (Qt::StrongFocus); + setFocusPolicy (Qt::StrongFocus); - QHBoxLayout *layout = new QHBoxLayout; + QHBoxLayout *layout = new QHBoxLayout; - layout->addWidget(line_editor); - layout->addWidget(browse_button); - setLayout(layout); + layout->addWidget(line_editor); + layout->addWidget(browse_button); + setLayout(layout); - setAutoFillBackground(true); - setBackgroundRole(QPalette::Highlight); -} + setAutoFillBackground(true); + setBackgroundRole(QPalette::Highlight); + } -QSize BrowseLineEdit::sizeHint() const -{ - QSize size_line_editor = line_editor->sizeHint(), - size_browse_button = browse_button->sizeHint(); + QSize BrowseLineEdit::sizeHint() const + { + QSize size_line_editor = line_editor->sizeHint(), + size_browse_button = browse_button->sizeHint(); - int w = size_line_editor.rwidth() + size_browse_button.rwidth(), - h = qMax(size_line_editor.rheight(), size_browse_button.rheight()); + int w = size_line_editor.rwidth() + size_browse_button.rwidth(), + h = qMax(size_line_editor.rheight(), size_browse_button.rheight()); - return QSize (w, h); -} + return QSize (w, h); + } -QSize BrowseLineEdit::minimumSizeHint() const -{ - QSize size_line_editor = line_editor->minimumSizeHint(), - size_browse_button = browse_button->minimumSizeHint(); - - int w = size_line_editor.rwidth() + size_browse_button.rwidth(), - h = qMax(size_line_editor.rheight(), size_browse_button.rheight()); + QSize BrowseLineEdit::minimumSizeHint() const + { + QSize size_line_editor = line_editor->minimumSizeHint(), + size_browse_button = browse_button->minimumSizeHint(); - return QSize (w, h); -} + int w = size_line_editor.rwidth() + size_browse_button.rwidth(), + h = qMax(size_line_editor.rheight(), size_browse_button.rheight()); + return QSize (w, h); + } -QString BrowseLineEdit::text() const -{ - return line_editor->text(); -} + QString BrowseLineEdit::text() const + { + return line_editor->text(); + } -void BrowseLineEdit::setText(const QString &str) -{ - line_editor->setText(str); -} + void BrowseLineEdit::setText(const QString &str) + { + line_editor->setText(str); + } -void BrowseLineEdit::editing_finished() -{ - emit editingFinished(); -} + void BrowseLineEdit::editing_finished() + { + emit editingFinished(); + } -void BrowseLineEdit::browse() -{ - QString name = ""; - switch (browse_type) + void BrowseLineEdit::browse() { - case file: - { - name = QFileDialog::getOpenFileName(this, tr("Open File"), - QDir::currentPath(), - tr("All Files (*.*)")); - break; - }; + QString name = ""; - case directory: + switch (browse_type) { - name = QFileDialog::getExistingDirectory(this, tr("Open Directory"), - QDir::homePath(), - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - break; + case file: + { + name = QFileDialog::getOpenFileName(this, tr("Open File"), + QDir::currentPath(), + tr("All Files (*.*)")); + break; + }; + + case directory: + { + name = QFileDialog::getExistingDirectory(this, tr("Open Directory"), + QDir::homePath(), + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + break; + }; }; - }; - if (!name.isEmpty() && !name.isNull()) - line_editor->setText(name); + if (!name.isEmpty() && !name.isNull()) + line_editor->setText(name); + } + } } diff --git a/deal.II/contrib/parameter_gui/browse_lineedit.h b/deal.II/contrib/parameter_gui/browse_lineedit.h index 215693192b..2c0a97fada 100644 --- a/deal.II/contrib/parameter_gui/browse_lineedit.h +++ b/deal.II/contrib/parameter_gui/browse_lineedit.h @@ -1,3 +1,13 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #ifndef BROWSELINEEDIT_H #define BROWSELINEEDIT_H @@ -7,6 +17,14 @@ #include #include + +namespace dealii +{ +/*! @addtogroup ParameterGui + *@{ + */ + namespace ParameterGui + { /** * The BrowseLineEdit class provides a special line editor for the parameterGUI. * While editing file- or directory names it is much more easier to have a file-dialog @@ -15,78 +33,84 @@ * copies the path to the line editor. Depending on the BrowseType given in the constructor * the browse button opens a file or a directory dialog. * - * @ingroup gui - * @author Martin Steigemann, Wolfgang Bangerth, December 2010 + * @note This class is used in the graphical user interface for the @ref ParameterHandler class. + * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. + * + * @ingroup ParameterGui + * @author Martin Steigemann, Wolfgang Bangerth, 2010 */ -class BrowseLineEdit : public QFrame -{ - Q_OBJECT + class BrowseLineEdit : public QFrame + { + Q_OBJECT - public: + public: /** * The browse button opens a file or * a directory dialog. This can be specified * in the constructor by setting this flag BrowseType. */ - enum BrowseType {file = 0, directory = 1}; + enum BrowseType {file = 0, directory = 1}; /** * Constructor. The type of the browse dialog can be specified * by the flag BrowseType, the default is file. */ - BrowseLineEdit (const BrowseType type = file, - QWidget *parent = 0); + BrowseLineEdit (const BrowseType type = file, + QWidget *parent = 0); /** * Reimplemented from the QWidget class. * Returns the size of the editor. */ - QSize sizeHint() const; + QSize sizeHint() const; /** * Reimplemented from the QWidget class. */ - QSize minimumSizeHint() const; + QSize minimumSizeHint() const; /** * Returns the text of the line editor. */ - QString text() const; + QString text() const; /** * This pattern stores the type of the browse dialog. */ - BrowseType browse_type; + BrowseType browse_type; - public slots: + public slots: /** - * A slot for setting the text of the line editor. + * A slot to set @p str as text of the line editor. */ - void setText(const QString &str); - - signals: + void setText(const QString &str); + signals: /** * This signal will be emitted, if editing is finished. */ - void editingFinished(); + void editingFinished(); - private slots: + private slots: /** * This slot should be always called, if editing is finished. */ - void editing_finished(); + void editing_finished(); /** * This function opens a file- or a directory dialog as specified in the * constructor. */ - void browse(); + void browse(); - private: + private: /** * The line editor. */ - QLineEdit * line_editor; + QLineEdit * line_editor; /** * The browse button. */ - QPushButton * browse_button; -}; + QPushButton * browse_button; + }; + } +/**@}*/ +} + #endif diff --git a/deal.II/contrib/parameter_gui/info_message.cpp b/deal.II/contrib/parameter_gui/info_message.cpp index e0af897d37..db753bc0b1 100644 --- a/deal.II/contrib/parameter_gui/info_message.cpp +++ b/deal.II/contrib/parameter_gui/info_message.cpp @@ -1,83 +1,99 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #include #include "info_message.h" -InfoMessage::InfoMessage(QWidget *parent) - : QDialog(parent, 0) +namespace dealii { - show_again = true; // this variable stores, if the + namespace ParameterGui + { + InfoMessage::InfoMessage(QWidget *parent) + : QDialog(parent, 0) + { + show_again = true; // this variable stores, if the // the info message should be shown again - QGridLayout * grid = new QGridLayout(this); + QGridLayout * grid = new QGridLayout(this); - icon = new QLabel(this); // set an icon + icon = new QLabel(this); // set an icon #ifndef QT_NO_MESSAGEBOX - icon->setPixmap(QMessageBox::standardIcon(QMessageBox::Information)); - icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop); + icon->setPixmap(QMessageBox::standardIcon(QMessageBox::Information)); + icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop); #endif - grid->addWidget(icon, 0, 0, Qt::AlignTop); // add the icon in the upper left corner + grid->addWidget(icon, 0, 0, Qt::AlignTop); // add the icon in the upper left corner - message = new QTextEdit(this); // set the new message - message->setReadOnly(true); - grid->addWidget(message, 0, 1); // and add the message on the right + message = new QTextEdit(this); // set the new message + message->setReadOnly(true); + grid->addWidget(message, 0, 1); // and add the message on the right - again = new QCheckBox(this); // add a check box - again->setChecked(true); - again->setText(QErrorMessage::tr("&Show this message again")); - grid->addWidget(again, 1, 1, Qt::AlignTop); + again = new QCheckBox(this); // add a check box + again->setChecked(true); + again->setText(QErrorMessage::tr("&Show this message again")); + grid->addWidget(again, 1, 1, Qt::AlignTop); - ok = new QPushButton(this); // and finally a OK button - ok->setText(QErrorMessage::tr("&OK")); + ok = new QPushButton(this); // and finally a OK button + ok->setText(QErrorMessage::tr("&OK")); #ifdef QT_SOFTKEYS_ENABLED - ok_action = new QAction(ok); // define the action for the button - ok_action->setSoftKeyRole(QAction::PositiveSoftKey); - ok_action->setText(ok->text()); - connect(ok_action, SIGNAL(triggered()), this, SLOT(accept())); - addAction(ok_action); + ok_action = new QAction(ok); // define the action for the button + ok_action->setSoftKeyRole(QAction::PositiveSoftKey); + ok_action->setText(ok->text()); + connect(ok_action, SIGNAL(triggered()), this, SLOT(accept())); + addAction(ok_action); #endif - connect(ok, SIGNAL(clicked()), this, SLOT(accept())); - ok->setFocus(); // aand set the focus on the button - grid->addWidget(ok, 2, 0, 1, 2, Qt::AlignCenter); + connect(ok, SIGNAL(clicked()), this, SLOT(accept())); + ok->setFocus(); // aand set the focus on the button + grid->addWidget(ok, 2, 0, 1, 2, Qt::AlignCenter); - grid->setColumnStretch(1, 42); - grid->setRowStretch(0, 42); + grid->setColumnStretch(1, 42); + grid->setRowStretch(0, 42); // load settings from an ini-file - QString settings_file = QDir::currentPath() + "/settings.ini"; + QString settings_file = QDir::currentPath() + "/settings.ini"; - settings = new QSettings (settings_file, QSettings::IniFormat); + settings = new QSettings (settings_file, QSettings::IniFormat); - settings->beginGroup("infoMessage"); // we store settings of this class in the - show_again = settings->value("showInformation", true).toBool(); //group infoMessage - settings->endGroup(); -} + settings->beginGroup("infoMessage"); // we store settings of this class in the + show_again = settings->value("showInformation", true).toBool(); //group infoMessage + settings->endGroup(); + } -void InfoMessage::setInfoMessage(const QString &message) -{ - this->message->setText(message); // set the message -} + void InfoMessage::setInfoMessage(const QString &message) + { + this->message->setText(message); // set the message + } -void InfoMessage::showMessage() -{ - if (show_again) // and show the message - show(); -} + void InfoMessage::showMessage() + { + if (show_again) // and show the message + show(); + } -void InfoMessage::done(int r) -{ - if(!again->isChecked()) // if the box is not checked, - { // store this to settings - settings->beginGroup("infoMessage"); - settings->setValue("showInformation", false); - settings->endGroup(); - }; + void InfoMessage::done(int r) + { + if(!again->isChecked()) // if the box is not checked, + { // store this to settings + settings->beginGroup("infoMessage"); + settings->setValue("showInformation", false); + settings->endGroup(); + }; - QDialog::done(r); + QDialog::done(r); + } + } } diff --git a/deal.II/contrib/parameter_gui/info_message.h b/deal.II/contrib/parameter_gui/info_message.h index 03bf905c2e..f3ad3711e7 100644 --- a/deal.II/contrib/parameter_gui/info_message.h +++ b/deal.II/contrib/parameter_gui/info_message.h @@ -1,3 +1,13 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #ifndef INFOMESSAGE_H #define INFOMESSAGE_H @@ -9,76 +19,90 @@ #include +namespace dealii +{ +/*! @addtogroup ParameterGui + *@{ + */ + namespace ParameterGui + { /** * The InfoMessage class implements a special info message for the parameterGUI. - * Besides showing a info message itself, the dialog shows a checkbox "Show this message again". - * If the user unchecks this box, this is stored in the "settings.ini" file and will be reloaded + * Besides showing a info message itself, the dialog shows a checkbox "Show this message again". + * If the user unchecks this box, this is stored in the "settings.ini" file and will be reloaded * the next time the user opens the parameterGUI. The intention of such a info message is the following. - * The user should have some information on how using the GUI "at hand" - * such as "how to edit parameter values?" for example. But after reading this message, the user knows it - * and the message should not appear permanently. + * The user should have some information on how using the GUI "at hand" + * such as "how to edit parameter values" for example. But after reading this message, the user knows + * it and the message should not appear permanently. + * + * @note This class is used in the graphical user interface for the @ref ParameterHandler class. + * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. * - * @ingroup gui - * @author Martin Steigemann, Wolfgang Bangerth, December 2010 + * @ingroup ParameterGui + * @author Martin Steigemann, Wolfgang Bangerth, 2010 */ -class InfoMessage : public QDialog -{ - Q_OBJECT + class InfoMessage : public QDialog + { + Q_OBJECT - public: + public: /** * Constructor */ - InfoMessage (QWidget *parent = 0); + InfoMessage (QWidget *parent = 0); /** - * With this function the message which will be shown in the + * With this function the @p message which will be shown in the * dialog can be set. */ - void setInfoMessage(const QString &message); + void setInfoMessage(const QString &message); - public slots: + public slots: /** * Show the dialog with the message. */ - void showMessage(); + void showMessage(); - protected: + protected: /** * Reimplemented from QDialog. */ - void done(int r); + void done(int r); - private: + private: /** * This variable stores, if the message should be shown again the next time. */ - bool show_again; + bool show_again; /** * The Ok button. */ - QPushButton * ok; + QPushButton * ok; /** * The checkboxShow this message again. */ - QCheckBox * again; + QCheckBox * again; /** * The message editor. */ - QTextEdit * message; + QTextEdit * message; /** * An icon for the dialog. */ - QLabel * icon; + QLabel * icon; #ifdef QT_SOFTKEYS_ENABLED /** * A action for pressing the Ok button. */ - QAction *ok_action; + QAction * ok_action; #endif /** * An object for storing settings in a file. */ - QSettings * settings; -}; + QSettings * settings; + }; + } +/**@}*/ +} + #endif diff --git a/deal.II/contrib/parameter_gui/main.cpp b/deal.II/contrib/parameter_gui/main.cpp index 851df5bae5..461cd0c0aa 100644 --- a/deal.II/contrib/parameter_gui/main.cpp +++ b/deal.II/contrib/parameter_gui/main.cpp @@ -1,3 +1,13 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #include #include @@ -5,36 +15,52 @@ #include "mainwindow.h" +/*! @addtogroup ParameterGui + *@{ + */ /** * Main function for the parameterGUI. * The parameterGUI is a graphical user interface for editing parameter files based on the XML format, * created by the ParameterHandler::print_parameters() function with ParameterHandler::XML as second argument. * - * @image html logo_dealii_gui.png + * @image html logo_dealii_gui.png + * + * @note This class is used in the graphical user interface for the @ref ParameterHandler class. + * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. + * * - * @ingroup gui - * @author Martin Steigemann, Wolfgang Bangerth, December 2010 + *

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

+ * + * + * @ingroup ParameterGui + * @author Martin Steigemann, Wolfgang Bangerth, 2010 */ int main(int argc, char *argv[]) { - Q_INIT_RESOURCE(application); // init resources such as icons or graphics + Q_INIT_RESOURCE(application); // init resources such as icons or graphics QApplication app(argc, argv); - QSplashScreen * splash = new QSplashScreen; // setup a splash screen + QSplashScreen * splash = new QSplashScreen; // setup a splash screen splash->setPixmap(QPixmap(":/images/logo_dealii_gui.png")); splash->show(); - QTimer::singleShot(3000, splash, SLOT(close())); // and close it after 3000 ms + QTimer::singleShot(3000, splash, SLOT(close())); // and close it after 3000 ms - app.setApplicationName("parameterGUI for deal.II"); // setup the application name + app.setApplicationName("parameterGUI for deal.II"); // setup the application name - MainWindow * main_win = new MainWindow (argv[1]); // give command line arguments to main_win - // if a parameter file is specified at the - // command line, give it to the MainWindow. + dealii::ParameterGui::MainWindow * main_win = + new dealii::ParameterGui::MainWindow (argv[1]); // give command line arguments to main_win + // if a parameter file is specified at the + // command line, give it to the MainWindow. - QTimer::singleShot(1500, main_win, SLOT(show())); // show the main window with a short delay - // so we can see the splash screen + QTimer::singleShot(1500, main_win, SLOT(show())); // show the main window with a short delay + // so we can see the splash screen return app.exec(); } +/**@}*/ + diff --git a/deal.II/contrib/parameter_gui/mainwindow.cpp b/deal.II/contrib/parameter_gui/mainwindow.cpp index 1c621a130d..4cef562f34 100644 --- a/deal.II/contrib/parameter_gui/mainwindow.cpp +++ b/deal.II/contrib/parameter_gui/mainwindow.cpp @@ -1,123 +1,140 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #include #include "mainwindow.h" +#include "parameter_delegate.h" +#include "xml_parameter_reader.h" +#include "xml_parameter_writer.h" -MainWindow::MainWindow(const QString &filename) +namespace dealii { - QString settings_file = QDir::currentPath() + "/settings.ini"; // a file for user settings - - gui_settings = new QSettings (settings_file, QSettings::IniFormat); // load settings - // Up to now, we do not read any settings, - // but this can be used in the future for customizing the GUI. - - tree_widget = new QTreeWidget; // tree for showing XML tags - - // Setup the tree and the window first: - tree_widget->header()->setResizeMode(QHeaderView::ResizeToContents); // behavior of the header sections: - // "Interactive: User can resize sections" - // "Fixed: User cannot resize sections" - // "Stretch: Qt will automatically resize sections to fill available space" - // "ResizeToContents: Qt will automatically resize sections to optimal size" - tree_widget->setHeaderLabels(QStringList() << tr("(Sub)Sections/Parameters") - << tr("Value")); - tree_widget->setMouseTracking(true); // enables mouse events e.g. showing ToolTips - // and documentation in the StatusLine - tree_widget->setEditTriggers(QAbstractItemView::DoubleClicked| - QAbstractItemView::SelectedClicked| - QAbstractItemView::EditKeyPressed); -// QAbstractItemView::AnyKeyPressed); - // set which actions will initiate item editing: Editing starts when: - // DoubleClicked: an item is double clicked - // SelectedClicked: clicking on an already selected item - // EditKeyPressed: the platform edit key has been pressed over an item - // AnyKeyPressed: any key is pressed over an item - - tree_widget->setItemDelegate(new ParameterDelegate(1)); // set the delegate for editing items - setCentralWidget(tree_widget); - // connect: if the tree changes, the window will know - connect(tree_widget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(tree_was_modified())); - - create_actions(); // create window actions as "Open",... - create_menus(); // and menus - statusBar()->showMessage(tr("Ready, start editing by double-clicking or hitting F2!")); - setWindowTitle(tr("[*]parameterGUI")); // set window title - - resize(800, 600); // set window height and width - - if (filename.size() > 3) // if there is a file_name, try to load the file. - load_file(filename); // a vliad file has the xml extension, so we require size() > 3 -} + namespace ParameterGui + { + MainWindow::MainWindow(const QString &filename) + { + QString settings_file = QDir::currentPath() + "/settings.ini"; // a file for user settings + + gui_settings = new QSettings (settings_file, QSettings::IniFormat); // load settings + // Up to now, we do not read any settings, + // but this can be used in the future for customizing the GUI. + + tree_widget = new QTreeWidget; // tree for showing XML tags + + // Setup the tree and the window first: + tree_widget->header()->setResizeMode(QHeaderView::ResizeToContents); // behavior of the header sections: + // "Interactive: User can resize sections" + // "Fixed: User cannot resize sections" + // "Stretch: Qt will automatically resize sections to fill available space" + // "ResizeToContents: Qt will automatically resize sections to optimal size" + tree_widget->setHeaderLabels(QStringList() << tr("(Sub)Sections/Parameters") + << tr("Value")); + tree_widget->setMouseTracking(true); // enables mouse events e.g. showing ToolTips + // and documentation in the StatusLine + tree_widget->setEditTriggers(QAbstractItemView::DoubleClicked| + QAbstractItemView::SelectedClicked| + QAbstractItemView::EditKeyPressed); + // set which actions will initiate item editing: Editing starts when: + // DoubleClicked: an item is double clicked + // SelectedClicked: clicking on an already selected item + // EditKeyPressed: the platform edit key has been pressed over an item + // AnyKeyPressed: any key is pressed over an item + + tree_widget->setItemDelegate(new ParameterDelegate(1)); // set the delegate for editing items + setCentralWidget(tree_widget); + // connect: if the tree changes, the window will know + connect(tree_widget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(tree_was_modified())); + + create_actions(); // create window actions as "Open",... + create_menus(); // and menus + statusBar()->showMessage(tr("Ready, start editing by double-clicking or hitting F2!")); + setWindowTitle(tr("[*]parameterGUI")); // set window title + + resize(800, 600); // set window height and width + + if (filename.size() > 3) // if there is a file_name, try to load the file. + load_file(filename); // a vliad file has the xml extension, so we require size() > 3 + } -void MainWindow::open() -{ - if (maybe_save()) // check, if the content was modified + void MainWindow::open() { - QString file_name = // open a file dialog - QFileDialog::getOpenFileName(this, tr("Open XML Parameter File"), - QDir::currentPath(), - tr("XML Files (*.xml)")); - if (!file_name.isEmpty()) // if a file was selected, - load_file(file_name); // load the content - }; -} + if (maybe_save()) // check, if the content was modified + { + QString file_name = // open a file dialog + QFileDialog::getOpenFileName(this, tr("Open XML Parameter File"), + QDir::currentPath(), + tr("XML Files (*.xml)")); + if (!file_name.isEmpty()) // if a file was selected, + load_file(file_name); // load the content + }; + } -bool MainWindow::save() -{ - if (current_file.isEmpty()) // if there is no file - return save_as(); // to save changes, open a dialog - else - return save_file(current_file); // otherwise save -} + bool MainWindow::save() + { + if (current_file.isEmpty()) // if there is no file + return save_as(); // to save changes, open a dialog + else + return save_file(current_file); // otherwise save + } -bool MainWindow::save_as() -{ - QString file_name = // open a file dialog - QFileDialog::getSaveFileName(this, tr("Save XML Parameter File"), - QDir::currentPath(), - tr("XML Files (*.xml)")); - - if (file_name.isEmpty()) // if no file was selected - return false; // return false - else - return save_file(file_name); // otherwise save content to file -} + bool MainWindow::save_as() + { + QString file_name = // open a file dialog + QFileDialog::getSaveFileName(this, tr("Save XML Parameter File"), + QDir::currentPath(), + tr("XML Files (*.xml)")); + if (file_name.isEmpty()) // if no file was selected + return false; // return false + else + return save_file(file_name); // otherwise save content to file + } -void MainWindow::about() -{ -#ifdef Q_WS_MAC - static QPointer old_msg_box; - if (old_msg_box) { - old_msg_box->show(); - old_msg_box->raise(); - old_msg_box->activateWindow(); - return; - } + void MainWindow::about() + { +#ifdef Q_WS_MAC + static QPointer old_msg_box; + + if (old_msg_box) + { + old_msg_box->show(); + old_msg_box->raise(); + old_msg_box->activateWindow(); + return; + }; #endif - QString title = "About parameterGUI"; + QString title = "About parameterGUI"; - QString trAboutparameterGUIcaption; - trAboutparameterGUIcaption = QMessageBox::tr( + QString trAboutparameterGUIcaption; + trAboutparameterGUIcaption = QMessageBox::tr( "

parameterGUI: A GraphicalUserInterface for parameter handling in deal.II

" "

This program uses Qt version %1.

" ).arg(QLatin1String(QT_VERSION_STR)); - QString trAboutparameterGUItext; - trAboutparameterGUItext = QMessageBox::tr( + QString trAboutparameterGUItext; + trAboutparameterGUItext = QMessageBox::tr( "

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

" @@ -141,220 +158,221 @@ void MainWindow::about() "Wolfgang Bangerth, bangerth@math.tamu.edu

" ); - QMessageBox *msg_box = new QMessageBox; - msg_box->setAttribute(Qt::WA_DeleteOnClose); - msg_box->setWindowTitle(title); - msg_box->setText(trAboutparameterGUIcaption); - msg_box->setInformativeText(trAboutparameterGUItext); + QMessageBox *msg_box = new QMessageBox; + msg_box->setAttribute(Qt::WA_DeleteOnClose); + msg_box->setWindowTitle(title); + msg_box->setText(trAboutparameterGUIcaption); + msg_box->setInformativeText(trAboutparameterGUItext); - QPixmap pm(QLatin1String(":/images/logo_dealii_gui_128.png")); + QPixmap pm(QLatin1String(":/images/logo_dealii_gui_128.png")); - if (!pm.isNull()) - msg_box->setIconPixmap(pm); + if (!pm.isNull()) + msg_box->setIconPixmap(pm); #ifdef Q_WS_MAC - old_msg_box = msg_box; - msg_box->show(); + old_msg_box = msg_box; + msg_box->show(); #else - msg_box->exec(); + msg_box->exec(); #endif -} + } -void MainWindow::tree_was_modified() -{ - setWindowModified(true); // store, that the window was modified - // this is a function from the QMainWindow class - // and we use the windowModified mechanism to show a "*" - // in the window title, if content was modified -} + void MainWindow::tree_was_modified() + { + setWindowModified(true); // store, that the window was modified + // this is a function from the QMainWindow class + // and we use the windowModified mechanism to show a "*" + // in the window title, if content was modified + } -void MainWindow::show_message () -{ - QString title = "parameterGUI"; + void MainWindow::show_message () + { + QString title = "parameterGUI"; - info_message = new InfoMessage(this); + info_message = new InfoMessage(this); - info_message->setWindowTitle(title); - info_message->setInfoMessage(tr("Start Editing by double-clicking on the parameter value or" - " by hitting the platform edit key. For example, on Linux this is the F2-key!")); - info_message->showMessage(); -} + info_message->setWindowTitle(title); + info_message->setInfoMessage(tr("Start Editing by double-clicking on the parameter value or" + " by hitting the platform edit key. For example, on Linux this is the F2-key!")); + info_message->showMessage(); + } -void MainWindow::closeEvent(QCloseEvent *event) -{ - if (maybe_save()) // reimplement the closeEvent from the QMainWindow class - event->accept(); // check, if we have to save modified content, - else // if content was saved, accept the event, - event->ignore(); // otherwise ignore it -} + void MainWindow::closeEvent(QCloseEvent *event) + { + if (maybe_save()) // reimplement the closeEvent from the QMainWindow class + event->accept(); // check, if we have to save modified content, + else // if content was saved, accept the event, + event->ignore(); // otherwise ignore it + } -void MainWindow::create_actions() -{ - open_act = new QAction(tr("&Open..."), this); // create actions - open_act->setIcon(QIcon(":/icons/fileopen.png")); // and set icons - open_act->setShortcut(Qt::CTRL + Qt::Key_O); // set a short cut - open_act->setStatusTip(tr("Open a XML file")); // set a status tip - connect(open_act, SIGNAL(triggered()), this, SLOT(open())); // and connect - - save_act = new QAction(tr("&Save ..."), this); - save_act->setIcon(QIcon(":/icons/filesave.png")); - save_act->setShortcut(Qt::CTRL + Qt::Key_S); - save_act->setStatusTip(tr("Save the current XML file")); - connect(save_act, SIGNAL(triggered()), this, SLOT(save())); - - save_as_act = new QAction(tr("&Save As..."), this); - save_as_act->setIcon(QIcon(":/icons/filesaveas.png")); - save_as_act->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Q); - save_as_act->setStatusTip(tr("Save the current XML file as")); - connect(save_as_act, SIGNAL(triggered()), this, SLOT(save_as())); - - exit_act = new QAction(tr("E&xit"), this); - exit_act->setIcon(QIcon(":/icons/exit.png")); - exit_act->setShortcut(Qt::CTRL + Qt::Key_Q); - exit_act->setStatusTip(tr("Exit the parameterGUI application")); - connect(exit_act, SIGNAL(triggered()), this, SLOT(close())); - - about_act = new QAction(tr("&About"), this); - about_act->setIcon(QIcon(":/icons/idea.png")); - about_act->setStatusTip(tr("Show the parameterGUI About box")); - connect(about_act, SIGNAL(triggered()), this, SLOT(about())); - - about_qt_act = new QAction(tr("About &Qt"), this); - about_qt_act->setStatusTip(tr("Show the Qt library's About box")); - connect(about_qt_act, SIGNAL(triggered()), qApp, SLOT(aboutQt())); -} + void MainWindow::create_actions() + { + open_act = new QAction(tr("&Open..."), this); // create actions + open_act->setIcon(QIcon(":/icons/fileopen.png")); // and set icons + open_act->setShortcut(Qt::CTRL + Qt::Key_O); // set a short cut + open_act->setStatusTip(tr("Open a XML file")); // set a status tip + connect(open_act, SIGNAL(triggered()), this, SLOT(open())); // and connect + + save_act = new QAction(tr("&Save ..."), this); + save_act->setIcon(QIcon(":/icons/filesave.png")); + save_act->setShortcut(Qt::CTRL + Qt::Key_S); + save_act->setStatusTip(tr("Save the current XML file")); + connect(save_act, SIGNAL(triggered()), this, SLOT(save())); + + save_as_act = new QAction(tr("&Save As..."), this); + save_as_act->setIcon(QIcon(":/icons/filesaveas.png")); + save_as_act->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Q); + save_as_act->setStatusTip(tr("Save the current XML file as")); + connect(save_as_act, SIGNAL(triggered()), this, SLOT(save_as())); + + exit_act = new QAction(tr("E&xit"), this); + exit_act->setIcon(QIcon(":/icons/exit.png")); + exit_act->setShortcut(Qt::CTRL + Qt::Key_Q); + exit_act->setStatusTip(tr("Exit the parameterGUI application")); + connect(exit_act, SIGNAL(triggered()), this, SLOT(close())); + + about_act = new QAction(tr("&About"), this); + about_act->setIcon(QIcon(":/icons/idea.png")); + about_act->setStatusTip(tr("Show the parameterGUI About box")); + connect(about_act, SIGNAL(triggered()), this, SLOT(about())); + + about_qt_act = new QAction(tr("About &Qt"), this); + about_qt_act->setStatusTip(tr("Show the Qt library's About box")); + connect(about_qt_act, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + } -void MainWindow::create_menus() -{ - file_menu = menuBar()->addMenu(tr("&File")); // create a file menu - file_menu->addAction(open_act); // and add actions - file_menu->addAction(save_act); - file_menu->addAction(save_as_act); - file_menu->addAction(exit_act); + void MainWindow::create_menus() + { + file_menu = menuBar()->addMenu(tr("&File")); // create a file menu + file_menu->addAction(open_act); // and add actions + file_menu->addAction(save_act); + file_menu->addAction(save_as_act); + file_menu->addAction(exit_act); - menuBar()->addSeparator(); + menuBar()->addSeparator(); - help_menu = menuBar()->addMenu(tr("&Help")); // create a help menu - help_menu->addAction(about_act); - help_menu->addAction(about_qt_act); -} + help_menu = menuBar()->addMenu(tr("&Help")); // create a help menu + help_menu->addAction(about_act); + help_menu->addAction(about_qt_act); + } -bool MainWindow::maybe_save() -{ - if (isWindowModified()) // if content was modified + bool MainWindow::maybe_save() { - QMessageBox::StandardButton ret; // ask, if content should be saved - ret = QMessageBox::warning(this, tr("parameterGUI"), - tr("The content has been modified.\n" - "Do you want to save your changes?"), - QMessageBox::Save | QMessageBox::Discard |QMessageBox::Cancel); - - if (ret == QMessageBox::Save) - return save(); - else if (ret == QMessageBox::Cancel) - return false; - }; - - return true; -} - + if (isWindowModified()) // if content was modified + { + QMessageBox::StandardButton ret; // ask, if content should be saved + ret = QMessageBox::warning(this, tr("parameterGUI"), + tr("The content has been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Save | QMessageBox::Discard |QMessageBox::Cancel); + + if (ret == QMessageBox::Save) + return save(); + else if (ret == QMessageBox::Cancel) + return false; + }; + + return true; + } -bool MainWindow::save_file(const QString &filename) -{ - QFile file(filename); - if (!file.open(QFile::WriteOnly | QFile::Text)) // open a file dialog + bool MainWindow::save_file(const QString &filename) { - QMessageBox::warning(this, tr("parameterGUI"), - tr("Cannot write file %1:\n%2.") - .arg(filename) - .arg(file.errorString())); - return false; - }; + QFile file(filename); - XMLParameterWriter xml_writer(tree_widget); // create a xml_writer + if (!file.open(QFile::WriteOnly | QFile::Text)) // open a file dialog + { + QMessageBox::warning(this, tr("parameterGUI"), + tr("Cannot write file %1:\n%2.") + .arg(filename) + .arg(file.errorString())); + return false; + }; - if (!xml_writer.write_xml_file(&file)) // and read the xml file - return false; + XMLParameterWriter xml_writer(tree_widget); // create a xml_writer - statusBar()->showMessage(tr("File saved"), 2000); // if we succeed, show a message - set_current_file(filename); // and reset the window + if (!xml_writer.write_xml_file(&file)) // and read the xml file + return false; - return true; -} + statusBar()->showMessage(tr("File saved"), 2000); // if we succeed, show a message + set_current_file(filename); // and reset the window + return true; + } -void MainWindow::load_file(const QString &filename) -{ - QFile file(filename); - if (!file.open(QFile::ReadOnly | QFile::Text)) // open the file + void MainWindow::load_file(const QString &filename) { - QMessageBox::warning(this, tr("parameterGUI"), - tr("Cannot read file %1:\n%2.") - .arg(filename) - .arg(file.errorString())); - return; - }; + QFile file(filename); + + if (!file.open(QFile::ReadOnly | QFile::Text)) // open the file + { + QMessageBox::warning(this, tr("parameterGUI"), + tr("Cannot read file %1:\n%2.") + .arg(filename) + .arg(file.errorString())); + return; + }; + + tree_widget->clear(); // clear the tree + + XMLParameterReader xml_reader(tree_widget); // and read the xml file + + if (!xml_reader.read_xml_file(&file)) + { + QMessageBox::warning(this, tr("parameterGUI"), + tr("Parse error in file %1:\n\n%2") + .arg(filename) + .arg(xml_reader.error_string())); + } + else + { + statusBar()->showMessage(tr("File loaded - Start editing by double-clicking or hitting F2"), 25000); + set_current_file(filename); // show a message and set current file + + show_message (); // show some informations how values can be edited + }; + } - tree_widget->clear(); // clear the tree - XMLParameterReader xml_reader(tree_widget); // and read the xml file - if (!xml_reader.read_xml_file(&file)) + void MainWindow::set_current_file(const QString &filename) { - QMessageBox::warning(this, tr("parameterGUI"), - tr("Parse error in file %1:\n\n%2") - .arg(filename) - .arg(xml_reader.error_string())); + // We use the windowModified mechanism from the + // QMainWindow class to indicate in the window title, + // if the content was modified. + // If there is "[*]" in the window title, a * will + // added automatically at this position, if the + // window was modified. + // We set the window title to + // file_name[*] - XMLParameterHandler + + current_file = filename; // set the (global) current file to file_name + + std::string win_title = (filename.toStdString()); // and create the window title, + + if (current_file.isEmpty()) // if file_name is empty + win_title = "[*]parameterGUI"; // set the title to our application name, + else + win_title += "[*] - parameterGUI"; // if there is a file_name, add the + // the file_name and a minus to the title + + setWindowTitle(tr(win_title.c_str())); // set the window title + setWindowModified(false); // and reset window modified } - else - { - statusBar()->showMessage(tr("File loaded - Start editing by double-clicking or hitting F2"), 25000); - set_current_file(filename); // show a message and set current file - - show_message (); // show some informations how values can be edited - }; -} - - - -void MainWindow::set_current_file(const QString &filename) -{ - // We use the windowModified mechanism from the - // QMainWindow class to indicate in the window title, - // if the content was modified. - // If there is "[*]" in the window title, a * will - // added automatically at this position, if the - // window was modified. - // We set the window title to - // file_name[*] - XMLParameterHandler - - current_file = filename; // set the (global) current file to file_name - - std::string win_title = (filename.toStdString()); // and create the window title, - - if (current_file.isEmpty()) // if file_name is empty - win_title = "[*]parameterGUI"; // set the title to our application name, - else - win_title += "[*] - parameterGUI"; // if there is a file_name, add the - // the file_name and a minus to the title - - setWindowTitle(tr(win_title.c_str())); // set the window title - setWindowModified(false); // and reset window modified + } } - diff --git a/deal.II/contrib/parameter_gui/mainwindow.h b/deal.II/contrib/parameter_gui/mainwindow.h index 03dfde0a94..54deeae047 100644 --- a/deal.II/contrib/parameter_gui/mainwindow.h +++ b/deal.II/contrib/parameter_gui/mainwindow.h @@ -1,3 +1,13 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #ifndef MAINWINDOW_H #define MAINWINDOW_H @@ -8,150 +18,161 @@ #include #include "info_message.h" -#include "parameter_delegate.h" -#include "xml_parameter_reader.h" -#include "xml_parameter_writer.h" + +namespace dealii +{ +/*! @addtogroup ParameterGui + *@{ + */ + namespace ParameterGui + { /** * The MainWindow class of the the parameterGUI. * The parameterGUI is a graphical user interface for editing parameter files based on the XML format, - * created by the ParameterHandler::print_parameters() function with ParameterHandler::XML as second argument. - * Please see @ref Representation of Parameters in the documentation of the @ref ParameterHandler class for more details. + * created by the @ref ParameterHandler::print_parameters() function with @ref ParameterHandler::XML as second argument. + * Please see Representation of Parameters in the documentation of the @ref ParameterHandler class for more details. * The MainWindow class provides the basic functionality of the GUI as save- and load-file-actions and documentation. * The parameterGUI provides special editors for the different types of parameters defined in the ParameterHandler class. * - * @ingroup gui - * @author Martin Steigemann, Wolfgang Bangerth, December 2010 + * @note This class is used in the graphical user interface for the @ref ParameterHandler class. + * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. + * + * @ingroup ParameterGui + * @author Martin Steigemann, Wolfgang Bangerth, 2010 */ -class MainWindow : public QMainWindow -{ - Q_OBJECT + class MainWindow : public QMainWindow + { + Q_OBJECT - public: + public: /** * Constructor. - * If a filename is given, + * If a @p filename is given, * the MainWindow tries to open * and parse the file. */ - MainWindow(const QString &filename = ""); + MainWindow(const QString &filename = ""); - protected: + protected: /** * Reimplemented from QMainWindow. * We ask, if changes should be saved. */ - void closeEvent(QCloseEvent *event); + void closeEvent(QCloseEvent *event); - private slots: + private slots: /** * Open a parameter file. */ - void open(); + void open(); /** * Save the parameter file. */ - bool save(); + bool save(); /** * Open a file dialog to save the parameter file. */ - bool save_as(); + bool save_as(); /** * Show some information on the parameterGUI */ - void about(); + void about(); /** * A slot that should be always called, * if parameter values were changed. */ - void tree_was_modified(); + void tree_was_modified(); - private: + private: /** * Show an information dialog, how * parameters can be edited. */ - void show_message (); + void show_message (); /** * This function creates all actions. */ - void create_actions(); + void create_actions(); /** * This function creates all menus. */ - void create_menus(); + void create_menus(); /** * This function checks, if parameters were changed * and show a dialog, if changes should be saved. * This function should be always called, * before open a new parameter file or before closing the GUI */ - bool maybe_save (); + bool maybe_save (); /** - * Save parameters to filename in XML format. + * Save parameters to @p filename in XML format. */ - bool save_file (const QString &filename); + bool save_file (const QString &filename); /** - * Load parameters from filename in XML format. + * Load parameters from @p filename in XML format. */ - void load_file (const QString &filename); + void load_file (const QString &filename); /** - * This functions writes the current filename to the window title. + * This functions writes the current @p filename to the window title. */ - void set_current_file (const QString &filename); + void set_current_file (const QString &filename); /** * This is the tree structure in which we store all parameters. */ - QTreeWidget * tree_widget; + QTreeWidget * tree_widget; /** * This menu provides all file actions as open, save, save as * and exit */ - QMenu * file_menu; + QMenu * file_menu; /** * This menu provides some informations about the parameterGUI * and about Qt */ - QMenu * help_menu; + QMenu * help_menu; /** * QAction open a file. */ - QAction * open_act; + QAction * open_act; /** * QAction save a file. */ - QAction * save_act; + QAction * save_act; /** * QAction save as a file. */ - QAction * save_as_act; + QAction * save_as_act; /** * QAction exit the GUI. */ - QAction * exit_act; + QAction * exit_act; /** * QAction about the parameterGUI. */ - QAction * about_act; + QAction * about_act; /** * QAction about Qt. */ - QAction * about_qt_act; + QAction * about_qt_act; /** * This value stores the current filename we work on. */ - QString current_file; + QString current_file; /** * This dialog shows a short information message after loading a file. */ - InfoMessage * info_message; + InfoMessage * info_message; /** * An object for storing user settings. */ - QSettings * gui_settings; -}; + QSettings * gui_settings; + }; + } +/**@}*/ +} #endif diff --git a/deal.II/contrib/parameter_gui/parameter_delegate.cpp b/deal.II/contrib/parameter_gui/parameter_delegate.cpp index da28c2aa94..ec7106f526 100644 --- a/deal.II/contrib/parameter_gui/parameter_delegate.cpp +++ b/deal.II/contrib/parameter_gui/parameter_delegate.cpp @@ -1,27 +1,43 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #include #include "parameter_delegate.h" +#include -ParameterDelegate::ParameterDelegate(const int value_column, QObject *parent) - : QItemDelegate(parent) + +namespace dealii { - this->value_column = value_column; + namespace ParameterGui + { + ParameterDelegate::ParameterDelegate(const int value_column, QObject *parent) + : QItemDelegate(parent) + { + this->value_column = value_column; - double_steps = 0.1; // any click in the editor will increase or decrease the value about double_steps - double_decimals = 14; // number of decimals shown in the editor + double_steps = 0.1; // any click in the editor will increase or decrease the value about double_steps + double_decimals = 14; // number of decimals shown in the editor - int_steps = 1; // step value for increasing or decrasing integers -} + int_steps = 1; // step value for increasing or decrasing integers + } -QSize ParameterDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - if (index.column() == value_column) + QSize ParameterDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - return QSize(400,30); // we increase the height of all lines to show editors + if (index.column() == value_column) + { + return QSize(400,30); // we increase the height of all lines to show editors /* QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description @@ -36,271 +52,273 @@ QSize ParameterDelegate::sizeHint(const QStyleOptionViewItem &option, const QMod return QItemDelegate::sizeHint(option, index); */ + } + else + return QItemDelegate::sizeHint(option, index); } - else - return QItemDelegate::sizeHint(option, index); -} -void ParameterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - if (index.column() == value_column) + void ParameterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description + if (index.column() == value_column) + { + QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description // stored in the StatusLine - QRegExp rx_string("\\b(FileName|DirectoryName)\\b"); // if the type is Filename + QRegExp rx_string("\\b(FileName|DirectoryName)\\b"); // if the type is Filename // or DirectoryName - if (rx_string.indexIn (pattern_description) != -1) - { - QString value = index.model()->data(index, Qt::DisplayRole).toString(); // take the value + if (rx_string.indexIn (pattern_description) != -1) + { + QString value = index.model()->data(index, Qt::DisplayRole).toString(); // take the value - QStyleOptionViewItem my_option = option; // load options - my_option.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; + QStyleOptionViewItem my_option = option; // load options + my_option.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; - drawDisplay(painter, my_option, my_option.rect, value); // print the text in the display - drawFocus(painter, my_option, my_option.rect); // if the line has the + drawDisplay(painter, my_option, my_option.rect, value); // print the text in the display + drawFocus(painter, my_option, my_option.rect); // if the line has the // focus, print a rectangle + } + else + QItemDelegate::paint(painter, option, index); // for all other types use + // the standard delegate } else - QItemDelegate::paint(painter, option, index); // for all other types use - // the standard delegate + QItemDelegate::paint(painter, option, index); } - else - QItemDelegate::paint(painter, option, index); -} -QWidget *ParameterDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - if (index.column() == value_column) + QWidget *ParameterDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem &option, + const QModelIndex &index) const { - QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description - // stored in the StatusLine - QRegExp rx_string("\\b(Anything|MultipleSelection|List)\\b"), - rx_filename("\\b(FileName)\\b"), - rx_dirname("\\b(DirectoryName)\\b"), - rx_integer("\\b(Integer)\\b"), - rx_double("\\b(Double|Float|Floating)\\b"), - rx_selection("\\b(Selection)\\b"), - rx_bool("\\b(Bool)\\b"); - - if (rx_string.indexIn (pattern_description) != -1) // if the type "Anything" + if (index.column() == value_column) { - QLineEdit * line_editor = new QLineEdit(parent); // choose a LineEditor + QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description + // stored in the StatusLine + QRegExp rx_string("\\b(Anything|MultipleSelection|List)\\b"), + rx_filename("\\b(FileName)\\b"), + rx_dirname("\\b(DirectoryName)\\b"), + rx_integer("\\b(Integer)\\b"), + rx_double("\\b(Double|Float|Floating)\\b"), + rx_selection("\\b(Selection)\\b"), + rx_bool("\\b(Bool)\\b"); + + if (rx_string.indexIn (pattern_description) != -1) // if the type is "Anything" + { + QLineEdit * line_editor = new QLineEdit(parent); // choose a LineEditor - connect(line_editor, SIGNAL(editingFinished()), // connect editors signal - this, SLOT(commit_and_close_editor())); // to the closer function + connect(line_editor, SIGNAL(editingFinished()), // and connect editors signal + this, SLOT(commit_and_close_editor())); // to the closer function - return line_editor; - } - else if (rx_filename.indexIn (pattern_description) != -1) // if the type "FileName" - { - BrowseLineEdit * filename_editor // choose a BrowseLineEditor - = new BrowseLineEdit(BrowseLineEdit::file, parent); + return line_editor; + } + else if (rx_filename.indexIn (pattern_description) != -1) // if the type is "FileName" + { + BrowseLineEdit * filename_editor = // choose a BrowseLineEditor + new BrowseLineEdit(BrowseLineEdit::file, parent); - connect(filename_editor, SIGNAL(editingFinished()), - this, SLOT(commit_and_close_editor())); + connect(filename_editor, SIGNAL(editingFinished()), + this, SLOT(commit_and_close_editor())); - return filename_editor; - } - else if (rx_dirname.indexIn (pattern_description) != -1) // if the type "DirectoryName" - { - BrowseLineEdit * dirname_editor // choose a BrowseLineEditor - = new BrowseLineEdit(BrowseLineEdit::directory, parent); + return filename_editor; + } + else if (rx_dirname.indexIn (pattern_description) != -1) // if the type is "DirectoryName" + { + BrowseLineEdit * dirname_editor = // choose a BrowseLineEditor + new BrowseLineEdit(BrowseLineEdit::directory, parent); - connect(dirname_editor, SIGNAL(editingFinished()), - this, SLOT(commit_and_close_editor())); + connect(dirname_editor, SIGNAL(editingFinished()), + this, SLOT(commit_and_close_editor())); - return dirname_editor; - } - else if (rx_integer.indexIn (pattern_description) != -1) // if the tpye is "Integer" - { - QSpinBox * spin_box = new QSpinBox(parent); // choose a spin box + return dirname_editor; + } + else if (rx_integer.indexIn (pattern_description) != -1) // if the tpye is "Integer" + { + QSpinBox * spin_box = new QSpinBox(parent); // choose a spin box - const int min_int_value = std::numeric_limits::min(); - const int max_int_value = std::numeric_limits::max(); + const int min_int_value = std::numeric_limits::min(); + const int max_int_value = std::numeric_limits::max(); - spin_box->setMaximum(max_int_value); // set max and min from the limits.h class - spin_box->setMinimum(min_int_value); - spin_box->setSingleStep(int_steps); // and every klick is a SingleStep + spin_box->setMaximum(max_int_value); // set max and min from the limits.h class + spin_box->setMinimum(min_int_value); + spin_box->setSingleStep(int_steps); // and every klick is a SingleStep - connect(spin_box, SIGNAL(editingFinished()), // connect editors signal to the closer function - this, SLOT(commit_and_close_editor())); + connect(spin_box, SIGNAL(editingFinished()), // connect editors signal to the closer function + this, SLOT(commit_and_close_editor())); - return spin_box; - } - else if (rx_double.indexIn (pattern_description) != -1) // the same with "Double" - { - QDoubleSpinBox * double_spin_box = new QDoubleSpinBox(parent); // choose a spin box + return spin_box; + } + else if (rx_double.indexIn (pattern_description) != -1) // the same with "Double" + { + QDoubleSpinBox * double_spin_box = new QDoubleSpinBox(parent); // choose a spin box - const double min_double_value = -std::numeric_limits::max(); - const double max_double_value = std::numeric_limits::max(); + const double min_double_value = -std::numeric_limits::max(); + const double max_double_value = std::numeric_limits::max(); - double_spin_box->setMaximum(max_double_value); // set max and min from the limits.h class - double_spin_box->setMinimum(min_double_value); - double_spin_box->setDecimals(double_decimals); // show "double_decimals" decimals - double_spin_box->setSingleStep(double_steps); // and every klick is a SingleStep + double_spin_box->setMaximum(max_double_value); // set max and min from the limits.h class + double_spin_box->setMinimum(min_double_value); + double_spin_box->setDecimals(double_decimals); // show "double_decimals" decimals + double_spin_box->setSingleStep(double_steps); // and every klick is a SingleStep - connect(double_spin_box, SIGNAL(editingFinished()), // connect editors signal to the closer function - this, SLOT(commit_and_close_editor())); + connect(double_spin_box, SIGNAL(editingFinished()), // connect editors signal to the closer function + this, SLOT(commit_and_close_editor())); - return double_spin_box; - } - else if (rx_selection.indexIn (pattern_description) != -1) // and selections - { - QComboBox * combo_box = new QComboBox(parent); // we assume, that pattern_desctiption is of the form - // "Type: [Selection item1|item2| ....|item ] " - std::vector choices; // list with the different items - std::string tmp(pattern_description.toStdString()); + return double_spin_box; + } + else if (rx_selection.indexIn (pattern_description) != -1) // and selections + { + QComboBox * combo_box = new QComboBox(parent); // we assume, that pattern_desctiption is of the form + // "Type: [Selection item1|item2| ....|item ] " + std::vector choices; // list with the different items + std::string tmp(pattern_description.toStdString()); - if (tmp.find("[") != std::string::npos) // delete all char before [ - tmp.erase (0, tmp.find("[")+1); + if (tmp.find("[") != std::string::npos) // delete all char before [ + tmp.erase (0, tmp.find("[")+1); - if (tmp.find("]") != std::string::npos) // delete all char after ] - tmp.erase (tmp.find("]"),tmp.length()); + if (tmp.find("]") != std::string::npos) // delete all char after ] + tmp.erase (tmp.find("]"),tmp.length()); - if (tmp.find(" ") != std::string::npos) // delete all char before " " - tmp.erase (0, tmp.find(" ")+1); + if (tmp.find(" ") != std::string::npos) // delete all char before " " + tmp.erase (0, tmp.find(" ")+1); - while (tmp.find('|') != std::string::npos) // extract items - { - choices.push_back(std::string(tmp, 0, tmp.find('|'))); - tmp.erase (0, tmp.find('|')+1); - }; + while (tmp.find('|') != std::string::npos) // extract items + { + choices.push_back(std::string(tmp, 0, tmp.find('|'))); + tmp.erase (0, tmp.find('|')+1); + }; - if (tmp.find(" ") != std::string::npos) // delete " " - tmp.erase (tmp.find(" ")); + if (tmp.find(" ") != std::string::npos) // delete " " + tmp.erase (tmp.find(" ")); - choices.push_back(tmp); // add last item + choices.push_back(tmp); // add last item - for (unsigned int i=0; iaddItem (tr(choices[i].c_str()), tr(choices[i].c_str())); + for (unsigned int i=0; iaddItem (tr(choices[i].c_str()), tr(choices[i].c_str())); - combo_box->setEditable(false); + combo_box->setEditable(false); - connect(combo_box, SIGNAL(currentIndexChanged(int)), // connect editors signal to the closer function - this, SLOT(commit_and_close_editor())); + connect(combo_box, SIGNAL(currentIndexChanged(int)), // connect editors signal to the closer function + this, SLOT(commit_and_close_editor())); - return combo_box; - } - else if (rx_bool.indexIn (pattern_description) != -1) // and booleans - { - QComboBox * combo_box = new QComboBox(parent); + return combo_box; + } + else if (rx_bool.indexIn (pattern_description) != -1) // and booleans + { + QComboBox * combo_box = new QComboBox(parent); - std::vector choices; // list with the different items - choices.push_back(std::string("true")); // add true - choices.push_back(std::string("false")); // and false + std::vector choices; // list with the different items + choices.push_back(std::string("true")); // add true + choices.push_back(std::string("false")); // and false - for (unsigned int i=0; iaddItem (tr(choices[i].c_str()), tr(choices[i].c_str())); + for (unsigned int i=0; iaddItem (tr(choices[i].c_str()), tr(choices[i].c_str())); - combo_box->setEditable(false); + combo_box->setEditable(false); - connect(combo_box, SIGNAL(currentIndexChanged(int)), // connect editors signal to the closer function - this, SLOT(commit_and_close_editor())); + connect(combo_box, SIGNAL(currentIndexChanged(int)), // connect editors signal to the closer function + this, SLOT(commit_and_close_editor())); - return combo_box; - } - else - { - return QItemDelegate::createEditor(parent, option, index); + return combo_box; + } + else + { + return QItemDelegate::createEditor(parent, option, index); + }; }; - }; - return 0; // if it is not the column "parameter values", do nothing -} + return 0; // if it is not the column "parameter values", do nothing + } -void ParameterDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const -{ - if (index.column() == value_column) + void ParameterDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { - QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description + if (index.column() == value_column) + { + QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description // stored in the StatusLine - QRegExp rx_filename("\\b(FileName)\\b"), - rx_dirname("\\b(DirectoryName)\\b"), - rx_selection("\\b(Selection)\\b"); + QRegExp rx_filename("\\b(FileName)\\b"), + rx_dirname("\\b(DirectoryName)\\b"), + rx_selection("\\b(Selection)\\b"); - if (rx_filename.indexIn (pattern_description) != -1) // if the type is "FileName" - { - QString file_name = index.data(Qt::DisplayRole).toString(); + if (rx_filename.indexIn (pattern_description) != -1) // if the type is "FileName" + { + QString file_name = index.data(Qt::DisplayRole).toString(); - BrowseLineEdit *filename_editor = qobject_cast(editor); // set the text of the editor - filename_editor->setText(file_name); - } - else if (rx_dirname.indexIn (pattern_description) != -1) // if the type is "DirectoryName" - { - QString dir_name = index.data(Qt::DisplayRole).toString(); + BrowseLineEdit *filename_editor = qobject_cast(editor); // set the text of the editor + filename_editor->setText(file_name); + } + else if (rx_dirname.indexIn (pattern_description) != -1) // if the type is "DirectoryName" + { + QString dir_name = index.data(Qt::DisplayRole).toString(); - BrowseLineEdit *dirname_editor = qobject_cast(editor); // set the text of the editor - dirname_editor->setText(dir_name); - } - else if (rx_selection.indexIn (pattern_description) != -1) // if we have a combo box, - { - QRegExp rx(index.data(Qt::DisplayRole).toString()); + BrowseLineEdit *dirname_editor = qobject_cast(editor); // set the text of the editor + dirname_editor->setText(dir_name); + } + else if (rx_selection.indexIn (pattern_description) != -1) // if we have a combo box, + { + QRegExp rx(index.data(Qt::DisplayRole).toString()); - QComboBox * combo_box = qobject_cast(editor); + QComboBox * combo_box = qobject_cast(editor); - for (int i=0; icount(); ++i) // we look, which index - if (rx.exactMatch(combo_box->itemText(i))) // the data has and set - combo_box->setCurrentIndex(i); // it to the combo_box - } - else - QItemDelegate::setEditorData(editor, index); // if it is not FileName, - // DirectoryName or Selection - // use the standard delegate - }; -} + for (int i=0; icount(); ++i) // we look, which index + if (rx.exactMatch(combo_box->itemText(i))) // the data has and set + combo_box->setCurrentIndex(i); // it to the combo_box + } + else + QItemDelegate::setEditorData(editor, index); // if it is not FileName, + // DirectoryName or Selection + // use the standard delegate + }; + } -void ParameterDelegate::commit_and_close_editor() -{ - QWidget * editor = qobject_cast(sender()); - emit commitData(editor); - emit closeEditor(editor); -} + void ParameterDelegate::commit_and_close_editor() + { + QWidget * editor = qobject_cast(sender()); + emit commitData(editor); + emit closeEditor(editor); + } -void ParameterDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const -{ - if (index.column() == value_column) + void ParameterDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const { - QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description + if (index.column() == value_column) + { + QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description // stored in the StatusLine - QRegExp rx_filename("\\b(FileName)\\b"), - rx_dirname("\\b(DirectoryName)\\b"), - rx_selection("\\b(Selection)\\b"); + QRegExp rx_filename("\\b(FileName)\\b"), + rx_dirname("\\b(DirectoryName)\\b"), + rx_selection("\\b(Selection)\\b"); - if (rx_filename.indexIn (pattern_description) != -1) // if the type is "FileName" - { - BrowseLineEdit * filename_editor = qobject_cast(editor); // set the text from the editor - QString value = filename_editor->text(); - model->setData(index, value); - } - else if (rx_dirname.indexIn (pattern_description) != -1) // if the type is "DirectoryName" - { - BrowseLineEdit * dirname_editor = qobject_cast(editor); // set the text from the editor - QString value = dirname_editor->text(); - model->setData(index, value); - } - else if (rx_selection.indexIn (pattern_description) != -1) // if the type is "Selection" - { - QComboBox * combo_box = qobject_cast(editor); // set the text from the editor - QString value = combo_box->currentText(); - model->setData(index, value); - } - else - QItemDelegate::setModelData(editor, model, index); // if it is not FileName or DirectoryName, + if (rx_filename.indexIn (pattern_description) != -1) // if the type is "FileName" + { + BrowseLineEdit * filename_editor = qobject_cast(editor); // set the text from the editor + QString value = filename_editor->text(); + model->setData(index, value); + } + else if (rx_dirname.indexIn (pattern_description) != -1) // if the type is "DirectoryName" + { + BrowseLineEdit * dirname_editor = qobject_cast(editor); // set the text from the editor + QString value = dirname_editor->text(); + model->setData(index, value); + } + else if (rx_selection.indexIn (pattern_description) != -1) // if the type is "Selection" + { + QComboBox * combo_box = qobject_cast(editor); // set the text from the editor + QString value = combo_box->currentText(); + model->setData(index, value); + } + else + QItemDelegate::setModelData(editor, model, index); // if it is not FileName or DirectoryName, // use the standard delegate - }; + }; + } + } } diff --git a/deal.II/contrib/parameter_gui/parameter_delegate.h b/deal.II/contrib/parameter_gui/parameter_delegate.h index 654dca4e82..a4bcb2b98f 100644 --- a/deal.II/contrib/parameter_gui/parameter_delegate.h +++ b/deal.II/contrib/parameter_gui/parameter_delegate.h @@ -1,3 +1,13 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #ifndef PARAMETERDELEGATE_H #define PARAMETERDELEGATE_H @@ -9,88 +19,99 @@ #include #include -#include -#include - #include "browse_lineedit.h" +namespace dealii +{ +/*! @addtogroup ParameterGui + *@{ + */ + namespace ParameterGui + { /** * The ParameterDelegate class implements special delegates for the QTreeWidget class used in the parameterGUI. * The QTreeWidget class provides some different standard delegates for editing parameters shown in the * tree structure. The ParameterDelegate class provides special editors for the different types of parameters defined in - * the ParameterHandler class. For all parameter types based on strings as "Anything", "MultipleSelection" and - * "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 - * "Selection" type parameters a combo box will be shown up. For parameters of type "FileName" and "DirectoryName" + * the ParameterHandler class. For all parameter types based on strings as "Anything", "MultipleSelection" and + * "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 + * "Selection" type parameters a combo box will be shown up. For parameters of type "FileName" and "DirectoryName" * the delegate shows a @ref BrowseLineEdit editor. The column of the tree structure with the parameter values has to be set * in the constructor. * - * @ingroup gui - * @author Martin Steigemann, Wolfgang Bangerth, December 2010 + * @note This class is used in the graphical user interface for the @ref ParameterHandler class. + * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. + * + * @ingroup ParameterGui + * @author Martin Steigemann, Wolfgang Bangerth, 2010 */ -class ParameterDelegate : public QItemDelegate -{ - Q_OBJECT + class ParameterDelegate : public QItemDelegate + { + Q_OBJECT - public: + public: /** - * Constructor, the value_column specifies the column + * Constructor, @p value_column specifies the column * of the parameter tree this delegate will be used on. */ - ParameterDelegate (const int value_column, QObject *parent = 0); + ParameterDelegate (const int value_column, QObject *parent = 0); /** * This function creates the appropriate editor for the parameter * based on the index. */ - QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const; + QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; /** * Reimplemented from QItemDelegate. */ - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; /** * Reimplemented from QItemDelegate. */ - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; /** * Reimplemented from QItemDelegate. */ - void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; /** * Reimplemented from QItemDelegate. */ - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; - private slots: + private slots: /** * Reimplemented from QItemDelegate. */ - void commit_and_close_editor(); + void commit_and_close_editor(); - private: + private: /** * The column this delegate will be used on. */ - int value_column; + int value_column; /** * For parameters of type double a spin box * will be shown as editor. Any click on the spin box * will change the value about double_steps. */ - double double_steps; + double double_steps; /** * For parameters of type integer a spin box * will be shown as editor. Any click on the spin box * will change the value about int_steps. */ - unsigned int int_steps; + unsigned int int_steps; /** * For parameters of type double a spin box * will be shown as editor. The spin box will show * parameters with a precision of double_decimals. */ - unsigned int double_decimals; -}; + unsigned int double_decimals; + }; + } +/**@}*/ +} + #endif diff --git a/deal.II/contrib/parameter_gui/parameters.xml b/deal.II/contrib/parameter_gui/parameters.xml index fa4ff1c224..bdf3b3d02a 100644 --- a/deal.II/contrib/parameter_gui/parameters.xml +++ b/deal.II/contrib/parameter_gui/parameters.xml @@ -1,502 +1,2 @@ - - - - - Elasticity - Elasticity - Basic equation to solve - 0 - [Anything] - - - CtsSpecimen - Specimen - Domain - 1 - [Selection CtSpecimen|CtsSpecimen|SENBeam ] - - - 2 - 2 - Use this number of terms in asymptotic decompositions - 2 - [Selection 2|3|5 ] - - - false - false - Output grids in eps format - 3 - [Selection true|false ] - - - - - AluminiumAlloy7075T651 - AluminiumAlloy7075T651 - Description of the material: MaterialName|ReadMaterial - 4 - [Selection AluminiumAlloy7075T651|PlexiGlas|SuperAlloyPWA14801493|SihParisIrwinMaterialOne|SihParisIrwinMaterialTwo|CorticalBone|Beton|TestMaterial|ReadMaterial ] - - - Homogeneous - Homogeneous - Type of material: Homogeneous|Composite|FGM - 5 - [Selection Homogeneous|Composite|FGM ] - - - 0 - 0. - Material angle with respect to the basic coordinate system - 6 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - plane_strain - plain_strain - Plane state: plane_strain|plane_stress - 7 - [Selection plane_strain|plain_stress ] - - - false - false - Scale elastic moduli to a11 = 1 and a22 = 1 - 8 - [Selection true|false ] - - - - TestMaterialProperties - ReadedMaterialProperties - Description of ReadMaterial - 9 - [Anything] - - - 108752.2388 - 1. - Elastic constant - 10 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 56023.8806 - 1. - Elastic constant - 11 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 108752.2388 - 1. - Elastic constant - 12 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 0 - 1. - Elastic constant - 13 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 0 - 1. - Elastic constant - 14 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 26364.1791 - 1. - Elastic constant - 15 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - - - AluminiumAlloy7075T651 - AluminiumAlloy7075T651 - Description of the material: MaterialName|ReadMaterial - 16 - [Selection AluminiumAlloy7075T651|PlexiGlas|SuperAlloyPWA14801493|SihParisIrwinMaterialOne|SihParisIrwinMaterialTwo|CorticalBone|Beton|TestMaterial|ReadMaterial ] - - - 108752.2388 - 1. - Elastic constant - 17 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 56023.8806 - 1. - Elastic constant - 18 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 108752.2388 - 1. - Elastic constant - 19 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 0 - 1. - Elastic constant - 20 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 0 - 1. - Elastic constant - 21 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 26364.1791 - 1. - Elastic constant - 22 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 0 - 0. - Material angle with respect to the basic coordinate system - 23 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 0.5 - 0. - Perturbation parameter - 24 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - - - - 10000 - 4500 - Applied force value in Newton - 25 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 0 - 0 - If the specimen allows different forces, this parameter can be used to control them - 26 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - - - da/dN-curve - da/dN-curve - - 27 - [Selection da/dN-curve|Paris-law|Forman-Mettu-equation ] - - - - 104.25 - 100 - - 28 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 972 - 1000 - - 29 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 0.1 - 0.1 - - 30 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 3 - 1 - - 31 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - - - 2.12e-11 - 1 - - 32 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 2.1 - 1 - - 33 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - - - 2.12e-11 - 1 - - 34 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 2.885 - 1 - - 35 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - -

- 0.5 - 1 - - 36 - [Double -1.79769e+308...1.79769e+308 (inclusive)] -

- - 1 - 1 - - 37 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - -
-
- - - 2 - 1. - - 38 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 1 - 2 - - 39 - [Integer range -2147483648...2147483647 (inclusive)] - - - 0.5 - 1 - - 40 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 0.25 - 0.25 - - 41 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - - - 250 - 100 - - 42 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 110 - 110. - - 43 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - -110 - -110. - - 44 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 180 - 180. - - 45 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - -180 - -180. - - 46 - [Double -1.79769e+308...1.79769e+308 (inclusive)] - - - 22 - 22 - - 47 - [Integer range -2147483648...2147483647 (inclusive)] - - - 36 - 36 - - 48 - [Integer range -2147483648...2147483647 (inclusive)] - - - false - false - - 49 - [Selection true|false ] - - - false - false - - 50 - [Selection true|false ] - - - 1 - 1 - - 51 - [Integer range -2147483648...2147483647 (inclusive)] - - - 25 - 10 - - 52 - [Integer range -2147483648...2147483647 (inclusive)] - - - true - true - - 53 - [Selection true|false ] - - - false - false - - 54 - [Selection true|false ] - - - - - 250000 - 10000 - - 55 - [Integer range -2147483648...2147483647 (inclusive)] - - - - - - /home/masteige/projects/mcrack2d/projects/test/meshes/mesh.ucd - /home/masteige/mcrack2d/projects/mesh.ucd - - 56 - [FileName (Type: input)] - - - /home/masteige/projects/mcrack2d/projects/test/crack_path.data - /home/masteige/mcrack2d/projects/crack_path.data - - 57 - [FileName (Type: input)] - - - /home/masteige/projects/mcrack2d/projects/test/matrix_M.data - /home/masteige/mcrack2d/projects/Matrix_M.data - - 58 - [FileName (Type: input)] - - - /home/masteige/projects/mcrack2d/projects/test/da_dN_curve.data - /home/masteige/mcrack2d/projects/da_dN_curve.data - - 59 - [FileName (Type: input)] - - - /home/masteige/projects/mcrack2d/projects/test/results.data - /home/masteige/mcrack2d/projects/results.data - - 60 - [FileName (Type: input)] - - - /home/masteige/projects/mcrack2d/scripts/extract_mesh.py - /home/masteige/mcrack2d/scripts/extract_mesh.py - - 61 - [FileName (Type: input)] - - - - - /home/masteige/projects/mcrack2d/material/ - /home/masteige/mcrack2d/materials - - 62 - [DirectoryName] - - - /home/masteige/projects/mcrack2d/projects/test/ - /home/masteige/mcrack2d/projects - - 63 - [DirectoryName] - - - /home/masteige/projects/mcrack2d/projects/test/graphics/ - /home/masteige/mcrack2d/projects/graphics - - 64 - [DirectoryName] - - - /home/masteige/projects/mcrack2d/projects/test/meshes/ - /home/masteige/mcrack2d/projects/meshes - - 65 - [DirectoryName] - - - /home/masteige/projects/mcrack2d/projects/test/results/ - /home/masteige/mcrack2d/projects/results - - 66 - [DirectoryName] - - - -
+ +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]
\ No newline at end of file diff --git a/deal.II/contrib/parameter_gui/xml_parameter_reader.cpp b/deal.II/contrib/parameter_gui/xml_parameter_reader.cpp index 7973c7b64e..115da80d12 100644 --- a/deal.II/contrib/parameter_gui/xml_parameter_reader.cpp +++ b/deal.II/contrib/parameter_gui/xml_parameter_reader.cpp @@ -1,25 +1,39 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #include #include "xml_parameter_reader.h" -XMLParameterReader::XMLParameterReader(QTreeWidget *tree_widget) - : tree_widget(tree_widget) +namespace dealii { - QStyle * style = tree_widget->style(); + namespace ParameterGui + { + XMLParameterReader::XMLParameterReader(QTreeWidget *tree_widget) + : tree_widget(tree_widget) + { + QStyle * style = tree_widget->style(); - subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off); - subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); + subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off); + subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); - parameter_icon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); -} + parameter_icon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); + } -bool XMLParameterReader::read_xml_file(QIODevice *device) -{ - xml.setDevice(device); + bool XMLParameterReader::read_xml_file(QIODevice *device) + { + xml.setDevice(device); // We look for a StartElement "ParameterHandler" // and start parsing after this. @@ -29,52 +43,52 @@ bool XMLParameterReader::read_xml_file(QIODevice *device) // // - while (xml.readNext() != QXmlStreamReader::Invalid) - { - if (xml.isStartElement()) - if (xml.name() == "ParameterHandler") - { - parse_parameters(); + while (xml.readNext() != QXmlStreamReader::Invalid) + { + if (xml.isStartElement()) + if (xml.name() == "ParameterHandler") + { + parse_parameters(); - return !xml.error();; - }; - }; + return !xml.error();; + }; + }; - xml.raiseError(QObject::tr("The file is not an ParameterHandler XML file.")); + xml.raiseError(QObject::tr("The file is not an ParameterHandler XML file.")); - return !xml.error(); -} + return !xml.error(); + } -QString XMLParameterReader::error_string() const -{ - return QObject::tr("%1\nLine %2, column %3") - .arg(xml.errorString()) - .arg(xml.lineNumber()) - .arg(xml.columnNumber()); -} + QString XMLParameterReader::error_string() const + { + return QObject::tr("%1\nLine %2, column %3") + .arg(xml.errorString()) + .arg(xml.lineNumber()) + .arg(xml.columnNumber()); + } -void XMLParameterReader::parse_parameters() -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "ParameterHandler"); + void XMLParameterReader::parse_parameters() + { + Q_ASSERT(xml.isStartElement() && xml.name() == "ParameterHandler"); - while (xml.readNext() != QXmlStreamReader::Invalid) // go to the next - { // if it is the closing element of ParameterHandler, - if (xml.isEndElement() && xml.name() == "ParameterHandler") - break; // break the loop + while (xml.readNext() != QXmlStreamReader::Invalid) // go to the next + { // if it is the closing element of ParameterHandler, + if (xml.isEndElement() && xml.name() == "ParameterHandler") + break; // break the loop - if (xml.isStartElement()) // if it is a start element - read_subsection_element(0); // it must be a subsection or a parameter - }; -} + if (xml.isStartElement()) // if it is a start element + read_subsection_element(0); // it must be a subsection or a parameter + }; + } -void XMLParameterReader::read_subsection_element(QTreeWidgetItem *parent) -{ + void XMLParameterReader::read_subsection_element(QTreeWidgetItem *parent) + { // The structure of the parameter file is assumed to be of the form // // @@ -104,205 +118,205 @@ void XMLParameterReader::read_subsection_element(QTreeWidgetItem *parent) // and a parameter has the entries , , , // and - Q_ASSERT(xml.isStartElement()); // the actual element is + Q_ASSERT(xml.isStartElement()); // the actual element is - QTreeWidgetItem * subsection = create_child_item(parent); // create a new subsection in the tree + QTreeWidgetItem * subsection = create_child_item(parent); // create a new subsection in the tree - subsection->setIcon(0, subsection_icon); // set the icon, - subsection->setText(0, demangle(xml.name().toString())); // the name + subsection->setIcon(0, subsection_icon); // set the icon, + subsection->setText(0, demangle(xml.name().toString())); // the name - tree_widget->setItemExpanded(subsection, 0); // and the folder is not expanded + tree_widget->setItemExpanded(subsection, 0); // and the folder is not expanded - while (xml.readNext() != QXmlStreamReader::Invalid) // read the next element - { - if (xml.isEndElement()) // if the next element is , break the loop - break; - - if (xml.isStartElement()) // if it is a start element + while (xml.readNext() != QXmlStreamReader::Invalid) // read the next element { - if (xml.name() == "value") // it can be , then we have found a parameter, - { - subsection->setFlags(subsection->flags() | Qt::ItemIsEditable); // values can be edited, - read_parameter_element (subsection); - } - else // or it can be a new + if (xml.isEndElement()) // if the next element is , break the loop + break; + + if (xml.isStartElement()) // if it is a start element { - subsection->setFlags(subsection->flags() | Qt::NoItemFlags); // subsections can not be edited, - read_subsection_element (subsection); + if (xml.name() == "value") // it can be , then we have found a parameter, + { + subsection->setFlags(subsection->flags() | Qt::ItemIsEditable); // values can be edited, + read_parameter_element (subsection); + } + else // or it can be a new + { + subsection->setFlags(subsection->flags() | Qt::NoItemFlags); // subsections can not be edited, + read_subsection_element (subsection); + }; }; }; - }; -} + } -void XMLParameterReader::read_parameter_element(QTreeWidgetItem *parent) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "value"); // the actual element is , - // then we have found a parameter-item - QString value = xml.readElementText(); // read the element text - parent->setText(1, value); // and store as text to the item - parent->setIcon(0, parameter_icon); // change the icon of parent - - while (xml.readNext() != QXmlStreamReader::Invalid) // go to the next + void XMLParameterReader::read_parameter_element(QTreeWidgetItem *parent) { - if (xml.isStartElement()) - { - if (xml.isStartElement() && xml.name() == "default_value") // if it is - { - QString default_value = xml.readElementText(); // store it - parent->setText(2, default_value); - } - else if (xml.isStartElement() && xml.name() == "documentation") // if it is - { - QString documentation = xml.readElementText(); // store it - parent->setText(3, documentation); + Q_ASSERT(xml.isStartElement() && xml.name() == "value"); // the actual element is , + // then we have found a parameter-item + QString value = xml.readElementText(); // read the element text + parent->setText(1, value); // and store as text to the item + parent->setIcon(0, parameter_icon); // change the icon of parent - if (!documentation.isEmpty()) // if there is a documentation, - { - parent->setToolTip(0, "Documentation: " + documentation); // set Documentation as ToolTip for both columns - parent->setToolTip(1, "Documentation: " + documentation); - parent->setStatusTip(0, "Documentation: " + documentation); // and as StatusTip for the first column also - }; - } - else if (xml.isStartElement() && xml.name() == "pattern") // if it is - { - QString pattern = xml.readElementText(); // store it as text - parent->setText(4, pattern); // we only need this value - // for writing back to XML later - } - else if (xml.isStartElement() && xml.name() == "pattern_description") // if it is + while (xml.readNext() != QXmlStreamReader::Invalid) // go to the next { - QString pattern_description = xml.readElementText(); // store it as text - parent->setText(5, pattern_description); - // show the type and default - // in the StatusLine - parent->setStatusTip(1, "Type: " + pattern_description + " Default: " + parent->text(2)); - - // in order to store values as correct data types, - // we check the following types in the pattern_description: - - QRegExp rx_string("\\b(Anything|FileName|DirectoryName|Selection|List|MultipleSelection)\\b"), - rx_integer("\\b(Integer)\\b"), - rx_double("\\b(Float|Floating|Double)\\b"), - rx_bool("\\b(Selection true|false)\\b"); - - if (rx_string.indexIn (pattern_description) != -1) // the type "Anything" or "Filename" - { - QString value = parent->text(1); // store as a QString - - parent->setData(1, Qt::EditRole, value); // and set the data in the item - parent->setData(1, Qt::DisplayRole, value); - } - else if (rx_integer.indexIn (pattern_description) != -1) // if the tpye is "Integer" + if (xml.isStartElement()) { - QString text = parent->text(1); - - bool ok = true; - - int value = text.toInt(&ok); // we convert the string to int - - if (ok) // and store + if (xml.isStartElement() && xml.name() == "default_value") // if it is { - parent->setData(1, Qt::EditRole, value); - parent->setData(1, Qt::DisplayRole, value); + QString default_value = xml.readElementText(); // store it + parent->setText(2, default_value); } - else // otherwise raise an error - xml.raiseError(QObject::tr("Cannot convert integer type to integer!")); - } - else if (rx_double.indexIn (pattern_description) != -1) // the same with "Float" - { - QString text = parent->text(1); - - bool ok = true; - - double value = text.toDouble(&ok); - - if (ok) + else if (xml.isStartElement() && xml.name() == "documentation") // if it is { - parent->setData(1, Qt::EditRole, value); - parent->setData(1, Qt::DisplayRole, value); + QString documentation = xml.readElementText(); // store it + parent->setText(3, documentation); + + if (!documentation.isEmpty()) // if there is a documentation, + { + parent->setToolTip(0, "Documentation: " + documentation); // set Documentation as ToolTip for both columns + parent->setToolTip(1, "Documentation: " + documentation); + parent->setStatusTip(0, "Documentation: " + documentation); // and as StatusTip for the first column also + }; } - else - xml.raiseError(QObject::tr("Cannot convert double type to double!")); - }; - - if (rx_bool.indexIn (pattern_description) != -1) // and booleans - { - QRegExp test(parent->text(1)); + else if (xml.isStartElement() && xml.name() == "pattern") // if it is + { + QString pattern = xml.readElementText(); // store it as text + parent->setText(4, pattern); // we only need this value + // for writing back to XML later + } + else if (xml.isStartElement() && xml.name() == "pattern_description") // if it is + { + QString pattern_description = xml.readElementText(); // store it as text + parent->setText(5, pattern_description); + // show the type and default + // in the StatusLine + parent->setStatusTip(1, "Type: " + pattern_description + " Default: " + parent->text(2)); - bool value = true; + // in order to store values as correct data types, + // we check the following types in the pattern_description: - if (test.exactMatch("true")) - value = true; - else if (test.exactMatch("false")) - value = false; + QRegExp rx_string("\\b(Anything|FileName|DirectoryName|Selection|List|MultipleSelection)\\b"), + rx_integer("\\b(Integer)\\b"), + rx_double("\\b(Float|Floating|Double)\\b"), + rx_bool("\\b(Selection true|false)\\b"); + + if (rx_string.indexIn (pattern_description) != -1) // the type "Anything" or "Filename" + { + QString value = parent->text(1); // store as a QString + + parent->setData(1, Qt::EditRole, value); // and set the data in the item + parent->setData(1, Qt::DisplayRole, value); + } + else if (rx_integer.indexIn (pattern_description) != -1) // if the tpye is "Integer" + { + QString text = parent->text(1); + + bool ok = true; + + int value = text.toInt(&ok); // we convert the string to int + + if (ok) // and store + { + parent->setData(1, Qt::EditRole, value); + parent->setData(1, Qt::DisplayRole, value); + } + else // otherwise raise an error + xml.raiseError(QObject::tr("Cannot convert integer type to integer!")); + } + else if (rx_double.indexIn (pattern_description) != -1) // the same with "Float" + { + QString text = parent->text(1); + + bool ok = true; + + double value = text.toDouble(&ok); + + if (ok) + { + parent->setData(1, Qt::EditRole, value); + parent->setData(1, Qt::DisplayRole, value); + } + else + xml.raiseError(QObject::tr("Cannot convert double type to double!")); + }; + + if (rx_bool.indexIn (pattern_description) != -1) // and booleans + { + QRegExp test(parent->text(1)); + + bool value = true; + + if (test.exactMatch("true")) + value = true; + else if (test.exactMatch("false")) + value = false; + else + xml.raiseError(QObject::tr("Cannot convert boolen type to boolean!")); + + parent->setText(1, ""); // this is needed because we use + parent->setData(1, Qt::EditRole, value); // for booleans the standard + parent->setData(1, Qt::DisplayRole, value); // delegate + }; + + break; // and break the loop + } else - xml.raiseError(QObject::tr("Cannot convert boolen type to boolean!")); - - parent->setText(1, ""); // this is needed because we use - parent->setData(1, Qt::EditRole, value); // for booleans the standard - parent->setData(1, Qt::DisplayRole, value); // delegate - }; - - break; // and break the loop - } - else - { // if there is any other element, raise an error - xml.raiseError(QObject::tr("Incomplete or unknown Parameter!")); - break; // and break the loop - }; // here we assume the special structure - }; // of the parameter-file! - }; -} - + { // if there is any other element, raise an error + xml.raiseError(QObject::tr("Incomplete or unknown Parameter!")); + break; // and break the loop, here + }; // we assume the special structure + }; // of the parameter-file! + }; + } -QTreeWidgetItem *XMLParameterReader::create_child_item(QTreeWidgetItem *item) -{ - QTreeWidgetItem * child_item; // create a new child-item - if (item) - child_item = new QTreeWidgetItem(item); // if item is not empty, - else // append the new item as a child - child_item = new QTreeWidgetItem(tree_widget); // otherwise create a new item - // in the tree + QTreeWidgetItem *XMLParameterReader::create_child_item(QTreeWidgetItem *item) + { + QTreeWidgetItem * child_item; // create a new child-item - child_item->setData(0, Qt::DisplayRole, xml.name().toString()); // set xml.tag_name as data - child_item->setText(0, xml.name().toString()); // set xml.tag_name as data + if (item) + child_item = new QTreeWidgetItem(item); // if item is not empty, + else // append the new item as a child + child_item = new QTreeWidgetItem(tree_widget); // otherwise create a new item + // in the tree - return child_item; -} + child_item->setData(0, Qt::DisplayRole, xml.name().toString()); // set xml.tag_name as data + child_item->setText(0, xml.name().toString()); // set xml.tag_name as data + return child_item; + } -QString XMLParameterReader::demangle (const QString &s) -{ - std::string s_temp (s.toStdString()); // this function is copied from the ParameterHandler class - std::string u; - u.reserve (s_temp.size()); + QString XMLParameterReader::demangle (const QString &s) + { + std::string s_temp (s.toStdString()); // this function is copied from the ParameterHandler class - for (unsigned int i=0; i(c)); + u.push_back (static_cast(c)); // skip the two characters - i += 2; - } + i += 2; + } - QString v (u.c_str()); + QString v (u.c_str()); - return v; + return v; + } + } } diff --git a/deal.II/contrib/parameter_gui/xml_parameter_reader.h b/deal.II/contrib/parameter_gui/xml_parameter_reader.h index 2fe44c6081..6d90fd4d75 100644 --- a/deal.II/contrib/parameter_gui/xml_parameter_reader.h +++ b/deal.II/contrib/parameter_gui/xml_parameter_reader.h @@ -1,3 +1,13 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #ifndef XMLPARAMETERREADER_H #define XMLPARAMETERREADER_H @@ -8,52 +18,65 @@ #include +namespace dealii +{ +/*! @addtogroup ParameterGui + *@{ + */ + namespace ParameterGui + { /** * The XMLParameterReader class provides an interface to parse parameters from XML files to a QTreeWidget. * This class makes extensive use of the QXmlStreamReader class, which implements the basic functionalities * for parsing XML files. * - * @ingroup gui - * @author Martin Steigemann, Wolfgang Bangerth, December 2010 + * @note This class is used in the graphical user interface for the @ref ParameterHandler class. + * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. + * + * @ingroup ParameterGui + * @author Martin Steigemann, Wolfgang Bangerth, 2010 */ -class XMLParameterReader -{ - public: + class XMLParameterReader + { + public: /** * Constructor. + * The parameter values will be stored in @p tree_widget. */ - XMLParameterReader (QTreeWidget *tree_widget); + XMLParameterReader (QTreeWidget *tree_widget); /** - * This function reads the parameters from device into the tree_widget. + * This function reads the parameters from @p device into the tree_widget. * We use the QXmlStreaReader class for this. * There must be a start element - * - * and an end element + * <ParameterHandler> + * and an end element </ParameterHandler> * otherwise an exception is thrown. */ - bool read_xml_file (QIODevice *device); + bool read_xml_file (QIODevice *device); /** * This function returns an error message. */ - QString error_string () const; + QString error_string () const; - private: + private: /** * This function implements a loop over the XML file * and parses XML elements. It calls @ref read_subsection_element - * till the element is found + * till the </ParameterHandler> element is found * or the end of the file is reached. In this case, an exception is thrown. */ - void parse_parameters (); + void parse_parameters (); /** * This functions parses a subsection. - * If the next element is , + * and adds it as a child to @p parent. + * If the next element is <value>, * this functions calls @ref read_parameter_element * otherwise the function itself recursively. */ - void read_subsection_element (QTreeWidgetItem *parent); + void read_subsection_element (QTreeWidgetItem *parent); /** - * This functions parses a parameter. + * This function parses a parameter and + * and adds it as a child to @p parent. * A parameter description consists of five elements: * @code * value @@ -65,32 +88,36 @@ class XMLParameterReader * If a parameter description is incomplete, an exception * is thrown. */ - void read_parameter_element (QTreeWidgetItem *parent); + void read_parameter_element (QTreeWidgetItem *parent); /** - * Reimplemented from the ParameterHandler class. - * Unmangle a string into its original form. + * Reimplemented from the @ref ParameterHandler class. + * Unmangle a string @p s into its original form. */ - QString demangle (const QString &s); + QString demangle (const QString &s); /** - * This helper function creates a new item in the tree. + * This helper function creates a new child of @p item in the tree. */ - QTreeWidgetItem * create_child_item(QTreeWidgetItem *item); + QTreeWidgetItem * create_child_item(QTreeWidgetItem *item); /** * The QXmlStreamReader object for reading XML elements. */ - QXmlStreamReader xml; + QXmlStreamReader xml; /** * A pointer to the tree structure. */ - QTreeWidget * tree_widget; + QTreeWidget * tree_widget; /** * An icon for subsections in the tree structure. */ - QIcon subsection_icon; + QIcon subsection_icon; /** * An icon for parameters in the tree structure. */ - QIcon parameter_icon; -}; + QIcon parameter_icon; + }; + } +/**@}*/ +} + #endif diff --git a/deal.II/contrib/parameter_gui/xml_parameter_writer.cpp b/deal.II/contrib/parameter_gui/xml_parameter_writer.cpp index 95a1f5a2d1..553267d873 100644 --- a/deal.II/contrib/parameter_gui/xml_parameter_writer.cpp +++ b/deal.II/contrib/parameter_gui/xml_parameter_writer.cpp @@ -1,83 +1,98 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #include #include "xml_parameter_writer.h" -XMLParameterWriter::XMLParameterWriter(QTreeWidget *tree_widget) - : tree_widget(tree_widget) +namespace dealii { - xml.setAutoFormatting(true); // enable auto-formatting -} + namespace ParameterGui + { + XMLParameterWriter::XMLParameterWriter(QTreeWidget *tree_widget) + : tree_widget(tree_widget) + { + xml.setAutoFormatting(true); // enable auto-formatting + } -bool XMLParameterWriter::write_xml_file(QIODevice *device) -{ - xml.setDevice(device); // setup the output device - xml.writeStartDocument(); // write the head - xml.writeStartElement("ParameterHandler"); // write the root element - // loop over the elements - for (int i = 0; i < tree_widget->topLevelItemCount(); ++i) - write_item(tree_widget->topLevelItem(i)); // and write the items + bool XMLParameterWriter::write_xml_file(QIODevice *device) + { + xml.setDevice(device); // setup the output device + xml.writeStartDocument(); // write the head + xml.writeStartElement("ParameterHandler"); // write the root element + // loop over the elements + for (int i = 0; i < tree_widget->topLevelItemCount(); ++i) + write_item(tree_widget->topLevelItem(i)); // and write the items - xml.writeEndDocument(); // close the first element + xml.writeEndDocument() ; // close the first element - return true; -} + return true; + } -void XMLParameterWriter::write_item(QTreeWidgetItem *item) -{ - QString tag_name = mangle(item->text(0)); // store the element name + void XMLParameterWriter::write_item(QTreeWidgetItem *item) + { + QString tag_name = mangle(item->text(0)); // store the element name - xml.writeStartElement(tag_name); // and write to the file + xml.writeStartElement(tag_name); // and write to the file - if (!item->text(1).isEmpty()) // if the "value"-entry of this item is not empty - { // we have a parameter - xml.writeTextElement("value", item->data(1,Qt::EditRole).toString()); - xml.writeTextElement("default_value", item->text(2)); // and we write its values - xml.writeTextElement("documentation", item->text(3)); - xml.writeTextElement("pattern", item->text(4)); - xml.writeTextElement("pattern_description", item->text(5)); - }; + if (!item->text(1).isEmpty()) // if the "value"-entry of this item is not empty + { // we have a parameter + xml.writeTextElement("value", item->data(1,Qt::EditRole).toString()); + xml.writeTextElement("default_value", item->text(2)); // and we write its values + xml.writeTextElement("documentation", item->text(3)); + xml.writeTextElement("pattern", item->text(4)); + xml.writeTextElement("pattern_description", item->text(5)); + }; - for (int i = 0; i < item->childCount(); ++i) // go over the childrens recursively - write_item(item->child(i)); + for (int i = 0; i < item->childCount(); ++i) // go over the childrens recursively + write_item(item->child(i)); - xml.writeEndElement(); // write closing -} + xml.writeEndElement(); // write closing + } -QString XMLParameterWriter::mangle (const QString &s) -{ - std::string s_temp (s.toStdString()); // this function is copied from - // the ParameterHandler class - std::string u; // and adapted to mangle QString - u.reserve (s_temp.size()); + QString XMLParameterWriter::mangle (const QString &s) + { + std::string s_temp (s.toStdString()); // this function is copied from + // the ParameterHandler class + std::string u; // and adapted to mangle QString + u.reserve (s_temp.size()); - static const std::string allowed_characters - ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); + static const std::string allowed_characters + ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); // for all parts of the string, see // if it is an allowed character or // not - for (unsigned int i=0; i(s_temp[i])/16]); - u.push_back (hex[static_cast(s_temp[i])%16]); - } - - QString v (u.c_str()); - - return v; + for (unsigned int i=0; i(s_temp[i])/16]); + u.push_back (hex[static_cast(s_temp[i])%16]); + } + + QString v (u.c_str()); + + return v; + } + } } - diff --git a/deal.II/contrib/parameter_gui/xml_parameter_writer.h b/deal.II/contrib/parameter_gui/xml_parameter_writer.h index f11b8e955f..814b486b82 100644 --- a/deal.II/contrib/parameter_gui/xml_parameter_writer.h +++ b/deal.II/contrib/parameter_gui/xml_parameter_writer.h @@ -1,3 +1,13 @@ +//--------------------------------------------------------------------------- +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- #ifndef XMLPARAMETERWRITER_H #define XMLPARAMETERWRITER_H @@ -7,34 +17,45 @@ #include +namespace dealii +{ +/*! @addtogroup ParameterGui + *@{ + */ + namespace ParameterGui + { /** * The XMLParameterWriter class provides an interface to write parameters stored in a QTreeWidget to a file in XML format. * This class makes extensive use of the QXmlStreamWriter class, which implements the basic functionalities for writing * XML files. * - * @ingroup gui - * @author Martin Steigemann, Wolfgang Bangerth, December 2010 + * @note This class is used in the graphical user interface for the @ref ParameterHandler class. + * It is not compiled into the deal.II libraries and can not be used by applications using deal.II. + * + * @ingroup ParameterGui + * @author Martin Steigemann, Wolfgang Bangerth, 2010 */ -class XMLParameterWriter -{ - public: + class XMLParameterWriter + { + public: /** * Constructor. + * Parameter values from @p tree_widget will be written. */ - XMLParameterWriter (QTreeWidget *tree_widget); + XMLParameterWriter (QTreeWidget *tree_widget); /** - * This function writes the parameters stored in the tree_widget - * to device in XML format. We use the QXmlStreaWriter class + * This function writes the parameter values stored in tree_widget + * to @p device in XML format. We use the QXmlStreaWriter class * for this. The root element is - * + * <ParameterHandler> */ - bool write_xml_file (QIODevice *device); + bool write_xml_file (QIODevice *device); - private: + private: /** - * This function writes an item of tree_widget + * This function writes a given @p item of tree_widget * to a file in XML format. For this the QXmlStreamWriter class is used. - * If the item is a parameter, the elements that describes this parameter + * If the @p item is a parameter, the elements that describes this parameter * are written: * @code * value @@ -43,29 +64,32 @@ class XMLParameterWriter * pattern * [pattern_description] * @endcode - * If the item is a subsection, a start element this_subsection is written + * If the @p item is a subsection, a start element this_subsection is written * and write_item is called recursively to write the next item. */ - void write_item (QTreeWidgetItem *item); + void write_item (QTreeWidgetItem *item); /** - * Reimplemented from the ParameterHandler class. - * Mangle a string so that it + * Reimplemented from the @ref ParameterHandler class. + * Mangle a string @p s so that it * doesn't contain any special * characters or spaces. */ - QString mangle (const QString &s); + QString mangle (const QString &s); /** * An QXmlStreamWriter object * which implements the functionalities * we need for writing parameters to XML files. */ - QXmlStreamWriter xml; + QXmlStreamWriter xml; /** * A pointer to the QTreeWidget structure * which stores the parameters. */ - QTreeWidget * tree_widget; -}; + QTreeWidget * tree_widget; + }; + } +/**@}*/ +} #endif diff --git a/deal.II/doc/doxygen/Makefile.in b/deal.II/doc/doxygen/Makefile.in index a6c11ef20a..261826a5cd 100644 --- a/deal.II/doc/doxygen/Makefile.in +++ b/deal.II/doc/doxygen/Makefile.in @@ -36,6 +36,7 @@ deal.II deal.tag: tutorial \ deal.dox \ $D/include/deal.II/*/*.h \ headers/*.h \ + $D/contrib/parameter_gui/*.h \ $(addprefix tutorial/doxygen/, $(shell ls tutorial/doxygen/)) @echo "=== Generating reference documentation. " \ "This can take several minutes..." @@ -55,8 +56,8 @@ tutorial: deal.dox: Makefile $(shell echo images ../../examples/*/doc ../news/*.h) @echo "=== Making $@" - @echo "INPUT=`echo headers $D/include/deal.II/* tutorial/doxygen ../news/*.h`" > $@ - @echo "IMAGE_PATH=`echo images ../../examples/*/doc`" >> $@ + @echo "INPUT=`echo headers $D/include/deal.II/* tutorial/doxygen ../news/*.h $D/contrib/parameter_gui`" > $@ + @echo "IMAGE_PATH=`echo images ../../examples/*/doc $D/contrib/parameter_gui/images`" >> $@