[Feature Request] [Core] [Preferences] [UI/UX] Buttons to reset default values of Pages/Groups (#10688)
* Gui: added buttons to restore the default values of the selected Tab or Group * reformatted texts for better translations * Morphed buttons from QPushButton to QToolButton * added code to resize items list and buttons on language change Signed-off-by: CalligaroV <vincenzo.calligaro@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6c8856cd78
commit
d8636dd058
@@ -6,95 +6,163 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>570</width>
|
||||
<height>454</height>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Preferences</string>
|
||||
</property>
|
||||
<property name="locale">
|
||||
<locale language="English" country="UnitedStates"/>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" alignment="Qt::AlignHCenter">
|
||||
<widget class="QToolButton" name="buttonResetAll">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>128</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reset All</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox_2">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Help</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="8" alignment="Qt::AlignRight">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="7">
|
||||
<widget class="QToolButton" name="buttonResetTab">
|
||||
<property name="text">
|
||||
<string>Reset Tab</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="9">
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>128</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>96</width>
|
||||
<height>96</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<property name="viewMode">
|
||||
<enum>QListView::IconMode</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="listBoxVL">
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QListWidget" name="listBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>128</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>96</width>
|
||||
<height>96</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<property name="viewMode">
|
||||
<enum>QListView::IconMode</enum>
|
||||
</property>
|
||||
<property name="itemAlignment">
|
||||
<set>Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QToolButton" name="buttonResetGroup">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="tabWidgetStack"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<tabstops>
|
||||
<tabstop>listBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
# include <QAbstractButton>
|
||||
# include <QApplication>
|
||||
# include <QDebug>
|
||||
# include <QLabel>
|
||||
# include <QMessageBox>
|
||||
# include <QScreen>
|
||||
# include <QScrollArea>
|
||||
@@ -73,16 +74,29 @@ DlgPreferencesImp::DlgPreferencesImp(QWidget* parent, Qt::WindowFlags fl)
|
||||
invalidParameter(false), canEmbedScrollArea(true), restartRequired(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setupConnections();
|
||||
|
||||
QFontMetrics fm(font());
|
||||
int length = QtTools::horizontalAdvance(fm, longestGroupName());
|
||||
ui->listBox->setFixedWidth(Base::clamp<int>(length + 20, 108, 120));
|
||||
ui->listBox->setGridSize(QSize(108, 75));
|
||||
ui->listBox->setGridSize(QSize(Base::clamp<int>(length + 20, 108, 120), 75));
|
||||
|
||||
ui->buttonResetGroup->setFixedWidth(Base::clamp<int>(length + 20, 108, 120));
|
||||
ui->buttonResetGroup->setLayout(new QVBoxLayout(ui->buttonResetGroup));
|
||||
auto ResetGroup = new QLabel(ui->buttonResetGroup);
|
||||
ResetGroup->setAlignment(Qt::AlignCenter);
|
||||
ResetGroup->setWordWrap(true);
|
||||
ui->buttonResetGroup->layout()->setMargin(0);
|
||||
ui->buttonResetGroup->layout()->addWidget(ResetGroup);
|
||||
|
||||
ui->buttonResetAll->setFixedWidth(Base::clamp<int>(length + 20, 108, 120));
|
||||
|
||||
// remove unused help button
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::clicked,
|
||||
this, &DlgPreferencesImp::onButtonBoxClicked);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::helpRequested,
|
||||
connect(ui->buttonBox_2, &QDialogButtonBox::helpRequested,
|
||||
getMainWindow(), &MainWindow::whatsThis);
|
||||
connect(ui->listBox, &QListWidget::currentItemChanged,
|
||||
this, &DlgPreferencesImp::changeGroup);
|
||||
@@ -105,6 +119,17 @@ DlgPreferencesImp::~DlgPreferencesImp()
|
||||
}
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::setupConnections()
|
||||
{
|
||||
connect(ui->buttonResetTab, &QToolButton::clicked,
|
||||
this, &DlgPreferencesImp::onButtonResetTabClicked);
|
||||
connect(ui->buttonResetGroup, &QToolButton::clicked,
|
||||
this, &DlgPreferencesImp::onButtonResetGroupClicked);
|
||||
connect(ui->buttonResetAll, &QToolButton::clicked,
|
||||
this, &DlgPreferencesImp::restoreDefaults);
|
||||
}
|
||||
|
||||
|
||||
void DlgPreferencesImp::setupPages()
|
||||
{
|
||||
// make sure that pages are ready to create
|
||||
@@ -204,11 +229,37 @@ void DlgPreferencesImp::createPageInGroup(QTabWidget *tabWidget, const std::stri
|
||||
}
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::relabelResetButtons()
|
||||
{
|
||||
int groupIndex = ui->listBox->currentRow();
|
||||
QFontMetrics fm(font());
|
||||
QString group = fm.elidedText(ui->listBox->item(groupIndex)->text(), Qt::ElideRight, ui->buttonResetGroup->width()-4);
|
||||
|
||||
QTabWidget* tabWidget = static_cast<QTabWidget*>(ui->tabWidgetStack->currentWidget());
|
||||
int tabIndex = tabWidget->currentIndex();
|
||||
|
||||
static_cast<QLabel*>(ui->buttonResetGroup->layout()->itemAt(0)->widget())->setText(tr("Reset Group %1").arg(group));
|
||||
ui->buttonResetTab->setText(tr("Reset Tab %1").arg(tabWidget->tabText(tabIndex)));
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::changeTab(int current)
|
||||
{
|
||||
Q_UNUSED(current);
|
||||
|
||||
relabelResetButtons();
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::changeGroup(QListWidgetItem *current, QListWidgetItem *previous)
|
||||
{
|
||||
if (!current)
|
||||
current = previous;
|
||||
ui->tabWidgetStack->setCurrentIndex(ui->listBox->row(current));
|
||||
|
||||
auto tabWidget = static_cast<QTabWidget*>(ui->tabWidgetStack->currentWidget());
|
||||
connect(tabWidget, &QTabWidget::currentChanged,
|
||||
this, &DlgPreferencesImp::changeTab);
|
||||
|
||||
relabelResetButtons();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,8 +403,6 @@ void DlgPreferencesImp::onButtonBoxClicked(QAbstractButton* btn)
|
||||
{
|
||||
if (ui->buttonBox->standardButton(btn) == QDialogButtonBox::Apply)
|
||||
applyChanges();
|
||||
else if (ui->buttonBox->standardButton(btn) == QDialogButtonBox::Reset)
|
||||
restoreDefaults();
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::restoreDefaults()
|
||||
@@ -578,6 +627,14 @@ void DlgPreferencesImp::changeEvent(QEvent *e)
|
||||
QByteArray group = item->data(GroupNameRole).toByteArray();
|
||||
item->setText(QObject::tr(group.constData()));
|
||||
}
|
||||
|
||||
//resizes items list and buttons
|
||||
QFontMetrics fm(font());
|
||||
int length = QtTools::horizontalAdvance(fm, longestGroupName());
|
||||
ui->listBox->setFixedWidth(Base::clamp<int>(length + 20, 108, 120));
|
||||
ui->listBox->setGridSize(QSize(Base::clamp<int>(length + 20, 108, 120), 75));
|
||||
ui->buttonResetGroup->setFixedWidth(Base::clamp<int>(length + 20, 108, 120));
|
||||
ui->buttonResetAll->setFixedWidth(Base::clamp<int>(length + 20, 108, 120));
|
||||
} else {
|
||||
QWidget::changeEvent(e);
|
||||
}
|
||||
@@ -596,4 +653,86 @@ void DlgPreferencesImp::reload()
|
||||
applyChanges();
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::restorePageDefaults(PreferencePage** page)
|
||||
{
|
||||
QList<QObject*> prefs = (*page)->findChildren<QObject*>();
|
||||
|
||||
for (const auto & pref : prefs) {
|
||||
if (!pref->property("prefPath").isNull() && !pref->property("prefEntry").isNull()) {
|
||||
std::string path = pref->property("prefPath").toString().toStdString();
|
||||
std::string entry = pref->property("prefEntry").toString().toStdString();
|
||||
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(std::string("User parameter:BaseApp/Preferences/" + path).c_str());
|
||||
|
||||
for (const auto & pn : hGrp->GetParameterNames(entry.c_str())){
|
||||
hGrp->RemoveAttribute(pn.first, pn.second.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string pageName = (*page)->property("PageName").toString().toStdString();
|
||||
(*page) = WidgetFactory().createPreferencePage(pageName.c_str());
|
||||
(*page)->loadSettings();
|
||||
(*page)->setProperty("PageName", QVariant(QString::fromStdString(pageName)));
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::onButtonResetTabClicked()
|
||||
{
|
||||
auto tabWidget = static_cast<QTabWidget*>(ui->tabWidgetStack->widget(ui->listBox->currentRow()));
|
||||
|
||||
QMessageBox box(this);
|
||||
box.setIcon(QMessageBox::Question);
|
||||
box.setWindowTitle(tr("Reset Tab Parameters"));
|
||||
box.setText(tr("All the parameters for the Tab %1 will be deleted.").arg(tabWidget->tabText(tabWidget->currentIndex())));
|
||||
box.setInformativeText(tr("Do you want to continue?"));
|
||||
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
box.setDefaultButton(QMessageBox::No);
|
||||
|
||||
if (box.exec() == QMessageBox::Yes) {
|
||||
int pageIndex = tabWidget->currentIndex();
|
||||
QString pageText = tabWidget->tabText(pageIndex);
|
||||
PreferencePage* page = qobject_cast<PreferencePage*>(tabWidget->widget(pageIndex));
|
||||
|
||||
restorePageDefaults(&page);
|
||||
page->setProperty("GroupName", tabWidget->property("GroupName"));
|
||||
|
||||
tabWidget->removeTab(pageIndex);
|
||||
tabWidget->insertTab(pageIndex, page, pageText);
|
||||
tabWidget->setCurrentIndex(pageIndex);
|
||||
|
||||
applyChanges();
|
||||
}
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::onButtonResetGroupClicked()
|
||||
{
|
||||
QMessageBox box(this);
|
||||
box.setIcon(QMessageBox::Question);
|
||||
box.setWindowTitle(tr("Reset Group Parameters"));
|
||||
box.setText(tr("All the parameters for the Group %1 will be deleted.").arg(ui->listBox->currentItem()->text()));
|
||||
box.setInformativeText(tr("Do you want to continue?"));
|
||||
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
box.setDefaultButton(QMessageBox::No);
|
||||
|
||||
if (box.exec() == QMessageBox::Yes) {
|
||||
auto tabWidget = static_cast<QTabWidget*>(ui->tabWidgetStack->widget(ui->listBox->currentRow()));
|
||||
int pageIndex = tabWidget->currentIndex();
|
||||
|
||||
for (int i = 0; i < tabWidget->count(); i++) {
|
||||
QString pageText = tabWidget->tabText(i);
|
||||
PreferencePage* page = qobject_cast<PreferencePage*>(tabWidget->widget(i));
|
||||
|
||||
restorePageDefaults(&page);
|
||||
page->setProperty("GroupName", tabWidget->property("GroupName"));
|
||||
|
||||
tabWidget->removeTab(i);
|
||||
tabWidget->insertTab(i, page, pageText);
|
||||
}
|
||||
|
||||
tabWidget->setCurrentIndex(pageIndex);
|
||||
|
||||
applyChanges();
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_DlgPreferencesImp.cpp"
|
||||
|
||||
@@ -130,12 +130,17 @@ public:
|
||||
void activeGroupPage(QString& group, int& index) const;
|
||||
|
||||
protected:
|
||||
void setupConnections();
|
||||
void changeEvent(QEvent *e) override;
|
||||
void showEvent(QShowEvent*) override;
|
||||
void resizeEvent(QResizeEvent*) override;
|
||||
void onButtonResetTabClicked();
|
||||
void onButtonResetGroupClicked();
|
||||
void relabelResetButtons();
|
||||
|
||||
|
||||
protected Q_SLOTS:
|
||||
void changeTab(int current);
|
||||
void changeGroup(QListWidgetItem *current, QListWidgetItem *previous);
|
||||
void onButtonBoxClicked(QAbstractButton*);
|
||||
void resizeWindow(int w, int h);
|
||||
@@ -149,6 +154,7 @@ private:
|
||||
void createPageInGroup(QTabWidget* tabWidget, const std::string& pageName);
|
||||
void applyChanges();
|
||||
void restoreDefaults();
|
||||
void restorePageDefaults(PreferencePage**);
|
||||
QString longestGroupName() const;
|
||||
void restartIfRequired();
|
||||
//@}
|
||||
|
||||
Reference in New Issue
Block a user