From: Rene Gassmoeller Date: Sat, 8 Apr 2017 02:31:53 +0000 (-0600) Subject: Move comments to default position X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f50b339eb69484b55fa838beef8c651b45b9b8a;p=parameter_gui.git Move comments to default position --- diff --git a/browse_lineedit.h b/browse_lineedit.h index 03dc445..467d8d0 100644 --- a/browse_lineedit.h +++ b/browse_lineedit.h @@ -55,6 +55,7 @@ namespace dealii * in the constructor by setting this flag BrowseType. */ enum BrowseType {file = 0, directory = 1, files = 2}; + /** * Constructor. The type of the browse dialog can be specified * by the flag BrowseType, the default is file. @@ -67,14 +68,17 @@ namespace dealii * Returns the size of the editor. */ QSize sizeHint() const; + /** * Reimplemented from the QWidget class. */ QSize minimumSizeHint() const; + /** * Returns the text of the line editor. */ QString text() const; + /** * This pattern stores the type of the browse dialog. */ @@ -97,6 +101,7 @@ namespace dealii * This slot should be always called, if editing is finished. */ void editing_finished(); + /** * This function opens a file- or a directory dialog as specified in the * constructor. @@ -108,6 +113,7 @@ namespace dealii * The line editor. */ QLineEdit *line_editor; + /** * The browse button. */ diff --git a/info_message.cpp b/info_message.cpp index b5207d3..20ce137 100644 --- a/info_message.cpp +++ b/info_message.cpp @@ -26,48 +26,60 @@ namespace dealii InfoMessage::InfoMessage(QWidget *parent) : QDialog(parent, 0) { - show_again = true; // this variable stores, if the - // the info message should be shown again + // this variable stores, if the + // the info message should be shown again + show_again = true; QGridLayout * grid = new QGridLayout(this); - icon = new QLabel(this); // set an icon + // set an icon + icon = new QLabel(this); #ifndef QT_NO_MESSAGEBOX 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 + // add the icon in the upper left corner + grid->addWidget(icon, 0, 0, Qt::AlignTop); - message = new QTextEdit(this); // set the new message + // set the new message + message = new QTextEdit(this); message->setReadOnly(true); - grid->addWidget(message, 0, 1); // and add the message on the right - again = new QCheckBox(this); // add a check box + // and add the message on the right + grid->addWidget(message, 0, 1); + + // add a check box + again = new QCheckBox(this); 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 + // and finally a OK button + ok = new QPushButton(this); ok->setText(QErrorMessage::tr("&OK")); #ifdef QT_SOFTKEYS_ENABLED - ok_action = new QAction(ok); // define the action for the button + // define the action for the button + ok_action = new QAction(ok); 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 + // and set the focus on the button + ok->setFocus(); grid->addWidget(ok, 2, 0, 1, 2, Qt::AlignCenter); grid->setColumnStretch(1, 42); grid->setRowStretch(0, 42); - // load settings from an ini-file + + // load settings from an ini-file QString settings_file = QDir::currentPath() + "/settings.ini"; 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 + // we store settings of this class in the group infoMessage + settings->beginGroup("infoMessage"); + show_again = settings->value("showInformation", true).toBool(); settings->endGroup(); } @@ -75,14 +87,16 @@ namespace dealii void InfoMessage::setInfoMessage(const QString &message) { - this->message->setText(message); // set the message + // set the message + this->message->setText(message); } void InfoMessage::showMessage() { - if (show_again) // and show the message + // and show the message + if (show_again) show(); } @@ -90,8 +104,9 @@ namespace dealii void InfoMessage::done(int r) { - if(!again->isChecked()) // if the box is not checked, - { // store this to settings + // if the box is not checked, store this to settings + if(!again->isChecked()) + { settings->beginGroup("infoMessage"); settings->setValue("showInformation", false); settings->endGroup(); diff --git a/info_message.h b/info_message.h index ea147dc..09a00a2 100644 --- a/info_message.h +++ b/info_message.h @@ -55,6 +55,7 @@ namespace dealii * Constructor */ InfoMessage (QWidget *parent = 0); + /** * With this function the @p message which will be shown in the * dialog can be set. @@ -78,28 +79,34 @@ namespace dealii * This variable stores, if the message should be shown again the next time. */ bool show_again; + /** * The Ok button. */ QPushButton *ok; + /** * The checkboxShow this message again. */ QCheckBox *again; + /** * The message editor. */ QTextEdit *message; + /** * An icon for the dialog. */ QLabel *icon; + #ifdef QT_SOFTKEYS_ENABLED /** * A action for pressing the Ok button. */ QAction *ok_action; #endif + /** * An object for storing settings in a file. */ diff --git a/main.cpp b/main.cpp index 6229d7e..1eae68c 100644 --- a/main.cpp +++ b/main.cpp @@ -46,25 +46,32 @@ */ int main(int argc, char *argv[]) { - Q_INIT_RESOURCE(application); // init resources such as icons or graphics + // init resources such as icons or graphics + Q_INIT_RESOURCE(application); QApplication app(argc, argv); - QSplashScreen * splash = new QSplashScreen; // setup a splash screen + // setup a splash screen + QSplashScreen * splash = new QSplashScreen; splash->setPixmap(QPixmap(":/images/logo_dealii_gui.png")); splash->show(); - QTimer::singleShot(3000, splash, SLOT(close())); // and close it after 3000 ms + // and close it after 3000 ms + QTimer::singleShot(3000, splash, SLOT(close())); - app.setApplicationName("parameterGUI for deal.II"); // setup the application name + // setup the application name + app.setApplicationName("parameterGUI for deal.II"); + // 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. + new dealii::ParameterGui::MainWindow (argv[1]); + + // show the main window with a short delay + // so we can see the splash screen + QTimer::singleShot(1500, main_win, SLOT(show())); - 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/mainwindow.cpp b/mainwindow.cpp index b129089..190b833 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -29,22 +29,23 @@ namespace dealii { MainWindow::MainWindow(const QString &filename) { - QString settings_file = QDir::currentPath() + "/settings.ini"; // a file for user settings + // a file for user settings + QString settings_file = QDir::currentPath() + "/settings.ini"; - gui_settings = new QSettings (settings_file, QSettings::IniFormat); // load settings + // load settings + gui_settings = new QSettings (settings_file, QSettings::IniFormat); - tree_widget = new QTreeWidget; // tree for showing XML tags + // tree for showing XML tags + tree_widget = new QTreeWidget; - // 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" + // Setup the tree and the window first: + tree_widget->header()->setResizeMode(QHeaderView::ResizeToContents); 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 + + // enables mouse events e.g. showing ToolTips + // and documentation in the StatusLine + tree_widget->setMouseTracking(true); tree_widget->setEditTriggers(QAbstractItemView::DoubleClicked| QAbstractItemView::SelectedClicked| QAbstractItemView::EditKeyPressed); @@ -53,18 +54,14 @@ namespace dealii tree_widget->setContextMenuPolicy(Qt::ActionsContextMenu); context_menu = new QMenu(tree_widget); - // 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 + // set the delegate for editing items + tree_widget->setItemDelegate(new ParameterDelegate(1)); - setCentralWidget(tree_widget); // connect: if the tree changes, the window will know + setCentralWidget(tree_widget); - connect(tree_widget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(set_documentation_text(QTreeWidgetItem *, QTreeWidgetItem *))); // and connect - connect(tree_widget, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(item_changed(QTreeWidgetItem *, int))); // and connect + connect(tree_widget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(set_documentation_text(QTreeWidgetItem *, QTreeWidgetItem *))); + // connect: if the tree changes, the window will know + connect(tree_widget, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(item_changed(QTreeWidgetItem *, int))); connect(tree_widget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(tree_was_modified())); QDockWidget *documentation_widget = new QDockWidget(tr("Parameter documentation:"), this); @@ -76,17 +73,22 @@ namespace dealii addDockWidget(Qt::BottomDockWidgetArea, documentation_widget); - create_actions(); // create window actions as "Open",... - create_menus(); // and menus + // create window actions as "Open",... + create_actions(); + // and menus + create_menus(); + // and the toolbar create_toolbar(); statusBar()->showMessage(tr("Ready, start editing by double-clicking or hitting F2!")); - setWindowTitle(tr("[*]parameterGUI")); // set window title + setWindowTitle(tr("[*]parameterGUI")); showMaximized(); - 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 + // if there is a file_name, try to load the file. + // a valid file has the xml extension, so we require size() > 3 + if (filename.size() > 3) + load_file(filename); apply_settings(); } @@ -100,6 +102,8 @@ namespace dealii documentation_text_widget->insertPlainText(selected_item->text(3)); } + + void MainWindow::item_changed(QTreeWidgetItem *item, int column) { @@ -143,40 +147,47 @@ namespace dealii void MainWindow::open() { - if (maybe_save()) // check, if the content was modified + // check, if the content was modified + if (maybe_save()) { - QString file_name = // open a file dialog + // open a file dialog + QString file_name = 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 a file was selected, load the content + if (!file_name.isEmpty()) + load_file(file_name); + } } bool MainWindow::save() { - if (current_file.isEmpty()) // if there is no file - return save_as(); // to save changes, open a dialog + // if there is no file to save changes, open a dialog + if (current_file.isEmpty()) + return save_as(); else - return save_file(current_file); // otherwise save + return save_file(current_file); } bool MainWindow::save_as() { - QString file_name = // open a file dialog + // open a file dialog + QString file_name = QFileDialog::getSaveFileName(this, tr("Save Parameter File"), QDir::currentPath(), tr("XML Files (*.xml);;PRM Files (*.prm)")); - if (file_name.isEmpty()) // if no file was selected - return false; // return false + // return if a file was saved + if (file_name.isEmpty()) + return false; else - return save_file(file_name); // otherwise save content to file + return save_file(file_name); } @@ -254,10 +265,11 @@ namespace dealii 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 + // 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 + setWindowModified(true); } @@ -359,10 +371,13 @@ namespace dealii 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 + // Reimplement the closeEvent from the QMainWindow class. + // First check, if we have to save modified content. + // If not, or the content was saved, accept the event, otherwise ignore it + if (maybe_save()) + event->accept(); + else + event->ignore(); } @@ -371,11 +386,13 @@ namespace dealii { QStyle * style = tree_widget->style(); - open_act = new QAction(tr("&Open..."), this); // create actions - open_act->setIcon(style->standardPixmap(QStyle::SP_DialogOpenButton)); // 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 + // Create actions, and set icons, shortcuts, status tip and connect to + // activate the action. + open_act = new QAction(tr("&Open..."), this); + open_act->setIcon(style->standardPixmap(QStyle::SP_DialogOpenButton)); + open_act->setShortcut(Qt::CTRL + Qt::Key_O); + open_act->setStatusTip(tr("Open a XML file")); + connect(open_act, SIGNAL(triggered()), this, SLOT(open())); save_act = new QAction(tr("&Save ..."), this); save_act->setIcon(style->standardPixmap(QStyle::SP_DialogSaveButton)); @@ -417,20 +434,22 @@ namespace dealii 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->addSeparator(); - file_menu->addAction(settings_act); - file_menu->addSeparator(); - file_menu->addAction(exit_act); - - menuBar()->addSeparator(); - - help_menu = menuBar()->addMenu(tr("&Help")); // create a help menu - help_menu->addAction(about_act); - help_menu->addAction(about_qt_act); + // create a file menu, and add the entries + file_menu = menuBar()->addMenu(tr("&File")); + file_menu->addAction(open_act); + file_menu->addAction(save_act); + file_menu->addAction(save_as_act); + file_menu->addSeparator(); + file_menu->addAction(settings_act); + file_menu->addSeparator(); + file_menu->addAction(exit_act); + + menuBar()->addSeparator(); + + // create a help menu + help_menu = menuBar()->addMenu(tr("&Help")); + help_menu->addAction(about_act); + help_menu->addAction(about_qt_act); } @@ -439,7 +458,8 @@ namespace dealii { QToolBar *toolbar = new QToolBar(tr("Toolbar"),this); - toolbar->addAction(open_act); // and add actions + // add entries + toolbar->addAction(open_act); toolbar->addAction(save_act); toolbar->addAction(save_as_act); @@ -463,9 +483,10 @@ namespace dealii bool MainWindow::maybe_save() { - if (isWindowModified()) // if content was modified + // if content was modified, ask if content should be saved + if (isWindowModified()) { - QMessageBox::StandardButton ret; // ask, if content should be saved + QMessageBox::StandardButton ret; ret = QMessageBox::warning(this, tr("parameterGUI"), tr("The content has been modified.\n" "Do you want to save your changes?"), @@ -486,7 +507,8 @@ namespace dealii { QFile file(filename); - if (!file.open(QFile::WriteOnly | QFile::Text)) // open a file dialog + // open a file dialog + if (!file.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::warning(this, tr("parameterGUI"), tr("Cannot write file %1:\n%2.") @@ -497,14 +519,16 @@ namespace dealii if (filename.endsWith(".xml",Qt::CaseInsensitive)) { - XMLParameterWriter writer(tree_widget); // create a xml writer - if (!writer.write_xml_file(&file)) // and write the xml file + // create a xml writer and write the xml file + XMLParameterWriter writer(tree_widget); + if (!writer.write_xml_file(&file)) return false; } else if (filename.endsWith(".prm",Qt::CaseInsensitive)) { - PRMParameterWriter writer(tree_widget); // create a prm writer - if (!writer.write_prm_file(&file)) // and write the prm file + // create a prm writer and write the prm file + PRMParameterWriter writer(tree_widget); + if (!writer.write_prm_file(&file)) return false; } else @@ -517,8 +541,9 @@ namespace dealii return false; } - statusBar()->showMessage(tr("File saved"), 2000); // if we succeed, show a message - set_current_file(filename); // and reset the window + // if we succeed, show a message and reset the window + statusBar()->showMessage(tr("File saved"), 2000); + set_current_file(filename); return true; } @@ -529,7 +554,8 @@ namespace dealii { QFile file(filename); - if (!file.open(QFile::ReadOnly | QFile::Text)) // open the file + // open the file + if (!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this, tr("parameterGUI"), tr("Cannot read file %1:\n%2.") @@ -538,9 +564,9 @@ namespace dealii return; }; - tree_widget->clear(); // clear the tree - - XMLParameterReader xml_reader(tree_widget); // and read the xml file + // clear the tree and read the xml file + tree_widget->clear(); + XMLParameterReader xml_reader(tree_widget); if (!xml_reader.read_xml_file(&file)) { @@ -551,10 +577,12 @@ namespace dealii } else { + // show a message and set current file 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 + set_current_file(filename); - show_message (); // show some informations how values can be edited + // show some informations how values can be edited + show_message (); }; } @@ -562,27 +590,34 @@ namespace dealii 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, + // 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 + + // set the (global) current file to file_name + current_file = filename; + + // and create the window title, + std::string win_title = (filename.toStdString()); + + // if file_name is empty set the title to our application name + if (current_file.isEmpty()) + win_title = "[*]parameterGUI"; else - win_title += "[*] - parameterGUI"; // if there is a file_name, add the - // the file_name and a minus to the title + { + // if there is a file_name, add the + // the file_name and a minus to the title + win_title += "[*] - parameterGUI"; + } - setWindowTitle(tr(win_title.c_str())); // set the window title - setWindowModified(false); // and reset window modified + // set the window title and reset window modified + setWindowTitle(tr(win_title.c_str())); + setWindowModified(false); } diff --git a/mainwindow.h b/mainwindow.h index b95d948..41d8071 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -75,14 +75,17 @@ namespace dealii * Open a parameter file. */ void open(); + /** * Save the parameter file. */ bool save(); + /** * Open a file dialog to save the parameter file. */ bool save_as(); + /** * Show some information on the parameterGUI */ @@ -155,19 +158,23 @@ namespace dealii * parameters can be edited. */ void show_message (); + /** * This function creates all actions. */ void create_actions(); + /** * This function creates all menus. */ void create_menus(); + /** * This function creates the toolbar. */ void create_toolbar(); + /** * This function checks, if parameters were changed * and show a dialog, if changes should be saved. @@ -175,14 +182,17 @@ namespace dealii * before open a new parameter file or before closing the GUI */ bool maybe_save (); + /** * Save parameters to @p filename in XML format. */ bool save_file (const QString &filename); + /** * Load parameters from @p filename in XML format. */ void load_file (const QString &filename); + /** * This functions writes the current @p filename to the window title. */ @@ -199,57 +209,70 @@ namespace dealii * This is the tree structure in which we store all parameters. */ QTreeWidget *tree_widget; + /** * This is the documentation text area. */ QTextEdit *documentation_text_widget; + /** A tool button that allows to toggle between showing/hiding parameters * with default values. */ QToolButton *hide_default; + /** * This menu provides all file actions as open, save, save as * and exit */ QMenu *file_menu; + /** * This menu provides some informations about the parameterGUI * and about Qt */ QMenu *help_menu; + /** * This menu provides context menu options for the active tree item. */ QMenu *context_menu; + /** * QAction open a file. */ QAction *open_act; + /** * QAction save a file. */ QAction *save_act; + /** * QAction save as a file. */ QAction *save_as_act; + /** * QAction save as a file. */ QAction *settings_act; + /** * QAction exit the GUI. */ QAction *exit_act; + /** * QAction about the parameterGUI. */ QAction *about_act; + /** * QAction about Qt. */ QAction *about_qt_act; + /** * QAction set_to_default. */ @@ -259,11 +282,15 @@ namespace dealii * This value stores the current filename we work on. */ QString current_file; + /** * This dialog shows a short information message after loading a file. */ InfoMessage *info_message; + /** + * This dialog shows the available settings. + */ SettingsDialog *settings_dialog; /** diff --git a/parameter_delegate.cpp b/parameter_delegate.cpp index c28a1f2..98b71c0 100644 --- a/parameter_delegate.cpp +++ b/parameter_delegate.cpp @@ -37,7 +37,8 @@ namespace dealii { if (index.column() == value_column) { - return QSize(400,30); // we increase the height of all lines to show editors + // we increase the height of all lines to show editors + return QSize(400,30); /* QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description @@ -63,24 +64,29 @@ namespace dealii { 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 - // or DirectoryName + // load pattern description stored in the StatusLine + QString pattern_description = index.data(Qt::StatusTipRole).toString(); + + 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 + QString value = index.model()->data(index, Qt::DisplayRole).toString(); - QStyleOptionViewItem my_option = option; // load options + QStyleOptionViewItem my_option = option; 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 - // focus, print a rectangle + // print the text in the display + drawDisplay(painter, my_option, my_option.rect, value); + // if the line has the focus, print a rectangle + drawFocus(painter, my_option, my_option.rect); } else - QItemDelegate::paint(painter, option, index); // for all other types use - // the standard delegate + { + // for all other types use the standard delegate + QItemDelegate::paint(painter, option, index); + } } else QItemDelegate::paint(painter, option, index); @@ -94,8 +100,9 @@ namespace dealii { if (index.column() == value_column) { - QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description - // stored in the StatusLine + // load pattern description stored in the StatusLine + QString pattern_description = index.data(Qt::StatusTipRole).toString(); + QRegExp rx_string("\\b(Anything|MultipleSelection|Map)\\b"), rx_list("\\b(List)\\b"), rx_filename("\\b(FileName)\\b"), @@ -105,20 +112,21 @@ namespace dealii rx_selection("\\b(Selection)\\b"), rx_bool("\\b(Bool)\\b"); - if (rx_string.indexIn (pattern_description) != -1) // if the type is "Anything" + // if the type is "Anything" choose a LineEditor + if (rx_string.indexIn (pattern_description) != -1) { - QLineEdit * line_editor = new QLineEdit(parent); // choose a LineEditor - - connect(line_editor, SIGNAL(editingFinished()), // and connect editors signal - this, SLOT(commit_and_close_editor())); // to the closer function + QLineEdit * line_editor = new QLineEdit(parent); + connect(line_editor, SIGNAL(editingFinished()), + this, SLOT(commit_and_close_editor())); return line_editor; } - else if (rx_list.indexIn (pattern_description) != -1) // if the type is "List" + else if (rx_list.indexIn (pattern_description) != -1) { + // if the type is "List" of files/directories choose a BrowseLineEditor if (rx_filename.indexIn (pattern_description) != -1) { - BrowseLineEdit * filename_editor = // choose a BrowseLineEditor + BrowseLineEdit * filename_editor = new BrowseLineEdit(BrowseLineEdit::files, parent); connect(filename_editor, SIGNAL(editingFinished()), @@ -126,19 +134,21 @@ namespace dealii return filename_editor; } + // if the type is "List" of something else choose a LineEditor else { - QLineEdit * line_editor = new QLineEdit(parent); // choose a LineEditor + QLineEdit * line_editor = new QLineEdit(parent); - connect(line_editor, SIGNAL(editingFinished()), // and connect editors signal - this, SLOT(commit_and_close_editor())); // to the closer function + connect(line_editor, SIGNAL(editingFinished()), + this, SLOT(commit_and_close_editor())); return line_editor; } } - else if (rx_filename.indexIn (pattern_description) != -1) // if the type is "FileName" + // if the type is "FileName" choose a BrowseLineEditor + else if (rx_filename.indexIn (pattern_description) != -1) { - BrowseLineEdit * filename_editor = // choose a BrowseLineEditor + BrowseLineEdit * filename_editor = new BrowseLineEdit(BrowseLineEdit::file, parent); connect(filename_editor, SIGNAL(editingFinished()), @@ -146,9 +156,10 @@ namespace dealii return filename_editor; } - else if (rx_dirname.indexIn (pattern_description) != -1) // if the type is "DirectoryName" + // if the type is "DirectoryName" choose a BrowseLineEditor + else if (rx_dirname.indexIn (pattern_description) != -1) { - BrowseLineEdit * dirname_editor = // choose a BrowseLineEditor + BrowseLineEdit * dirname_editor = new BrowseLineEdit(BrowseLineEdit::directory, parent); connect(dirname_editor, SIGNAL(editingFinished()), @@ -156,7 +167,8 @@ namespace dealii return dirname_editor; } - else if (rx_integer.indexIn (pattern_description) != -1) // if the type is "Integer" + // if the type is "Integer" choose a LineEditor with appropriate bounds + else if (rx_integer.indexIn (pattern_description) != -1) { const QStringList default_pattern = pattern_description.split(" ").filter("..."); const QStringList default_values = default_pattern[0].split("..."); @@ -164,12 +176,13 @@ namespace dealii QLineEdit * line_edit = new QLineEdit(parent); line_edit->setValidator(new QIntValidator(default_values[0].toInt(), default_values[1].toInt(), line_edit)); - connect(line_edit, SIGNAL(editingFinished()), // connect editors signal to the closer function + connect(line_edit, SIGNAL(editingFinished()), this, SLOT(commit_and_close_editor())); return line_edit; } - else if (rx_double.indexIn (pattern_description) != -1) // the same with "Double" + // if the type is "Double" choose a LineEditor with appropriate bounds + else if (rx_double.indexIn (pattern_description) != -1) { const QStringList default_pattern = pattern_description.split(" ").filter("..."); QStringList default_values = default_pattern[0].split("..."); @@ -190,12 +203,13 @@ namespace dealii number_of_decimals, line_edit)); - connect(line_edit, SIGNAL(editingFinished()), // connect editors signal to the closer function + connect(line_edit, SIGNAL(editingFinished()), this, SLOT(commit_and_close_editor())); return line_edit; } - else if (rx_selection.indexIn (pattern_description) != -1) // and selections + // if the type is "Selection" choose a ComboBox + else if (rx_selection.indexIn (pattern_description) != -1) { QComboBox * combo_box = new QComboBox(parent); @@ -222,25 +236,27 @@ namespace dealii combo_box->setEditable(false); - connect(combo_box, SIGNAL(currentIndexChanged(int)), // connect editors signal to the closer function + connect(combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(commit_and_close_editor())); return combo_box; } - else if (rx_bool.indexIn (pattern_description) != -1) // and booleans + // if the type is "Bool" choose a ComboBox + else if (rx_bool.indexIn (pattern_description) != -1) { 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; + choices.push_back(std::string("true")); + choices.push_back(std::string("false")); - for (unsigned int i=0; iaddItem (tr(choices[i].c_str()), tr(choices[i].c_str())); combo_box->setEditable(false); - connect(combo_box, SIGNAL(currentIndexChanged(int)), // connect editors signal to the closer function + connect(combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(commit_and_close_editor())); return combo_box; @@ -251,7 +267,8 @@ namespace dealii }; }; - return 0; // if it is not the column "parameter values", do nothing + // if it is not the column "parameter values", do nothing + return 0; } @@ -269,8 +286,9 @@ namespace dealii { QRegExp rx(index.data(Qt::DisplayRole).toString()); - for (int i=0; icount(); ++i) // we look, which index - if (rx.exactMatch(combo_box->itemText(i))) // the data has and set + // Preset ComboBox to the current selection + for (int i=0; icount(); ++i) + if (rx.exactMatch(combo_box->itemText(i))) combo_box->setCurrentIndex(i); } else diff --git a/parameter_delegate.h b/parameter_delegate.h index bccbac0..b93622a 100644 --- a/parameter_delegate.h +++ b/parameter_delegate.h @@ -60,24 +60,29 @@ namespace dealii * of the parameter tree this delegate will be used on. */ 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; + /** * Reimplemented from QItemDelegate. */ QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + /** * Reimplemented from QItemDelegate. */ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + /** * Reimplemented from QItemDelegate. */ void setEditorData(QWidget *editor, const QModelIndex &index) const; + /** * Reimplemented from QItemDelegate. */ diff --git a/prm_parameter_writer.cpp b/prm_parameter_writer.cpp index cd277a5..e5d1777 100644 --- a/prm_parameter_writer.cpp +++ b/prm_parameter_writer.cpp @@ -32,7 +32,7 @@ namespace dealii bool PRMParameterWriter::write_prm_file(QIODevice *device) { - // loop over the elements + // loop over the elements for (int i = 0; i < tree_widget->topLevelItemCount(); ++i) { const QString item_string = item_to_string(tree_widget->topLevelItem(i),0); @@ -49,8 +49,9 @@ namespace dealii { QString item_string; - if (item->childCount() == 0) // if the "value"-entry of this item is not empty - { // we have a parameter + // if the entry has no children we have a parameter + if (item->childCount() == 0) + { bool non_default_value; if (item->text(5).startsWith("[Double")) diff --git a/xml_parameter_reader.cpp b/xml_parameter_reader.cpp index c391906..ea1f32c 100644 --- a/xml_parameter_reader.cpp +++ b/xml_parameter_reader.cpp @@ -40,13 +40,13 @@ namespace dealii { xml.setDevice(device); - // We look for a StartElement "ParameterHandler" - // and start parsing after this. - // - // - // ... - // - // + // We look for a StartElement "ParameterHandler" + // and start parsing after this. + // + // + // ... + // + // while (xml.readNext() != QXmlStreamReader::Invalid) { @@ -80,13 +80,16 @@ namespace dealii { Q_ASSERT(xml.isStartElement() && xml.name() == "ParameterHandler"); - while (xml.readNext() != QXmlStreamReader::Invalid) // go to the next - { // if it is the closing element of ParameterHandler, + // go to the next + while (xml.readNext() != QXmlStreamReader::Invalid) + { + // if it is the closing element of ParameterHandler, break the loop if (xml.isEndElement() && xml.name() == "ParameterHandler") - break; // break the loop + break; - if (xml.isStartElement()) // if it is a start element - read_subsection_element(0); // it must be a subsection or a parameter + // if it is a start element it must be a subsection or a parameter + if (xml.isStartElement()) + read_subsection_element(0); }; } @@ -94,59 +97,68 @@ namespace dealii void XMLParameterReader::read_subsection_element(QTreeWidgetItem *parent) { - // The structure of the parameter file is assumed to be of the form - // - // - // - // ... - // - // ... - // ... - // ... - // - // - // ... - // - // ... - // - // - // ... - // - // ... - // - // - // Any subsection has a user-specified name also any parameter, but we do not know - // the userspecified names and we can not assume anything. So, when parsing the file, - // we do not know, if the actual is a or a - // in a subsection. To decide, if the element is a subsection- or a parameter-name, - // we assume, that if the next is , we have a - // and a parameter has the entries , , , - // and - - Q_ASSERT(xml.isStartElement()); // the actual element is - - 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 - - tree_widget->setItemExpanded(subsection, 0); // and the folder is not expanded - - while (xml.readNext() != QXmlStreamReader::Invalid) // read the next element + // The structure of the parameter file is assumed to be of the form + // + // + // + // ... + // + // ... + // ... + // ... + // + // + // ... + // + // ... + // + // + // ... + // + // ... + // + // + // Any subsection has a user-specified name also any parameter, but we do not know + // the userspecified names and we can not assume anything. So, when parsing the file, + // we do not know, if the actual is a or a + // in a subsection. To decide, if the element is a subsection- or a parameter-name, + // we assume, that if the next is , we have a + // and a parameter has the entries , , , + // and + + // the actual element is + Q_ASSERT(xml.isStartElement()); + + // create a new subsection in the tree + QTreeWidgetItem * subsection = create_child_item(parent); + + subsection->setIcon(0, subsection_icon); + subsection->setText(0, demangle(xml.name().toString())); + + // the folder is not expanded + tree_widget->setItemExpanded(subsection, 0); + + // read the next element + while (xml.readNext() != QXmlStreamReader::Invalid) { - if (xml.isEndElement()) // if the next element is , break the loop + // if the next element is , break the loop + if (xml.isEndElement()) break; - if (xml.isStartElement()) // if it is a start element + if (xml.isStartElement()) { - if (xml.name() == "value") // it can be , then we have found a parameter, + // it can be , then we have found a parameter, + if (xml.name() == "value") { - subsection->setFlags(subsection->flags() | Qt::ItemIsEditable); // values can be edited, + // values can be edited + subsection->setFlags(subsection->flags() | Qt::ItemIsEditable); read_parameter_element (subsection); } - else // or it can be a new + // or it can be a new + else { - subsection->setFlags(subsection->flags() | Qt::NoItemFlags); // subsections can not be edited, + // subsections can not be edited + subsection->setFlags(subsection->flags() | Qt::NoItemFlags); read_subsection_element (subsection); }; }; @@ -157,74 +169,85 @@ namespace dealii 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 + // the actual element is , + // then we have found a parameter-item + Q_ASSERT(xml.isStartElement() && xml.name() == "value"); + + QString value = xml.readElementText(); + // store as text to the item + parent->setText(1, value); + // change the icon of parent + parent->setIcon(0, parameter_icon); - while (xml.readNext() != QXmlStreamReader::Invalid) // go to the next + // go to the next + while (xml.readNext() != QXmlStreamReader::Invalid) { if (xml.isStartElement()) { - if (xml.isStartElement() && xml.name() == "default_value") // if it is + // if it is store it + if (xml.isStartElement() && xml.name() == "default_value") { - QString default_value = xml.readElementText(); // store it + QString default_value = xml.readElementText(); parent->setText(2, default_value); } - else if (xml.isStartElement() && xml.name() == "documentation") // if it is + // if it is store it + else if (xml.isStartElement() && xml.name() == "documentation") { - QString documentation = xml.readElementText(); // store it + QString documentation = xml.readElementText(); parent->setText(3, documentation); } - else if (xml.isStartElement() && xml.name() == "pattern") // if it is + // if it is store it as text, + // we only need this value for writing back to XML later + else if (xml.isStartElement() && xml.name() == "pattern") { - QString pattern = xml.readElementText(); // store it as text - parent->setText(4, pattern); // we only need this value - // for writing back to XML later + QString pattern = xml.readElementText(); + parent->setText(4, pattern); } - else if (xml.isStartElement() && xml.name() == "pattern_description") // if it is + // if it is store it as text + else if (xml.isStartElement() && xml.name() == "pattern_description") { - QString pattern_description = xml.readElementText(); // store it as text + QString pattern_description = xml.readElementText(); + + // show the type and default + // in the StatusLine when + // hovering over column 0 or 1 parent->setText(5, pattern_description); - // show the type and default - // in the StatusLine when - // hovering over column 0 or 1 parent->setStatusTip(0, "Type: " + pattern_description + " Default: " + parent->text(2)); 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: - + // 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" + // store the type "Anything" or "Filename" as a QString + if (rx_string.indexIn (pattern_description) != -1) { - QString value = parent->text(1); // store as a QString + QString value = parent->text(1); - parent->setData(1, Qt::EditRole, value); // and set the data in the item + parent->setData(1, Qt::EditRole, value); parent->setData(1, Qt::DisplayRole, value); } - else if (rx_integer.indexIn (pattern_description) != -1) // if the tpye is "Integer" + // store the type "Integer" as an int + else if (rx_integer.indexIn (pattern_description) != -1) { QString text = parent->text(1); bool ok = true; + int value = text.toInt(&ok); - int value = text.toInt(&ok); // we convert the string to int - - if (ok) // and store + if (ok) { parent->setData(1, Qt::EditRole, value); parent->setData(1, Qt::DisplayRole, value); } - else // otherwise raise an error + else xml.raiseError(QObject::tr("Cannot convert integer type to integer!")); } - else if (rx_double.indexIn (pattern_description) != -1) // the same with "Float" + // store the type "Double" as an double + else if (rx_double.indexIn (pattern_description) != -1) { QString text = parent->text(1); @@ -239,9 +262,10 @@ namespace dealii } else xml.raiseError(QObject::tr("Cannot convert double type to double!")); - }; + } - if (rx_bool.indexIn (pattern_description) != -1) // and booleans + // store the type "Bool" as an boolean + if (rx_bool.indexIn (pattern_description) != -1) { QRegExp test(parent->text(1)); @@ -254,36 +278,41 @@ namespace dealii 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 - }; + // this is needed because we use for booleans the standard delegate + parent->setText(1, ""); + parent->setData(1, Qt::EditRole, value); + parent->setData(1, Qt::DisplayRole, value); + } - break; // and break the loop + break; } + // if there is any other element, raise an error 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! - }; + break; + } + } + } } QTreeWidgetItem *XMLParameterReader::create_child_item(QTreeWidgetItem *item) { - QTreeWidgetItem * child_item; // create a new child-item + // create a new child-item + QTreeWidgetItem * child_item; + // if item is not empty, append the new item as a child 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 + child_item = new QTreeWidgetItem(item); + // otherwise create a new item in the tree + else + child_item = new QTreeWidgetItem(tree_widget); - 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 + // set xml.tag_name as data + child_item->setData(0, Qt::DisplayRole, xml.name().toString()); + child_item->setText(0, xml.name().toString()); return child_item; } @@ -292,7 +321,8 @@ namespace dealii QString XMLParameterReader::demangle (const QString &s) { - std::string s_temp (s.toStdString()); // this function is copied from the ParameterHandler class + // this function is copied from the ParameterHandler class + std::string s_temp (s.toStdString()); std::string u; u.reserve (s_temp.size()); @@ -306,52 +336,52 @@ namespace dealii unsigned char c = 0; switch (s_temp[i+1]) - { - case '0': c = 0 * 16; break; - case '1': c = 1 * 16; break; - case '2': c = 2 * 16; break; - case '3': c = 3 * 16; break; - case '4': c = 4 * 16; break; - case '5': c = 5 * 16; break; - case '6': c = 6 * 16; break; - case '7': c = 7 * 16; break; - case '8': c = 8 * 16; break; - case '9': c = 9 * 16; break; - case 'a': c = 10 * 16; break; - case 'b': c = 11 * 16; break; - case 'c': c = 12 * 16; break; - case 'd': c = 13 * 16; break; - case 'e': c = 14 * 16; break; - case 'f': c = 15 * 16; break; - default: - Q_ASSERT (false); - } + { + case '0': c = 0 * 16; break; + case '1': c = 1 * 16; break; + case '2': c = 2 * 16; break; + case '3': c = 3 * 16; break; + case '4': c = 4 * 16; break; + case '5': c = 5 * 16; break; + case '6': c = 6 * 16; break; + case '7': c = 7 * 16; break; + case '8': c = 8 * 16; break; + case '9': c = 9 * 16; break; + case 'a': c = 10 * 16; break; + case 'b': c = 11 * 16; break; + case 'c': c = 12 * 16; break; + case 'd': c = 13 * 16; break; + case 'e': c = 14 * 16; break; + case 'f': c = 15 * 16; break; + default: + Q_ASSERT (false); + } switch (s_temp[i+2]) - { - case '0': c += 0; break; - case '1': c += 1; break; - case '2': c += 2; break; - case '3': c += 3; break; - case '4': c += 4; break; - case '5': c += 5; break; - case '6': c += 6; break; - case '7': c += 7; break; - case '8': c += 8; break; - case '9': c += 9; break; - case 'a': c += 10; break; - case 'b': c += 11; break; - case 'c': c += 12; break; - case 'd': c += 13; break; - case 'e': c += 14; break; - case 'f': c += 15; break; - default: - Q_ASSERT (false); - } - - u.push_back (static_cast(c)); - - // skip the two characters - i += 2; + { + case '0': c += 0; break; + case '1': c += 1; break; + case '2': c += 2; break; + case '3': c += 3; break; + case '4': c += 4; break; + case '5': c += 5; break; + case '6': c += 6; break; + case '7': c += 7; break; + case '8': c += 8; break; + case '9': c += 9; break; + case 'a': c += 10; break; + case 'b': c += 11; break; + case 'c': c += 12; break; + case 'd': c += 13; break; + case 'e': c += 14; break; + case 'f': c += 15; break; + default: + Q_ASSERT (false); + } + + u.push_back (static_cast(c)); + + // skip the two characters + i += 2; } QString v (u.c_str()); diff --git a/xml_parameter_reader.h b/xml_parameter_reader.h index f2789d0..a928531 100644 --- a/xml_parameter_reader.h +++ b/xml_parameter_reader.h @@ -49,6 +49,7 @@ namespace dealii * The parameter values will be stored in @p tree_widget. */ XMLParameterReader (QTreeWidget *tree_widget); + /** * This function reads the parameters from @p device into the tree_widget. * We use the QXmlStreamReader class for this. @@ -58,6 +59,7 @@ namespace dealii * otherwise an exception is thrown. */ bool read_xml_file (QIODevice *device); + /** * This function returns an error message. */ @@ -71,6 +73,7 @@ namespace dealii * or the end of the file is reached. In this case, an exception is thrown. */ void parse_parameters (); + /** * This functions parses a subsection. * and adds it as a child to @p parent. @@ -79,6 +82,7 @@ namespace dealii * otherwise the function itself recursively. */ void read_subsection_element (QTreeWidgetItem *parent); + /** * This function parses a parameter and * and adds it as a child to @p parent. @@ -94,27 +98,33 @@ namespace dealii * is thrown. */ void read_parameter_element (QTreeWidgetItem *parent); + /** * Reimplemented from the @ref ParameterHandler class. * Unmangle a string @p s into its original form. */ QString demangle (const QString &s); + /** * This helper function creates a new child of @p item in the tree. */ QTreeWidgetItem *create_child_item(QTreeWidgetItem *item); + /** * The QXmlStreamReader object for reading XML elements. */ QXmlStreamReader xml; + /** * A pointer to the tree structure. */ QTreeWidget *tree_widget; + /** * An icon for subsections in the tree structure. */ QIcon subsection_icon; + /** * An icon for parameters in the tree structure. */ diff --git a/xml_parameter_writer.cpp b/xml_parameter_writer.cpp index 4e33312..cbaa9e4 100644 --- a/xml_parameter_writer.cpp +++ b/xml_parameter_writer.cpp @@ -26,21 +26,27 @@ namespace dealii XMLParameterWriter::XMLParameterWriter(QTreeWidget *tree_widget) : tree_widget(tree_widget) { - xml.setAutoFormatting(true); // enable auto-formatting + xml.setAutoFormatting(true); } 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 + xml.setDevice(device); + + // write the head + xml.writeStartDocument(); + + // write the root element + xml.writeStartElement("ParameterHandler"); + + // loop over the elements and write them for (int i = 0; i < tree_widget->topLevelItemCount(); ++i) - write_item(tree_widget->topLevelItem(i)); // and write the items + write_item(tree_widget->topLevelItem(i)); - xml.writeEndDocument() ; // close the first element + // close the first element + xml.writeEndDocument(); return true; } @@ -49,40 +55,44 @@ namespace dealii void XMLParameterWriter::write_item(QTreeWidgetItem *item) { - QString tag_name = mangle(item->text(0)); // store the element name + // store the element name + QString tag_name = mangle(item->text(0)); - xml.writeStartElement(tag_name); // and write to the file + // and write to the file + xml.writeStartElement(tag_name); - if (!item->text(1).isEmpty()) // if the "value"-entry of this item is not empty - { // we have a parameter + // if the "value"-entry of this item is not empty, write a parameter + if (!item->text(1).isEmpty()) + { xml.writeTextElement("value", item->data(1,Qt::EditRole).toString()); - xml.writeTextElement("default_value", item->text(2)); // and we write its values + xml.writeTextElement("default_value", item->text(2)); 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 + // go over the childrens recursively + for (int i = 0; i < item->childCount(); ++i) write_item(item->child(i)); - xml.writeEndElement(); // write closing + // write closing + xml.writeEndElement(); } 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 + // this function is copied from the ParameterHandler class and adapted to mangle QString + std::string s_temp (s.toStdString()); + + std::string u; u.reserve (s_temp.size()); static const std::string allowed_characters ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); - // for all parts of the string, see - // if it is an allowed character or - // not + // for all parts of the string, see if it is an allowed character or not for (unsigned int i=0; itree_widget * to @p device in XML format. We use the QXmlStreamWriter class @@ -73,6 +74,7 @@ namespace dealii * and write_item is called recursively to write the next item. */ void write_item (QTreeWidgetItem *item); + /** * Reimplemented from the @ref ParameterHandler class. * Mangle a string @p s so that it @@ -80,12 +82,14 @@ namespace dealii * characters or spaces. */ QString mangle (const QString &s); + /** * An QXmlStreamWriter object * which implements the functionalities * we need for writing parameters to XML files. */ QXmlStreamWriter xml; + /** * A pointer to the QTreeWidget structure * which stores the parameters.