All: Reformat according to new standard
This commit is contained in:
committed by
Kacper Donat
parent
eafd18dac0
commit
25c3ba7338
@@ -21,24 +21,23 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
|
||||
# include <QApplication>
|
||||
# include <QButtonGroup>
|
||||
# include <QCompleter>
|
||||
# include <QCryptographicHash>
|
||||
# include <QDialogButtonBox>
|
||||
# include <QDir>
|
||||
# include <QGridLayout>
|
||||
# include <QGroupBox>
|
||||
# include <QLineEdit>
|
||||
# include <QPushButton>
|
||||
# include <QRadioButton>
|
||||
# include <QRegularExpression>
|
||||
# include <QRegularExpressionMatch>
|
||||
# include <QResizeEvent>
|
||||
# include <QStandardPaths>
|
||||
# include <QStyle>
|
||||
# include <QUrl>
|
||||
#include <QApplication>
|
||||
#include <QButtonGroup>
|
||||
#include <QCompleter>
|
||||
#include <QCryptographicHash>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDir>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionMatch>
|
||||
#include <QResizeEvent>
|
||||
#include <QStandardPaths>
|
||||
#include <QStyle>
|
||||
#include <QUrl>
|
||||
|
||||
|
||||
#include <Base/Parameter.h>
|
||||
@@ -59,8 +58,11 @@ bool DialogOptions::dontUseNativeFileDialog()
|
||||
constexpr bool notNativeDialog = false;
|
||||
#endif
|
||||
|
||||
ParameterGrp::handle group = App::GetApplication().GetUserParameter().
|
||||
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Dialog");
|
||||
ParameterGrp::handle group = App::GetApplication()
|
||||
.GetUserParameter()
|
||||
.GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")
|
||||
->GetGroup("Dialog");
|
||||
return group->GetBool("DontUseNativeDialog", notNativeDialog);
|
||||
}
|
||||
|
||||
@@ -72,15 +74,18 @@ bool DialogOptions::dontUseNativeColorDialog()
|
||||
constexpr bool notNativeDialog = false;
|
||||
#endif
|
||||
|
||||
ParameterGrp::handle group = App::GetApplication().GetUserParameter().
|
||||
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Dialog");
|
||||
ParameterGrp::handle group = App::GetApplication()
|
||||
.GetUserParameter()
|
||||
.GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")
|
||||
->GetGroup("Dialog");
|
||||
return group->GetBool("DontUseNativeColorDialog", notNativeDialog);
|
||||
}
|
||||
|
||||
/* TRANSLATOR Gui::FileDialog */
|
||||
|
||||
FileDialog::FileDialog(QWidget * parent)
|
||||
: QFileDialog(parent)
|
||||
FileDialog::FileDialog(QWidget* parent)
|
||||
: QFileDialog(parent)
|
||||
{
|
||||
connect(this, &QFileDialog::filterSelected, this, &FileDialog::onSelectedFilter);
|
||||
}
|
||||
@@ -122,9 +127,12 @@ QList<QUrl> FileDialog::fetchSidebarUrls()
|
||||
|
||||
bool FileDialog::hasSuffix(const QString& ext) const
|
||||
{
|
||||
QRegularExpression rx(QStringLiteral("\\*.(%1)\\W").arg(ext), QRegularExpression::CaseInsensitiveOption);
|
||||
QRegularExpression rx(
|
||||
QStringLiteral("\\*.(%1)\\W").arg(ext),
|
||||
QRegularExpression::CaseInsensitiveOption
|
||||
);
|
||||
QStringList filters = nameFilters();
|
||||
for (const auto & str : filters) {
|
||||
for (const auto& str : filters) {
|
||||
if (rx.match(str).hasMatch()) {
|
||||
return true;
|
||||
}
|
||||
@@ -149,8 +157,9 @@ void FileDialog::accept()
|
||||
file = QStringLiteral("%1.%2").arg(file, ext);
|
||||
// That's the built-in line edit
|
||||
auto fileNameEdit = this->findChild<QLineEdit*>(QStringLiteral("fileNameEdit"));
|
||||
if (fileNameEdit)
|
||||
if (fileNameEdit) {
|
||||
fileNameEdit->setText(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,16 +183,24 @@ void FileDialog::getSuffixesDescription(QStringList& suffixes, const QString* su
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a convenience static function that will return a file name selected by the user. The file does not have to exist.
|
||||
* This is a convenience static function that will return a file name selected by the user. The file
|
||||
* does not have to exist.
|
||||
*/
|
||||
QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption, const QString & dir,
|
||||
const QString & filter, QString * selectedFilter, Options options)
|
||||
QString FileDialog::getSaveFileName(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter,
|
||||
QString* selectedFilter,
|
||||
Options options
|
||||
)
|
||||
{
|
||||
QString dirName = dir;
|
||||
bool hasFilename = false;
|
||||
if (dirName.isEmpty()) {
|
||||
dirName = getWorkingDirectory();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
QFileInfo fi(dir);
|
||||
if (fi.isRelative()) {
|
||||
dirName = getWorkingDirectory();
|
||||
@@ -196,7 +213,7 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
|
||||
// get the suffix for the filter: use the selected filter if there is one,
|
||||
// otherwise find the first valid suffix in the complete list of filters
|
||||
const QString *filterToSearch;
|
||||
const QString* filterToSearch;
|
||||
if (selectedFilter && !selectedFilter->isEmpty()) {
|
||||
filterToSearch = selectedFilter;
|
||||
}
|
||||
@@ -218,12 +235,13 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
}
|
||||
|
||||
QString windowTitle = caption;
|
||||
if (windowTitle.isEmpty())
|
||||
if (windowTitle.isEmpty()) {
|
||||
windowTitle = FileDialog::tr("Save As");
|
||||
}
|
||||
|
||||
// NOTE: We must not change the specified file name afterwards as we may return the name of an already
|
||||
// existing file. Hence we must extract the first matching suffix from the filter list and append it
|
||||
// before showing the file dialog.
|
||||
// NOTE: We must not change the specified file name afterwards as we may return the name of an
|
||||
// already existing file. Hence we must extract the first matching suffix from the filter list
|
||||
// and append it before showing the file dialog.
|
||||
QString file;
|
||||
if (DialogOptions::dontUseNativeFileDialog()) {
|
||||
QList<QUrl> urls = fetchSidebarUrls();
|
||||
@@ -239,17 +257,20 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
dlg.setFileMode(QFileDialog::AnyFile);
|
||||
dlg.setAcceptMode(QFileDialog::AcceptSave);
|
||||
dlg.setDirectory(dirName);
|
||||
if (hasFilename)
|
||||
if (hasFilename) {
|
||||
dlg.selectFile(dirName);
|
||||
}
|
||||
dlg.setNameFilters(filter.split(QLatin1String(";;")));
|
||||
if (selectedFilter && !selectedFilter->isEmpty())
|
||||
if (selectedFilter && !selectedFilter->isEmpty()) {
|
||||
dlg.selectNameFilter(*selectedFilter);
|
||||
}
|
||||
dlg.onSelectedFilter(dlg.selectedNameFilter());
|
||||
dlg.setOption(QFileDialog::HideNameFilterDetails, false);
|
||||
dlg.setOption(QFileDialog::DontConfirmOverwrite, false);
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
if (selectedFilter)
|
||||
if (selectedFilter) {
|
||||
*selectedFilter = dlg.selectedNameFilter();
|
||||
}
|
||||
file = dlg.selectedFiles().constFirst();
|
||||
}
|
||||
}
|
||||
@@ -261,7 +282,8 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
if (!file.isEmpty()) {
|
||||
setWorkingDirectory(file);
|
||||
return file;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -269,13 +291,18 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
/**
|
||||
* This is a convenience static function that will return an existing directory selected by the user.
|
||||
*/
|
||||
QString FileDialog::getExistingDirectory( QWidget * parent, const QString & caption, const QString & dir, Options options )
|
||||
QString FileDialog::getExistingDirectory(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
Options options
|
||||
)
|
||||
{
|
||||
QString path = QFileDialog::getExistingDirectory(parent, caption, dir, options);
|
||||
// valid path was selected
|
||||
if ( !path.isEmpty() ) {
|
||||
if (!path.isEmpty()) {
|
||||
QDir d(path);
|
||||
path = d.path(); // get path in Qt manner
|
||||
path = d.path(); // get path in Qt manner
|
||||
}
|
||||
|
||||
return path;
|
||||
@@ -285,8 +312,14 @@ QString FileDialog::getExistingDirectory( QWidget * parent, const QString & capt
|
||||
* This is a convenience static function that returns an existing file selected by the user.
|
||||
* If the user pressed Cancel, it returns a null string.
|
||||
*/
|
||||
QString FileDialog::getOpenFileName(QWidget * parent, const QString & caption, const QString & dir,
|
||||
const QString & filter, QString * selectedFilter, Options options)
|
||||
QString FileDialog::getOpenFileName(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter,
|
||||
QString* selectedFilter,
|
||||
Options options
|
||||
)
|
||||
{
|
||||
QString dirName = dir;
|
||||
if (dirName.isEmpty()) {
|
||||
@@ -294,8 +327,9 @@ QString FileDialog::getOpenFileName(QWidget * parent, const QString & caption, c
|
||||
}
|
||||
|
||||
QString windowTitle = caption;
|
||||
if (windowTitle.isEmpty())
|
||||
if (windowTitle.isEmpty()) {
|
||||
windowTitle = FileDialog::tr("Open");
|
||||
}
|
||||
|
||||
QString file;
|
||||
if (DialogOptions::dontUseNativeFileDialog()) {
|
||||
@@ -314,11 +348,13 @@ QString FileDialog::getOpenFileName(QWidget * parent, const QString & caption, c
|
||||
dlg.setDirectory(dirName);
|
||||
dlg.setNameFilters(filter.split(QLatin1String(";;")));
|
||||
dlg.setOption(QFileDialog::HideNameFilterDetails, false);
|
||||
if (selectedFilter && !selectedFilter->isEmpty())
|
||||
if (selectedFilter && !selectedFilter->isEmpty()) {
|
||||
dlg.selectNameFilter(*selectedFilter);
|
||||
}
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
if (selectedFilter)
|
||||
if (selectedFilter) {
|
||||
*selectedFilter = dlg.selectedNameFilter();
|
||||
}
|
||||
file = dlg.selectedFiles().constFirst();
|
||||
}
|
||||
}
|
||||
@@ -330,16 +366,24 @@ QString FileDialog::getOpenFileName(QWidget * parent, const QString & caption, c
|
||||
if (!file.isEmpty()) {
|
||||
setWorkingDirectory(file);
|
||||
return file;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a convenience static function that will return one or more existing files selected by the user.
|
||||
* This is a convenience static function that will return one or more existing files selected by the
|
||||
* user.
|
||||
*/
|
||||
QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & caption, const QString & dir,
|
||||
const QString & filter, QString * selectedFilter, Options options)
|
||||
QStringList FileDialog::getOpenFileNames(
|
||||
QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter,
|
||||
QString* selectedFilter,
|
||||
Options options
|
||||
)
|
||||
{
|
||||
QString dirName = dir;
|
||||
if (dirName.isEmpty()) {
|
||||
@@ -347,8 +391,9 @@ QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & capt
|
||||
}
|
||||
|
||||
QString windowTitle = caption;
|
||||
if (windowTitle.isEmpty())
|
||||
if (windowTitle.isEmpty()) {
|
||||
windowTitle = FileDialog::tr("Open");
|
||||
}
|
||||
|
||||
QStringList files;
|
||||
if (DialogOptions::dontUseNativeFileDialog()) {
|
||||
@@ -367,17 +412,19 @@ QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & capt
|
||||
dlg.setDirectory(dirName);
|
||||
dlg.setNameFilters(filter.split(QLatin1String(";;")));
|
||||
dlg.setOption(QFileDialog::HideNameFilterDetails, false);
|
||||
if (selectedFilter && !selectedFilter->isEmpty())
|
||||
if (selectedFilter && !selectedFilter->isEmpty()) {
|
||||
dlg.selectNameFilter(*selectedFilter);
|
||||
}
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
if (selectedFilter)
|
||||
if (selectedFilter) {
|
||||
*selectedFilter = dlg.selectedNameFilter();
|
||||
}
|
||||
files = dlg.selectedFiles();
|
||||
}
|
||||
}
|
||||
else {
|
||||
files = QFileDialog::getOpenFileNames(parent, windowTitle, dirName, filter, selectedFilter, options);
|
||||
for (auto & file : files) {
|
||||
for (auto& file : files) {
|
||||
file = QDir::fromNativeSeparators(file);
|
||||
}
|
||||
}
|
||||
@@ -411,10 +458,12 @@ void FileDialog::setWorkingDirectory(const QString& dir)
|
||||
QString dirName = dir;
|
||||
if (!dir.isEmpty()) {
|
||||
QFileInfo info(dir);
|
||||
if (!info.exists() || info.isFile())
|
||||
if (!info.exists() || info.isFile()) {
|
||||
dirName = info.absolutePath();
|
||||
else
|
||||
}
|
||||
else {
|
||||
dirName = info.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
|
||||
workingDirectory = dirName;
|
||||
@@ -428,12 +477,16 @@ void FileDialog::setWorkingDirectory(const QString& dir)
|
||||
QString FileDialog::restoreLocation()
|
||||
{
|
||||
std::string path = App::GetApplication().Config()["UserHomePath"];
|
||||
Base::Reference<ParameterGrp> hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")->GetGroup("General");
|
||||
Base::Reference<ParameterGrp> hPath = App::GetApplication()
|
||||
.GetUserParameter()
|
||||
.GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")
|
||||
->GetGroup("General");
|
||||
std::string dir = hPath->GetASCII("FileOpenSavePath", path.c_str());
|
||||
QFileInfo fi(QString::fromUtf8(dir.c_str()));
|
||||
if (!fi.exists())
|
||||
if (!fi.exists()) {
|
||||
dir = path;
|
||||
}
|
||||
return QString::fromUtf8(dir.c_str());
|
||||
}
|
||||
|
||||
@@ -443,8 +496,11 @@ QString FileDialog::restoreLocation()
|
||||
*/
|
||||
void FileDialog::saveLocation(const QString& dirName)
|
||||
{
|
||||
Base::Reference<ParameterGrp> hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")->GetGroup("General");
|
||||
Base::Reference<ParameterGrp> hPath = App::GetApplication()
|
||||
.GetUserParameter()
|
||||
.GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")
|
||||
->GetGroup("General");
|
||||
hPath->SetASCII("FileOpenSavePath", dirName.toUtf8());
|
||||
}
|
||||
|
||||
@@ -452,16 +508,16 @@ void FileDialog::saveLocation(const QString& dirName)
|
||||
|
||||
/* TRANSLATOR Gui::FileOptionsDialog */
|
||||
|
||||
FileOptionsDialog::FileOptionsDialog( QWidget* parent, Qt::WindowFlags fl )
|
||||
: QFileDialog( parent, fl )
|
||||
, extensionPos(ExtensionRight)
|
||||
FileOptionsDialog::FileOptionsDialog(QWidget* parent, Qt::WindowFlags fl)
|
||||
: QFileDialog(parent, fl)
|
||||
, extensionPos(ExtensionRight)
|
||||
{
|
||||
extensionButton = new QPushButton( this );
|
||||
extensionButton->setText( tr( "Extended" ) );
|
||||
extensionButton = new QPushButton(this);
|
||||
extensionButton->setText(tr("Extended"));
|
||||
|
||||
setOption(QFileDialog::DontUseNativeDialog);
|
||||
|
||||
//search for the grid layout and add the new button
|
||||
// search for the grid layout and add the new button
|
||||
auto grid = this->findChild<QGridLayout*>();
|
||||
grid->addWidget(extensionButton, 4, 2, Qt::AlignLeft);
|
||||
|
||||
@@ -480,10 +536,10 @@ void FileOptionsDialog::accept()
|
||||
QString ext = fi.suffix();
|
||||
ext.prepend(QLatin1String("*."));
|
||||
QStringList filters = this->nameFilters();
|
||||
bool ok=false;
|
||||
bool ok = false;
|
||||
// Compare the given suffix with the suffixes of all filters
|
||||
QString filter;
|
||||
for (const auto & it : filters) {
|
||||
for (const auto& it : filters) {
|
||||
if (it.contains(ext)) {
|
||||
filter = it;
|
||||
ok = true;
|
||||
@@ -512,17 +568,20 @@ void FileOptionsDialog::accept()
|
||||
QRegularExpression rx(QLatin1String(R"(\(\*.(\w+))"));
|
||||
QString suf = selectedNameFilter();
|
||||
auto match = rx.match(suf);
|
||||
if (match.hasMatch())
|
||||
if (match.hasMatch()) {
|
||||
suf = match.captured(1);
|
||||
if (ext.isEmpty())
|
||||
}
|
||||
if (ext.isEmpty()) {
|
||||
setDefaultSuffix(suf);
|
||||
}
|
||||
else if (ext.toLower() != suf.toLower()) {
|
||||
fn = QStringLiteral("%1.%2").arg(fn, suf);
|
||||
selectFile(fn);
|
||||
// That's the built-in line edit (fixes Debian bug #811200)
|
||||
auto fileNameEdit = this->findChild<QLineEdit*>(QStringLiteral("fileNameEdit"));
|
||||
if (fileNameEdit)
|
||||
if (fileNameEdit) {
|
||||
fileNameEdit->setText(fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,8 +595,8 @@ void FileOptionsDialog::toggleExtension()
|
||||
if (showIt) {
|
||||
oldSize = size();
|
||||
QSize s(extensionWidget->sizeHint()
|
||||
.expandedTo(extensionWidget->minimumSize())
|
||||
.boundedTo(extensionWidget->maximumSize()));
|
||||
.expandedTo(extensionWidget->minimumSize())
|
||||
.boundedTo(extensionWidget->maximumSize()));
|
||||
if (extensionPos == ExtensionRight) {
|
||||
setFixedSize(width() + s.width(), height());
|
||||
}
|
||||
@@ -558,8 +617,9 @@ void FileOptionsDialog::setOptionsWidget(FileOptionsDialog::ExtensionPosition po
|
||||
{
|
||||
extensionPos = pos;
|
||||
extensionWidget = w;
|
||||
if (extensionWidget->parentWidget() != this)
|
||||
if (extensionWidget->parentWidget() != this) {
|
||||
extensionWidget->setParent(this);
|
||||
}
|
||||
|
||||
auto grid = this->findChild<QGridLayout*>();
|
||||
|
||||
@@ -576,8 +636,9 @@ void FileOptionsDialog::setOptionsWidget(FileOptionsDialog::ExtensionPosition po
|
||||
|
||||
oldSize = size();
|
||||
w->hide();
|
||||
if (show)
|
||||
if (show) {
|
||||
toggleExtension();
|
||||
}
|
||||
}
|
||||
|
||||
QWidget* FileOptionsDialog::getOptionsWidget() const
|
||||
@@ -599,9 +660,9 @@ QIcon FileIconProvider::icon(IconType type) const
|
||||
return QFileIconProvider::icon(type);
|
||||
}
|
||||
|
||||
QIcon FileIconProvider::icon(const QFileInfo & info) const
|
||||
QIcon FileIconProvider::icon(const QFileInfo& info) const
|
||||
{
|
||||
auto toUrl = [](const QFileInfo & info) {
|
||||
auto toUrl = [](const QFileInfo& info) {
|
||||
QFileInfo fi(info);
|
||||
fi.makeAbsolute();
|
||||
QString fileName = fi.absoluteFilePath();
|
||||
@@ -613,7 +674,9 @@ QIcon FileIconProvider::icon(const QFileInfo & info) const
|
||||
};
|
||||
|
||||
auto urlToThumbnail = [](const QString& filename) {
|
||||
QString hash = QString::fromLatin1(QCryptographicHash::hash(filename.toUtf8(), QCryptographicHash::Md5).toHex());
|
||||
QString hash = QString::fromLatin1(
|
||||
QCryptographicHash::hash(filename.toUtf8(), QCryptographicHash::Md5).toHex()
|
||||
);
|
||||
QString cache = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
|
||||
return QStringLiteral("%1/thumbnails/normal/%2.png").arg(cache, hash);
|
||||
};
|
||||
@@ -621,8 +684,9 @@ QIcon FileIconProvider::icon(const QFileInfo & info) const
|
||||
auto iconFromFile = [](const QString& filename) {
|
||||
if (QFile::exists(filename)) {
|
||||
QIcon icon(filename);
|
||||
if (!icon.isNull())
|
||||
if (!icon.isNull()) {
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
|
||||
return QIcon(QStringLiteral(":/icons/freecad-doc.png"));
|
||||
@@ -639,13 +703,13 @@ QIcon FileIconProvider::icon(const QFileInfo & info) const
|
||||
QIcon darkIcon;
|
||||
int w = QApplication::style()->pixelMetric(QStyle::PM_ListViewIconSize);
|
||||
darkIcon.addPixmap(icon.pixmap(w, w, QIcon::Disabled, QIcon::Off), QIcon::Normal, QIcon::Off);
|
||||
darkIcon.addPixmap(icon.pixmap(w, w, QIcon::Disabled, QIcon::On ), QIcon::Normal, QIcon::On );
|
||||
darkIcon.addPixmap(icon.pixmap(w, w, QIcon::Disabled, QIcon::On), QIcon::Normal, QIcon::On);
|
||||
return darkIcon;
|
||||
}
|
||||
return QFileIconProvider::icon(info);
|
||||
}
|
||||
|
||||
QString FileIconProvider::type(const QFileInfo & info) const
|
||||
QString FileIconProvider::type(const QFileInfo& info) const
|
||||
{
|
||||
return QFileIconProvider::type(info);
|
||||
}
|
||||
@@ -657,23 +721,23 @@ QString FileIconProvider::type(const QFileInfo & info) const
|
||||
/**
|
||||
* Constructs a file chooser called \a name with the parent \a parent.
|
||||
*/
|
||||
FileChooser::FileChooser ( QWidget * parent )
|
||||
: QWidget(parent)
|
||||
, md( File )
|
||||
, accMode( AcceptOpen )
|
||||
, _filter( QString() )
|
||||
FileChooser::FileChooser(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, md(File)
|
||||
, accMode(AcceptOpen)
|
||||
, _filter(QString())
|
||||
{
|
||||
auto layout = new QHBoxLayout( this );
|
||||
layout->setContentsMargins( 0, 0, 0, 0 );
|
||||
layout->setSpacing( 2 );
|
||||
auto layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(2);
|
||||
|
||||
lineEdit = new QLineEdit ( this );
|
||||
completer = new QCompleter ( this );
|
||||
completer->setMaxVisibleItems( 12 );
|
||||
fs_model = new QFileSystemModel( completer );
|
||||
lineEdit = new QLineEdit(this);
|
||||
completer = new QCompleter(this);
|
||||
completer->setMaxVisibleItems(12);
|
||||
fs_model = new QFileSystemModel(completer);
|
||||
fs_model->setRootPath(QStringLiteral(""));
|
||||
completer->setModel( fs_model );
|
||||
lineEdit->setCompleter( completer );
|
||||
completer->setModel(fs_model);
|
||||
lineEdit->setCompleter(completer);
|
||||
|
||||
|
||||
connect(lineEdit, &QLineEdit::textChanged, this, &FileChooser::fileNameChanged);
|
||||
@@ -681,8 +745,8 @@ FileChooser::FileChooser ( QWidget * parent )
|
||||
|
||||
button = new QPushButton(QStringLiteral("…"), this);
|
||||
|
||||
#if defined (Q_OS_MACOS)
|
||||
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // layout size from QMacStyle was not correct
|
||||
#if defined(Q_OS_MACOS)
|
||||
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // layout size from QMacStyle was not correct
|
||||
#endif
|
||||
|
||||
layout->addWidget(lineEdit, 1);
|
||||
@@ -724,9 +788,9 @@ void FileChooser::editingFinished()
|
||||
/**
|
||||
* Sets the file name \a fn.
|
||||
*/
|
||||
void FileChooser::setFileName( const QString& fn )
|
||||
void FileChooser::setFileName(const QString& fn)
|
||||
{
|
||||
lineEdit->setText( fn );
|
||||
lineEdit->setText(fn);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -746,14 +810,31 @@ void FileChooser::chooseFile()
|
||||
}
|
||||
|
||||
QString fn;
|
||||
if ( mode() == File ) {
|
||||
if (acceptMode() == AcceptOpen)
|
||||
fn = QFileDialog::getOpenFileName(this, tr( "Select a File" ), prechosenDirectory, _filter, nullptr, dlgOpt);
|
||||
else
|
||||
fn = QFileDialog::getSaveFileName(this, tr( "Select a File" ), prechosenDirectory, _filter, nullptr, dlgOpt);
|
||||
} else {
|
||||
if (mode() == File) {
|
||||
if (acceptMode() == AcceptOpen) {
|
||||
fn = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Select a File"),
|
||||
prechosenDirectory,
|
||||
_filter,
|
||||
nullptr,
|
||||
dlgOpt
|
||||
);
|
||||
}
|
||||
else {
|
||||
fn = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
tr("Select a File"),
|
||||
prechosenDirectory,
|
||||
_filter,
|
||||
nullptr,
|
||||
dlgOpt
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
QFileDialog::Options option = QFileDialog::ShowDirsOnly | dlgOpt;
|
||||
fn = QFileDialog::getExistingDirectory( this, tr( "Select a Directory" ), prechosenDirectory,option );
|
||||
fn = QFileDialog::getExistingDirectory(this, tr("Select a Directory"), prechosenDirectory, option);
|
||||
}
|
||||
|
||||
if (!fn.isEmpty()) {
|
||||
@@ -790,7 +871,7 @@ FileChooser::Mode FileChooser::mode() const
|
||||
* If \a m is File the widget is set to choose a file, otherwise it is set to
|
||||
* choose a directory.
|
||||
*/
|
||||
void FileChooser::setMode( FileChooser::Mode m )
|
||||
void FileChooser::setMode(FileChooser::Mode m)
|
||||
{
|
||||
md = m;
|
||||
Q_EMIT modeChanged(md);
|
||||
@@ -812,7 +893,7 @@ QString FileChooser::filter() const
|
||||
/**
|
||||
* Sets the filter for choosing a file.
|
||||
*/
|
||||
void FileChooser::setFilter ( const QString& filter )
|
||||
void FileChooser::setFilter(const QString& filter)
|
||||
{
|
||||
_filter = filter;
|
||||
Q_EMIT filterChanged(_filter);
|
||||
@@ -843,8 +924,8 @@ QString FileChooser::buttonText() const
|
||||
|
||||
/* TRANSLATOR Gui::SelectModule */
|
||||
|
||||
SelectModule::SelectModule (const QString& type, const SelectModule::Dict& types, QWidget * parent)
|
||||
: QDialog(parent, Qt::WindowTitleHint)
|
||||
SelectModule::SelectModule(const QString& type, const SelectModule::Dict& types, QWidget* parent)
|
||||
: QDialog(parent, Qt::WindowTitleHint)
|
||||
{
|
||||
setWindowTitle(tr("Select Module"));
|
||||
groupBox = new QGroupBox(this);
|
||||
@@ -916,8 +997,9 @@ SelectModule::~SelectModule() = default;
|
||||
|
||||
void SelectModule::accept()
|
||||
{
|
||||
if (group->checkedButton())
|
||||
if (group->checkedButton()) {
|
||||
QDialog::accept();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectModule::reject()
|
||||
@@ -953,7 +1035,7 @@ SelectModule::Dict SelectModule::exportHandler(const QStringList& fileNames, con
|
||||
it = filterList.find((const char*)filter.toUtf8());
|
||||
if (it != filterList.end()) {
|
||||
QString module = QString::fromLatin1(it->second.c_str());
|
||||
for (const auto & fileName : fileNames) {
|
||||
for (const auto& fileName : fileNames) {
|
||||
dict[fileName] = module;
|
||||
}
|
||||
return dict;
|
||||
@@ -963,11 +1045,13 @@ SelectModule::Dict SelectModule::exportHandler(const QStringList& fileNames, con
|
||||
// the global filter (or no filter) was selected. We now try to sort filetypes that are
|
||||
// handled by more than one module and ask to the user to select one.
|
||||
QMap<QString, SelectModule::Dict> filetypeHandler;
|
||||
QMap<QString, QStringList > fileExtension;
|
||||
for (const auto & fileName : fileNames) {
|
||||
QMap<QString, QStringList> fileExtension;
|
||||
for (const auto& fileName : fileNames) {
|
||||
QFileInfo fi(fileName);
|
||||
QString ext = fi.completeSuffix().toLower();
|
||||
std::map<std::string, std::string> filters = App::GetApplication().getExportFilters(ext.toLatin1());
|
||||
std::map<std::string, std::string> filters = App::GetApplication().getExportFilters(
|
||||
ext.toLatin1()
|
||||
);
|
||||
|
||||
if (filters.empty()) {
|
||||
ext = fi.suffix().toLower();
|
||||
@@ -975,23 +1059,29 @@ SelectModule::Dict SelectModule::exportHandler(const QStringList& fileNames, con
|
||||
}
|
||||
|
||||
fileExtension[ext].push_back(fileName);
|
||||
for (const auto & filter : filters)
|
||||
filetypeHandler[ext][QString::fromUtf8(filter.first.c_str())] = QString::fromLatin1(filter.second.c_str());
|
||||
for (const auto& filter : filters) {
|
||||
filetypeHandler[ext][QString::fromUtf8(filter.first.c_str())] = QString::fromLatin1(
|
||||
filter.second.c_str()
|
||||
);
|
||||
}
|
||||
// set the default module handler
|
||||
if (!filters.empty())
|
||||
if (!filters.empty()) {
|
||||
dict[fileName] = QString::fromLatin1(filters.begin()->second.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
for (QMap<QString, SelectModule::Dict>::const_iterator it = filetypeHandler.cbegin();
|
||||
it != filetypeHandler.cend(); ++it) {
|
||||
it != filetypeHandler.cend();
|
||||
++it) {
|
||||
if (it.value().size() > 1) {
|
||||
SelectModule dlg(it.key(),it.value(), getMainWindow());
|
||||
SelectModule dlg(it.key(), it.value(), getMainWindow());
|
||||
QApplication::beep();
|
||||
if (dlg.exec()) {
|
||||
QString mod = dlg.getModule();
|
||||
const QStringList& files = fileExtension[it.key()];
|
||||
for (const auto & file : files)
|
||||
for (const auto& file : files) {
|
||||
dict[file] = mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1015,7 +1105,7 @@ SelectModule::Dict SelectModule::importHandler(const QStringList& fileNames, con
|
||||
it = filterList.find((const char*)filter.toUtf8());
|
||||
if (it != filterList.end()) {
|
||||
QString module = QString::fromLatin1(it->second.c_str());
|
||||
for (const auto & fileName : fileNames) {
|
||||
for (const auto& fileName : fileNames) {
|
||||
dict[fileName] = module;
|
||||
}
|
||||
return dict;
|
||||
@@ -1025,11 +1115,13 @@ SelectModule::Dict SelectModule::importHandler(const QStringList& fileNames, con
|
||||
// the global filter (or no filter) was selected. We now try to sort filetypes that are
|
||||
// handled by more than one module and ask to the user to select one.
|
||||
QMap<QString, SelectModule::Dict> filetypeHandler;
|
||||
QMap<QString, QStringList > fileExtension;
|
||||
for (const auto & fileName : fileNames) {
|
||||
QMap<QString, QStringList> fileExtension;
|
||||
for (const auto& fileName : fileNames) {
|
||||
QFileInfo fi(fileName);
|
||||
QString ext = fi.completeSuffix().toLower();
|
||||
std::map<std::string, std::string> filters = App::GetApplication().getImportFilters(ext.toLatin1());
|
||||
std::map<std::string, std::string> filters = App::GetApplication().getImportFilters(
|
||||
ext.toLatin1()
|
||||
);
|
||||
|
||||
if (filters.empty()) {
|
||||
ext = fi.suffix().toLower();
|
||||
@@ -1037,22 +1129,27 @@ SelectModule::Dict SelectModule::importHandler(const QStringList& fileNames, con
|
||||
}
|
||||
|
||||
fileExtension[ext].push_back(fileName);
|
||||
for (const auto & filter : filters)
|
||||
filetypeHandler[ext][QString::fromUtf8(filter.first.c_str())] = QString::fromLatin1(filter.second.c_str());
|
||||
for (const auto& filter : filters) {
|
||||
filetypeHandler[ext][QString::fromUtf8(filter.first.c_str())] = QString::fromLatin1(
|
||||
filter.second.c_str()
|
||||
);
|
||||
}
|
||||
// set the default module handler
|
||||
if (!filters.empty())
|
||||
if (!filters.empty()) {
|
||||
dict[fileName] = QString::fromLatin1(filters.begin()->second.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
for (QMap<QString, SelectModule::Dict>::const_iterator it = filetypeHandler.cbegin();
|
||||
it != filetypeHandler.cend(); ++it) {
|
||||
it != filetypeHandler.cend();
|
||||
++it) {
|
||||
if (it.value().size() > 1) {
|
||||
SelectModule dlg(it.key(),it.value(), getMainWindow());
|
||||
SelectModule dlg(it.key(), it.value(), getMainWindow());
|
||||
QApplication::beep();
|
||||
if (dlg.exec()) {
|
||||
QString mod = dlg.getModule();
|
||||
const QStringList& files = fileExtension[it.key()];
|
||||
for (const auto & file : files) {
|
||||
for (const auto& file : files) {
|
||||
dict[file] = mod;
|
||||
}
|
||||
}
|
||||
@@ -1068,4 +1165,3 @@ SelectModule::Dict SelectModule::importHandler(const QStringList& fileNames, con
|
||||
|
||||
|
||||
#include "moc_FileDialog.cpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user