From 477488093dd5910cc5d244f588b6931248197d18 Mon Sep 17 00:00:00 2001 From: Rene Gassmoeller Date: Wed, 29 Mar 2017 20:34:42 -0600 Subject: [PATCH] Add multiple file dialog. Improve appearance. --- browse_lineedit.cpp | 10 ++++++++ browse_lineedit.h | 2 +- parameter_delegate.cpp | 58 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/browse_lineedit.cpp b/browse_lineedit.cpp index d2890b5..e35abde 100644 --- a/browse_lineedit.cpp +++ b/browse_lineedit.cpp @@ -37,6 +37,7 @@ namespace dealii QHBoxLayout *layout = new QHBoxLayout; + layout->setContentsMargins(1,1,1,1); layout->addWidget(line_editor); layout->addWidget(browse_button); setLayout(layout); @@ -109,6 +110,15 @@ namespace dealii break; }; + case files: + { + QStringList names = QFileDialog::getOpenFileNames(this, tr("Open Files"), + QDir::currentPath(), + tr("All Files (*.*)")); + name = names.join(","); + break; + }; + case directory: { name = QFileDialog::getExistingDirectory(this, tr("Open Directory"), diff --git a/browse_lineedit.h b/browse_lineedit.h index 1c14ec6..6abe7f0 100644 --- a/browse_lineedit.h +++ b/browse_lineedit.h @@ -54,7 +54,7 @@ namespace dealii * 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, files = 2}; /** * Constructor. The type of the browse dialog can be specified * by the flag BrowseType, the default is file. diff --git a/parameter_delegate.cpp b/parameter_delegate.cpp index 28fc27a..a2480f9 100644 --- a/parameter_delegate.cpp +++ b/parameter_delegate.cpp @@ -101,7 +101,8 @@ namespace dealii { QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description // stored in the StatusLine - QRegExp rx_string("\\b(Anything|MultipleSelection|List|Map)\\b"), + QRegExp rx_string("\\b(Anything|MultipleSelection|Map)\\b"), + rx_list("\\b(List)\\b"), rx_filename("\\b(FileName)\\b"), rx_dirname("\\b(DirectoryName)\\b"), rx_integer("\\b(Integer)\\b"), @@ -118,6 +119,28 @@ namespace dealii return line_editor; } + else if (rx_list.indexIn (pattern_description) != -1) // if the type is "List" + { + if (rx_filename.indexIn (pattern_description) != -1) + { + BrowseLineEdit * filename_editor = // choose a BrowseLineEditor + new BrowseLineEdit(BrowseLineEdit::files, parent); + + connect(filename_editor, SIGNAL(editingFinished()), + this, SLOT(commit_and_close_editor())); + + return filename_editor; + } + else + { + 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 + + return line_editor; + } + } else if (rx_filename.indexIn (pattern_description) != -1) // if the type is "FileName" { BrowseLineEdit * filename_editor = // choose a BrowseLineEditor @@ -245,7 +268,8 @@ namespace dealii // stored in the StatusLine - QRegExp rx_string("\\b(Anything|MultipleSelection|List|Map)\\b"), + QRegExp rx_string("\\b(Anything|MultipleSelection|Map)\\b"), + rx_list("\\b(List)\\b"), rx_filename("\\b(FileName)\\b"), rx_dirname("\\b(DirectoryName)\\b"), rx_selection("\\b(Selection)\\b"); @@ -254,6 +278,20 @@ namespace dealii { QItemDelegate::setEditorData(editor, index); } + else if (rx_list.indexIn (pattern_description) != -1) // if the type is "List" + { + if (rx_filename.indexIn (pattern_description) != -1) + { + 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 + { + QItemDelegate::setEditorData(editor, index); + } + } else if (rx_filename.indexIn (pattern_description) != -1) // if the type is "FileName" { QString file_name = index.data(Qt::DisplayRole).toString(); @@ -304,7 +342,8 @@ namespace dealii QString pattern_description = index.data(Qt::StatusTipRole).toString(); // load pattern description // stored in the StatusLine - QRegExp rx_string("\\b(Anything|MultipleSelection|List|Map)\\b"), + QRegExp rx_string("\\b(Anything|MultipleSelection|Map)\\b"), + rx_list("\\b(List)\\b"), rx_filename("\\b(FileName)\\b"), rx_dirname("\\b(DirectoryName)\\b"), rx_selection("\\b(Selection)\\b"); @@ -313,6 +352,19 @@ namespace dealii { QItemDelegate::setModelData(editor, model, index); } + else if (rx_list.indexIn (pattern_description) != -1) // if the type is "List" + { + if (rx_filename.indexIn (pattern_description) != -1) + { + BrowseLineEdit * filename_editor = qobject_cast(editor); // set the text from the editor + QString value = filename_editor->text(); + model->setData(index, value); + } + else + { + QItemDelegate::setModelData(editor, model, index); + } + } else if (rx_filename.indexIn (pattern_description) != -1) // if the type is "FileName" { BrowseLineEdit * filename_editor = qobject_cast(editor); // set the text from the editor -- 2.39.5