Commit 47660a8f authored by Tobias Hunger's avatar Tobias Hunger

NewDialog: Keep information on whether the dialog is open or not

Keep that information in the NewDialog instead of ICore.

Change-Id: I3e351251be6c4927b80a22db175ed79cb1f24621
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent c0952e22
......@@ -48,7 +48,6 @@
Q_DECLARE_METATYPE(Core::IWizardFactory*)
namespace {
const int ICON_SIZE = 22;
......@@ -188,6 +187,7 @@ Q_DECLARE_METATYPE(WizardFactoryContainer)
using namespace Core;
using namespace Core::Internal;
bool NewDialog::m_isRunning = false;
QString NewDialog::m_lastCategory = QString();
NewDialog::NewDialog(QWidget *parent) :
......@@ -195,6 +195,10 @@ NewDialog::NewDialog(QWidget *parent) :
m_ui(new Ui::NewDialog),
m_okButton(0)
{
QTC_CHECK(!m_isRunning);
m_isRunning = true;
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowFlags(windowFlags());
setAttribute(Qt::WA_DeleteOnClose);
......@@ -332,6 +336,11 @@ QString NewDialog::selectedPlatform() const
return m_ui->comboBox->itemData(index).toString();
}
bool NewDialog::isRunning()
{
return m_isRunning;
}
bool NewDialog::event(QEvent *event)
{
if (event->type() == QEvent::ShortcutOverride) {
......@@ -346,6 +355,9 @@ bool NewDialog::event(QEvent *event)
NewDialog::~NewDialog()
{
QTC_CHECK(m_isRunning);
m_isRunning = false;
delete m_ui;
}
......
......@@ -60,13 +60,15 @@ class NewDialog : public QDialog
public:
explicit NewDialog(QWidget *parent);
virtual ~NewDialog();
~NewDialog();
void setWizardFactories(QList<IWizardFactory*> factories, const QString &defaultLocation, const QVariantMap &extraVariables);
void showDialog();
QString selectedPlatform() const;
static bool isRunning();
protected:
bool event(QEvent *);
......@@ -84,6 +86,7 @@ private:
void saveState();
static QString m_lastCategory;
static bool m_isRunning;
Ui::NewDialog *m_ui;
QStandardItemModel *m_model;
......
......@@ -304,7 +304,6 @@ namespace Core {
// The Core Singleton
static ICore *m_instance = 0;
static MainWindow *m_mainwindow;
static bool m_isNewItemDialogRunning = false;
ICore *ICore::instance()
{
......@@ -313,7 +312,7 @@ ICore *ICore::instance()
bool ICore::isNewItemDialogRunning()
{
return m_isNewItemDialogRunning;
return NewDialog::isRunning();
}
ICore::ICore(MainWindow *mainwindow)
......@@ -338,14 +337,14 @@ void ICore::showNewItemDialog(const QString &title,
const QString &defaultLocation,
const QVariantMap &extraVariables)
{
QTC_ASSERT(!m_isNewItemDialogRunning, return);
QTC_ASSERT(!isNewItemDialogRunning(), return);
auto newDialog = new NewDialog(dialogParent());
connect(newDialog, &QObject::destroyed, &ICore::newItemDialogClosed);
connect(newDialog, &QObject::destroyed, &ICore::validateNewDialogIsRunning);
newDialog->setWizardFactories(factories, defaultLocation, extraVariables);
newDialog->setWindowTitle(title);
newDialog->showDialog();
newItemDialogOpened();
validateNewDialogIsRunning();
}
bool ICore::showOptionsDialog(const Id page, QWidget *parent)
......@@ -552,15 +551,12 @@ void ICore::saveSettings()
ICore::settings(QSettings::UserScope)->sync();
}
void ICore::newItemDialogOpened()
void ICore::validateNewDialogIsRunning()
{
m_isNewItemDialogRunning = true;
emit instance()->newItemDialogRunningChanged();
}
void ICore::newItemDialogClosed()
{
m_isNewItemDialogRunning = false;
static bool wasRunning = false;
if (wasRunning == isNewItemDialogRunning())
return;
wasRunning = isNewItemDialogRunning();
emit instance()->newItemDialogRunningChanged();
}
......
......@@ -138,6 +138,7 @@ signals:
void themeChanged();
private:
static void validateNewDialogIsRunning();
static void newItemDialogOpened();
static void newItemDialogClosed();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment