Gui: Extend DlgCheckableMessageBox to use specific preference path and parameter

This commit is contained in:
Abdullah Tahiri
2021-03-20 15:54:47 +01:00
parent 13fef6ac79
commit eaf65569a8
2 changed files with 41 additions and 8 deletions

View File

@@ -38,7 +38,7 @@
#include <QPushButton>
#include <QtCore/QDebug>
#include "MainWindow.h"
#include "MainWindow.h"
#include <App/Application.h>
//#include <App/Parameter.h>
@@ -54,7 +54,7 @@ QByteArray toParamEntry(QString name)
void DlgCheckableMessageBox::showMessage(const QString& header, const QString& message, bool check, const QString& checkText)
{
bool checked = App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/CheckMessages"))->GetBool(toParamEntry(header));
bool checked = App::GetApplication().GetParameterGroupByPath(QByteArray("User parameter:BaseApp/CheckMessages"))->GetBool(toParamEntry(header));
if (!checked) {
DlgCheckableMessageBox *mb = new DlgCheckableMessageBox(Gui::getMainWindow());
@@ -69,7 +69,25 @@ void DlgCheckableMessageBox::showMessage(const QString& header, const QString& m
mb->show();
}
}
void DlgCheckableMessageBox::showMessage(const QString& header, const QString& message, const QString& prefPath, const QString& paramEntry,
bool entryDefault, bool check, const QString& checkText)
{
bool checked = App::GetApplication().GetParameterGroupByPath(prefPath.toLatin1())->GetBool(paramEntry.toLatin1(), entryDefault);
if(checked == entryDefault) {
auto mb = new Gui::Dialog::DlgCheckableMessageBox(Gui::getMainWindow());
mb->setWindowTitle(header);
mb->setIconPixmap(QMessageBox::standardIcon(QMessageBox::Warning));
mb->setText(message);
mb->setPrefPath(prefPath);
mb->setPrefEntry(paramEntry);
mb->setCheckBoxText(checkText);
mb->setChecked(check);
mb->setStandardButtons(QDialogButtonBox::Ok);
mb->setDefaultButton(QDialogButtonBox::Ok);
mb->show();
}
}
struct DlgCheckableMessageBoxPrivate {
DlgCheckableMessageBoxPrivate() : clickedButton(0) {}
@@ -80,7 +98,8 @@ struct DlgCheckableMessageBoxPrivate {
DlgCheckableMessageBox::DlgCheckableMessageBox(QWidget *parent) :
QDialog(parent),
m_d(new DlgCheckableMessageBoxPrivate)
m_d(new DlgCheckableMessageBoxPrivate),
prefPath(QLatin1String("User parameter:BaseApp/CheckMessages"))
{
setModal(true);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
@@ -99,10 +118,14 @@ DlgCheckableMessageBox::~DlgCheckableMessageBox()
void DlgCheckableMessageBox::setPrefEntry(const QString& entry)
{
paramEntry = toParamEntry(entry);
bool checked = App::GetApplication().GetParameterGroupByPath(QByteArray("User parameter:BaseApp/CheckMessages"))->GetBool(paramEntry);
bool checked = App::GetApplication().GetParameterGroupByPath(prefPath.toLatin1())->GetBool(paramEntry);
setChecked(checked);
}
void DlgCheckableMessageBox::setPrefPath(const QString& path)
{
prefPath = path;
}
void DlgCheckableMessageBox::slotClicked(QAbstractButton *b)
{
@@ -198,14 +221,14 @@ void DlgCheckableMessageBox::setDefaultButton(QDialogButtonBox::StandardButton s
void DlgCheckableMessageBox::accept()
{
if(!paramEntry.isEmpty())
App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/CheckMessages"))->SetBool(paramEntry,isChecked());
App::GetApplication().GetParameterGroupByPath(prefPath.toLatin1())->SetBool(paramEntry,isChecked());
QDialog::accept();
}
void DlgCheckableMessageBox::reject()
{
if(!paramEntry.isEmpty())
App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/CheckMessages"))->SetBool(paramEntry,isChecked());
App::GetApplication().GetParameterGroupByPath(prefPath.toLatin1())->SetBool(paramEntry,isChecked());
QDialog::reject();
}

View File

@@ -73,6 +73,8 @@ public:
void setPrefEntry(const QString& entry);
void setPrefPath(const QString& path);
virtual void accept();
virtual void reject();
@@ -99,8 +101,15 @@ public:
// Conversion convenience
static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton);
// convenient show method
static void showMessage(const QString& header, const QString& message, bool check=false, const QString& checkText = QString::fromLatin1("Don't show me again"));
/// convenient show method
/// It shows a dialog with header and message provided and a checkbox in check state with the message provided.
/// It uses a parameter in path "User parameter:BaseApp/CheckMessages" derived from the header test, defaulting to false,
/// to store the status of the checkbox, when the user exits the modal dialog.
static void showMessage(const QString& header, const QString& message, bool check = false, const QString& checkText = QString::fromLatin1("Don't show me again"));
/// Same as showMessage above, but it checks the specific preference path and parameter provided, defaulting to entryDefault value if the parameter is not present.
static void showMessage(const QString& header, const QString& message, const QString& prefPath, const QString& paramEntry, bool entryDefault = false,
bool check = false, const QString& checkText = QString::fromLatin1("Don't show me again"));
private Q_SLOTS:
void slotClicked(QAbstractButton *b);
@@ -108,6 +117,7 @@ private Q_SLOTS:
private:
DlgCheckableMessageBoxPrivate *m_d;
QByteArray paramEntry;
QString prefPath;
};
} // namespace Dialog