看起来你必须自己旋转。这是我们解决方案的重要部分。如果有人如此倾向于,这可能会被概括。由于我们的业务规则可能会破坏其他应用程序,我也能够假设某些事情。切换是一个可以在编译时定义的宏:YOUR_APP_APPLY_PREFERENCES_IMMEDIATELY
preferences_dialog.h
class PreferencesDialog : public QDialog {
Q_OBJECT
public:
explicit PreferencesDialog(... various arguments ...,
QWidget *parent);
private slots:
void ModifyMapLanguages();
private:
void ApplyLanguageChanges(const QList<Language> &languages,
const QHash<LanguageKey, LanguageKey> &renames);
void Initialize();
#ifndef YOUR_APP_APPLY_PREFERENCES_IMMEDIATELY
public slots:
void accept();
private slots:
void ApplyDialog();
private:
QList<Language> pending_languages_;
QHash<LanguageKey, LanguageKey> pending_language_renames_;
#endif
};
preferences_dialog.cpp
#include "forms/preferences_dialog.h"
#include "ui_preferences_dialog.h"
PreferencesDialog::PreferencesDialog(... various arguments ...,
QWidget *parent) :
QDialog(parent),
... various initializers ... {
ui->setupUi(this);
Initialize();
}
void PreferencesDialog::ApplyLanguageChanges(
const QList<Language> &languages,
const QHash<LanguageKey, LanguageKey> &renames) {
// Do the actual changes here, whether immediate or postponed
}
void PreferencesDialog::Initialize() {
// Disable the minimize and maximize buttons.
Qt::WindowFlags flags = this->windowFlags();
flags |= Qt::CustomizeWindowHint;
flags &= ~Qt::WindowMinMaxButtonsHint;
setWindowFlags(flags);
// buttons is the QDialogButtonBox with Ok, Cancel, and Apply buttons
#ifdef YOUR_APP_APPLY_PREFERENCES_IMMEDIATELY
ui->buttons->setVisible(false);
#else
QPushButton *apply_button = ui->buttons->button(QDialogButtonBox::Apply);
connect(apply_button, SIGNAL(clicked()), SLOT(ApplyDialog()));
#endif
}
void PreferencesDialog::ModifyMapLanguages() {
// Get the changes; in my case, they are coming from a dialog wizard
LanguageSetupWizard wizard(map_->languages(), true, this);
wizard.setWindowModality(Qt::WindowModal);
if (QDialog::Accepted == wizard.exec()) {
#ifdef YOUR_APP_APPLY_PREFERENCES_IMMEDIATELY
ApplyLanguageChanges(wizard.languages(), wizard.language_renames());
#else
pending_languages_ = wizard.languages();
pending_language_renames_ = wizard.language_renames();
#endif
}
}
#ifndef YOUR_APP_APPLY_PREFERENCES_IMMEDIATELY
void PreferencesDialog::ApplyDialog() {
if (!pending_languages_.isEmpty()) {
ApplyLanguageChanges(pending_languages_, pending_language_renames_);
}
}
void PreferencesDialog::accept() {
ApplyDialog();
QDialog::accept();
}
#endif