From e68191f777735e60f1952a103c08606b90260e9d Mon Sep 17 00:00:00 2001 From: zhitm Date: Thu, 21 Dec 2023 14:45:24 +0300 Subject: [PATCH 1/5] Add directory picker --- qrutils/widgets/dirPicker.cpp | 70 +++++++++++++++++++++++++++++++++++ qrutils/widgets/dirPicker.h | 57 ++++++++++++++++++++++++++++ qrutils/widgets/widgets.pri | 2 + 3 files changed, 129 insertions(+) create mode 100644 qrutils/widgets/dirPicker.cpp create mode 100644 qrutils/widgets/dirPicker.h diff --git a/qrutils/widgets/dirPicker.cpp b/qrutils/widgets/dirPicker.cpp new file mode 100644 index 0000000000..06382eb341 --- /dev/null +++ b/qrutils/widgets/dirPicker.cpp @@ -0,0 +1,70 @@ +/* Copyright 2017 CyberTech Labs Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +#include "dirPicker.h" +#include +#include +#include +#include +#include + +#include +#include + +using namespace qReal::ui; + + +dirPicker::dirPicker(QWidget *parent) + : QWidget(parent) +{ + mLabel = new QLabel(this); + mPathEditor = new QLineEdit(this); + QPushButton *button = new QPushButton(style()->standardIcon(QStyle::SP_DirIcon), tr("Browse..."), this); + QHBoxLayout *layout = new QHBoxLayout(this); + layout->addWidget(mLabel); + layout->addWidget(mPathEditor); + layout->addWidget(button); + connect(button, &QPushButton::clicked, this, &dirPicker::pick); +} + +void dirPicker::configure(const QString &settingsKey, const QString &title) +{ + mSettingsKey = settingsKey; + mLabel->setText(title); +} + +bool dirPicker::isSavedDirExist(){ + return QDir(SettingsManager::value(mSettingsKey).toString()).exists(); +} + +void dirPicker::save() const +{ + if (!mPathEditor->text().isEmpty() && !mSettingsKey.isEmpty()) { + SettingsManager::setValue(mSettingsKey, mPathEditor->text()); + } +} + +void dirPicker::restore() +{ + if (!mSettingsKey.isEmpty()) { + mPathEditor->setText(SettingsManager::value(mSettingsKey).toString()); + } +} + +void dirPicker::pick() +{ + QDir dirPath=QFileDialog::getExistingDirectory(this, "Get Any File"); + SettingsManager::setValue(mSettingsKey, dirPath.absolutePath()); + mPathEditor->setText(dirPath.absolutePath()); +} diff --git a/qrutils/widgets/dirPicker.h b/qrutils/widgets/dirPicker.h new file mode 100644 index 0000000000..e8a89d6e63 --- /dev/null +++ b/qrutils/widgets/dirPicker.h @@ -0,0 +1,57 @@ +/* Copyright 2017 CyberTech Labs Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +#pragma once + +#include + +#include + +class QLabel; +class QLineEdit; + +namespace qReal { +namespace ui { + +/// Picks some image from disk, saves into settings. +class QRUTILS_EXPORT dirPicker : public QWidget +{ + Q_OBJECT + +public: + explicit dirPicker(QWidget *parent = nullptr); + + /// Sets parameters of the image picker. + void configure(const QString &settingsKey, const QString &title); + + /// Saves picked location into settings. + void save() const; + + /// Restores last picked value. + void restore(); + + bool isSavedDirExist(); + + +private slots: + void pick(); + +private: + QString mSettingsKey; + QLabel *mLabel; + QLineEdit *mPathEditor; +}; + +} +} diff --git a/qrutils/widgets/widgets.pri b/qrutils/widgets/widgets.pri index c98cbd474e..a7041c2f84 100644 --- a/qrutils/widgets/widgets.pri +++ b/qrutils/widgets/widgets.pri @@ -14,6 +14,7 @@ HEADERS += \ $$PWD/colorListEditor.h \ + $$PWD/dirPicker.h \ $$PWD/paintWidget.h \ $$PWD/painterInterface.h \ $$PWD/searchLineEdit.h \ @@ -26,6 +27,7 @@ HEADERS += \ SOURCES += \ $$PWD/colorListEditor.cpp \ + $$PWD/dirPicker.cpp \ $$PWD/paintWidget.cpp \ $$PWD/searchLineEdit.cpp \ $$PWD/consoleDock.cpp \ From 01a37acf4519eebf89baca06e741b7e2bcb8c284 Mon Sep 17 00:00:00 2001 From: zhitm Date: Thu, 21 Dec 2023 15:59:06 +0300 Subject: [PATCH 2/5] Add translation for dirPicker --- qrtranslations/fr/qrutils_fr.ts | 8 ++++++++ qrtranslations/ru/qrutils_ru.ts | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/qrtranslations/fr/qrutils_fr.ts b/qrtranslations/fr/qrutils_fr.ts index d930d61d83..eacd8c6b85 100644 --- a/qrtranslations/fr/qrutils_fr.ts +++ b/qrtranslations/fr/qrutils_fr.ts @@ -507,6 +507,14 @@ + + qReal::ui::dirPicker + + + Browse... + + + utils::MetamodelGeneratorSupport diff --git a/qrtranslations/ru/qrutils_ru.ts b/qrtranslations/ru/qrutils_ru.ts index 36fc8f0fe9..9228a560dd 100644 --- a/qrtranslations/ru/qrutils_ru.ts +++ b/qrtranslations/ru/qrutils_ru.ts @@ -619,6 +619,14 @@ <строка>:<столбец> + + qReal::ui::dirPicker + + + Browse... + Обзор... + + utils::MetamodelGeneratorSupport From 92ba14e26f3d75af44ccaca880c7f7200a80f5a9 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 10 Jan 2025 18:36:49 +0300 Subject: [PATCH 3/5] Improve, format the code and add translations --- qrtranslations/fr/qrutils_fr.ts | 5 +++++ qrtranslations/ru/qrutils_ru.ts | 7 ++++++- qrutils/widgets/dirPicker.cpp | 11 ++++++----- qrutils/widgets/dirPicker.h | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/qrtranslations/fr/qrutils_fr.ts b/qrtranslations/fr/qrutils_fr.ts index eacd8c6b85..049e18fe93 100644 --- a/qrtranslations/fr/qrutils_fr.ts +++ b/qrtranslations/fr/qrutils_fr.ts @@ -514,6 +514,11 @@ Browse... + + + Select directory + + utils::MetamodelGeneratorSupport diff --git a/qrtranslations/ru/qrutils_ru.ts b/qrtranslations/ru/qrutils_ru.ts index 9228a560dd..f4ce671af8 100644 --- a/qrtranslations/ru/qrutils_ru.ts +++ b/qrtranslations/ru/qrutils_ru.ts @@ -624,7 +624,12 @@ Browse... - Обзор... + Обзор... + + + + Select directory + Выберите директорию diff --git a/qrutils/widgets/dirPicker.cpp b/qrutils/widgets/dirPicker.cpp index 06382eb341..90c3fd14dd 100644 --- a/qrutils/widgets/dirPicker.cpp +++ b/qrutils/widgets/dirPicker.cpp @@ -1,4 +1,4 @@ -/* Copyright 2017 CyberTech Labs Ltd. +/* Copyright 2025 CyberTech Labs Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,9 +27,9 @@ using namespace qReal::ui; dirPicker::dirPicker(QWidget *parent) : QWidget(parent) + , mLabel(new QLabel(this)) + , mPathEditor(new QLineEdit(this)) { - mLabel = new QLabel(this); - mPathEditor = new QLineEdit(this); QPushButton *button = new QPushButton(style()->standardIcon(QStyle::SP_DirIcon), tr("Browse..."), this); QHBoxLayout *layout = new QHBoxLayout(this); layout->addWidget(mLabel); @@ -44,7 +44,8 @@ void dirPicker::configure(const QString &settingsKey, const QString &title) mLabel->setText(title); } -bool dirPicker::isSavedDirExist(){ +bool dirPicker::isSavedDirExist() +{ return QDir(SettingsManager::value(mSettingsKey).toString()).exists(); } @@ -64,7 +65,7 @@ void dirPicker::restore() void dirPicker::pick() { - QDir dirPath=QFileDialog::getExistingDirectory(this, "Get Any File"); + QDir dirPath = QFileDialog::getExistingDirectory(this, tr("Select directory")); SettingsManager::setValue(mSettingsKey, dirPath.absolutePath()); mPathEditor->setText(dirPath.absolutePath()); } diff --git a/qrutils/widgets/dirPicker.h b/qrutils/widgets/dirPicker.h index e8a89d6e63..fb3deb74e3 100644 --- a/qrutils/widgets/dirPicker.h +++ b/qrutils/widgets/dirPicker.h @@ -1,4 +1,4 @@ -/* Copyright 2017 CyberTech Labs Ltd. +/* Copyright 2025 CyberTech Labs Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ #pragma once #include - #include class QLabel; @@ -41,6 +40,7 @@ class QRUTILS_EXPORT dirPicker : public QWidget /// Restores last picked value. void restore(); + /// Determines whether the picked location exists or not bool isSavedDirExist(); From a8c1b4e411b852b6bd8db5483fa9986e27b37bb2 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 10 Jan 2025 20:17:28 +0300 Subject: [PATCH 4/5] Rename the class according to the conventions --- qrutils/widgets/dirPicker.cpp | 14 +++++++------- qrutils/widgets/dirPicker.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qrutils/widgets/dirPicker.cpp b/qrutils/widgets/dirPicker.cpp index 90c3fd14dd..fb228103a4 100644 --- a/qrutils/widgets/dirPicker.cpp +++ b/qrutils/widgets/dirPicker.cpp @@ -25,7 +25,7 @@ using namespace qReal::ui; -dirPicker::dirPicker(QWidget *parent) +DirPicker::DirPicker(QWidget *parent) : QWidget(parent) , mLabel(new QLabel(this)) , mPathEditor(new QLineEdit(this)) @@ -35,35 +35,35 @@ dirPicker::dirPicker(QWidget *parent) layout->addWidget(mLabel); layout->addWidget(mPathEditor); layout->addWidget(button); - connect(button, &QPushButton::clicked, this, &dirPicker::pick); + connect(button, &QPushButton::clicked, this, &DirPicker::pick); } -void dirPicker::configure(const QString &settingsKey, const QString &title) +void DirPicker::configure(const QString &settingsKey, const QString &title) { mSettingsKey = settingsKey; mLabel->setText(title); } -bool dirPicker::isSavedDirExist() +bool DirPicker::isSavedDirExist() { return QDir(SettingsManager::value(mSettingsKey).toString()).exists(); } -void dirPicker::save() const +void DirPicker::save() const { if (!mPathEditor->text().isEmpty() && !mSettingsKey.isEmpty()) { SettingsManager::setValue(mSettingsKey, mPathEditor->text()); } } -void dirPicker::restore() +void DirPicker::restore() { if (!mSettingsKey.isEmpty()) { mPathEditor->setText(SettingsManager::value(mSettingsKey).toString()); } } -void dirPicker::pick() +void DirPicker::pick() { QDir dirPath = QFileDialog::getExistingDirectory(this, tr("Select directory")); SettingsManager::setValue(mSettingsKey, dirPath.absolutePath()); diff --git a/qrutils/widgets/dirPicker.h b/qrutils/widgets/dirPicker.h index fb3deb74e3..fa359bfbed 100644 --- a/qrutils/widgets/dirPicker.h +++ b/qrutils/widgets/dirPicker.h @@ -24,12 +24,12 @@ namespace qReal { namespace ui { /// Picks some image from disk, saves into settings. -class QRUTILS_EXPORT dirPicker : public QWidget +class QRUTILS_EXPORT DirPicker : public QWidget { Q_OBJECT public: - explicit dirPicker(QWidget *parent = nullptr); + explicit DirPicker(QWidget *parent = nullptr); /// Sets parameters of the image picker. void configure(const QString &settingsKey, const QString &title); From 3d57201de04031320b9309339bcbd06d7dd7d7ef Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 10 Jan 2025 20:31:17 +0300 Subject: [PATCH 5/5] Lupdate --- qrtranslations/fr/qrutils_fr.ts | 26 +++++++++++++------------- qrtranslations/ru/qrutils_ru.ts | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/qrtranslations/fr/qrutils_fr.ts b/qrtranslations/fr/qrutils_fr.ts index 049e18fe93..0ac115c262 100644 --- a/qrtranslations/fr/qrutils_fr.ts +++ b/qrtranslations/fr/qrutils_fr.ts @@ -447,6 +447,19 @@ + + qReal::ui::DirPicker + + + Browse... + + + + + Select directory + + + qReal::ui::ImagePicker @@ -507,19 +520,6 @@ - - qReal::ui::dirPicker - - - Browse... - - - - - Select directory - - - utils::MetamodelGeneratorSupport diff --git a/qrtranslations/ru/qrutils_ru.ts b/qrtranslations/ru/qrutils_ru.ts index f4ce671af8..d565092af3 100644 --- a/qrtranslations/ru/qrutils_ru.ts +++ b/qrtranslations/ru/qrutils_ru.ts @@ -559,6 +559,19 @@ Очистить консоль + + qReal::ui::DirPicker + + + Browse... + Обзор... + + + + Select directory + Выберите директорию + + qReal::ui::ImagePicker @@ -619,19 +632,6 @@ <строка>:<столбец> - - qReal::ui::dirPicker - - - Browse... - Обзор... - - - - Select directory - Выберите директорию - - utils::MetamodelGeneratorSupport