Gui: Switch back to a single Reset button
The reset button opens a menu that offers all options to reset the user settings.
This commit is contained in:
@@ -28,14 +28,17 @@
|
||||
# include <cstring>
|
||||
# include <QAbstractButton>
|
||||
# include <QApplication>
|
||||
# include <QCursor>
|
||||
# include <QDebug>
|
||||
# include <QLabel>
|
||||
# include <QMenu>
|
||||
# include <QMessageBox>
|
||||
# include <QScreen>
|
||||
# include <QScrollArea>
|
||||
# include <QScrollBar>
|
||||
# include <QTimer>
|
||||
# include <QToolTip>
|
||||
# include <QProcess>
|
||||
# include <QPushButton>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
@@ -74,32 +77,16 @@ 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(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()->setContentsMargins(0, 0, 0, 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_2, &QDialogButtonBox::helpRequested,
|
||||
getMainWindow(), &MainWindow::whatsThis);
|
||||
connect(ui->listBox, &QListWidget::currentItemChanged,
|
||||
this, &DlgPreferencesImp::changeGroup);
|
||||
setupConnections();
|
||||
|
||||
setupPages();
|
||||
|
||||
@@ -121,15 +108,19 @@ 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);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::clicked,
|
||||
this, &DlgPreferencesImp::onButtonBoxClicked);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::helpRequested,
|
||||
getMainWindow(), &MainWindow::whatsThis);
|
||||
connect(ui->listBox, &QListWidget::currentItemChanged,
|
||||
this, &DlgPreferencesImp::changeGroup);
|
||||
if (auto reset = ui->buttonBox->button(QDialogButtonBox::Reset)) {
|
||||
QString text = reset->text();
|
||||
text.append(QLatin1String("..."));
|
||||
reset->setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DlgPreferencesImp::setupPages()
|
||||
{
|
||||
// make sure that pages are ready to create
|
||||
@@ -229,37 +220,11 @@ 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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -401,8 +366,46 @@ void DlgPreferencesImp::reject()
|
||||
|
||||
void DlgPreferencesImp::onButtonBoxClicked(QAbstractButton* btn)
|
||||
{
|
||||
if (ui->buttonBox->standardButton(btn) == QDialogButtonBox::Apply)
|
||||
if (ui->buttonBox->standardButton(btn) == QDialogButtonBox::Apply) {
|
||||
applyChanges();
|
||||
}
|
||||
else if (ui->buttonBox->standardButton(btn) == QDialogButtonBox::Reset) {
|
||||
showResetOptions();
|
||||
}
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::showResetOptions()
|
||||
{
|
||||
// clang-format off
|
||||
QMenu menu(this);
|
||||
|
||||
// Reset per tab
|
||||
auto tabWidget = static_cast<QTabWidget*>(ui->tabWidgetStack->currentWidget());
|
||||
int tabIndex = tabWidget->currentIndex();
|
||||
QString tabText = tabWidget->tabText(tabIndex);
|
||||
QAction* tabAction = menu.addAction(tr("Reset tab '%1'...").arg(tabText), this,
|
||||
&DlgPreferencesImp::onButtonResetTabClicked);
|
||||
tabAction->setToolTip(tr("Resets the user settings for the tab '%1'").arg(tabText));
|
||||
|
||||
// Reset per group
|
||||
int groupIndex = ui->listBox->currentRow();
|
||||
QString group = ui->listBox->item(groupIndex)->text();
|
||||
QAction* grpAction = menu.addAction(tr("Reset group '%1'...").arg(group), this,
|
||||
&DlgPreferencesImp::onButtonResetGroupClicked);
|
||||
grpAction->setToolTip(tr("Resets the user settings for the group '%1'").arg(group));
|
||||
|
||||
// Reset all
|
||||
QAction* allAction = menu.addAction(tr("Reset all..."), this,
|
||||
&DlgPreferencesImp::restoreDefaults);
|
||||
allAction->setToolTip(tr("Resets the user settings entirely"));
|
||||
|
||||
connect(&menu, &QMenu::hovered, [&menu](QAction* hover){
|
||||
QPoint pos = menu.pos();
|
||||
pos.rx() += menu.width() + 10;
|
||||
QToolTip::showText(pos, hover->toolTip());
|
||||
});
|
||||
menu.exec(QCursor::pos());
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::restoreDefaults()
|
||||
@@ -430,6 +433,88 @@ void DlgPreferencesImp::restoreDefaults()
|
||||
}
|
||||
}
|
||||
|
||||
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 Settings"));
|
||||
box.setText(tr("All the settings 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 Settings"));
|
||||
box.setText(tr("All the settings 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();
|
||||
}
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the dialog is currently showing and the static variable _pages changed, this function
|
||||
* will rescan that list of pages and add any that are new to the current dialog. It will not
|
||||
@@ -633,8 +718,6 @@ void DlgPreferencesImp::changeEvent(QEvent *e)
|
||||
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);
|
||||
}
|
||||
@@ -653,86 +736,4 @@ 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"
|
||||
|
||||
Reference in New Issue
Block a user