Commit 8e18fd08 authored by Tobias Hunger's avatar Tobias Hunger

Utils: Make wizard pages derive from Utils::WizardPage

Utils::WizardPage has a bit of helper code to the Utils::Wizard to
query registered fields later on. Without this code it will print
warnings whenever something tries to read a field that does not
exist.

Make the wizard pages defined in Utils export some fields.

Change-Id: I907be327a8b1b8691f90773470630582503d294a
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent be9e4d71
......@@ -59,7 +59,7 @@ FileWizardPagePrivate::FileWizardPagePrivate() :
}
FileWizardPage::FileWizardPage(QWidget *parent) :
QWizardPage(parent),
WizardPage(parent),
d(new FileWizardPagePrivate)
{
d->m_ui.setupUi(this);
......@@ -70,6 +70,9 @@ FileWizardPage::FileWizardPage(QWidget *parent) :
connect(d->m_ui.nameLineEdit, SIGNAL(validReturnPressed()), this, SLOT(slotActivated()));
setProperty(SHORT_TITLE_PROPERTY, tr("Location"));
registerFieldWithName(QLatin1String("Path"), d->m_ui.pathChooser, "path", SIGNAL(pathChanged(QString)));
registerFieldWithName(QLatin1String("FileName"), d->m_ui.nameLineEdit);
}
FileWizardPage::~FileWizardPage()
......
......@@ -32,13 +32,13 @@
#include "utils_global.h"
#include <QWizardPage>
#include "wizardpage.h"
namespace Utils {
class FileWizardPagePrivate;
class QTCREATOR_UTILS_EXPORT FileWizardPage : public QWizardPage
class QTCREATOR_UTILS_EXPORT FileWizardPage : public WizardPage
{
Q_OBJECT
Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
......
......@@ -81,7 +81,7 @@ ProjectIntroPagePrivate:: ProjectIntroPagePrivate() :
}
ProjectIntroPage::ProjectIntroPage(QWidget *parent) :
QWizardPage(parent),
WizardPage(parent),
d(new ProjectIntroPagePrivate)
{
d->m_ui.setupUi(this);
......@@ -100,6 +100,8 @@ ProjectIntroPage::ProjectIntroPage(QWidget *parent) :
connect(d->m_ui.projectComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChanged()));
setProperty(SHORT_TITLE_PROPERTY, tr("Location"));
registerFieldWithName(QLatin1String("Path"), d->m_ui.pathChooser, "path", SIGNAL(pathChanged(QString)));
registerFieldWithName(QLatin1String("ProjectName"), d->m_ui.nameLineEdit);
}
void ProjectIntroPage::insertControl(int row, QWidget *label, QWidget *control)
......
......@@ -31,14 +31,13 @@
#define PROJECTINTROPAGE_H
#include "utils_global.h"
#include <QWizardPage>
#include "wizardpage.h"
namespace Utils {
struct ProjectIntroPagePrivate;
class QTCREATOR_UTILS_EXPORT ProjectIntroPage : public QWizardPage
class QTCREATOR_UTILS_EXPORT ProjectIntroPage : public WizardPage
{
Q_OBJECT
Q_PROPERTY(QString description READ description WRITE setPath DESIGNABLE true)
......
......@@ -25,6 +25,7 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/pathchooser.cpp \
$$PWD/pathlisteditor.cpp \
$$PWD/wizard.cpp \
$$PWD/wizardpage.cpp \
$$PWD/filewizardpage.cpp \
$$PWD/filesystemwatcher.cpp \
$$PWD/projectintropage.cpp \
......@@ -110,6 +111,7 @@ HEADERS += \
$$PWD/pathchooser.h \
$$PWD/pathlisteditor.h \
$$PWD/wizard.h \
$$PWD/wizardpage.h \
$$PWD/filewizardpage.h \
$$PWD/filesystemwatcher.h \
$$PWD/projectintropage.h \
......
......@@ -190,6 +190,8 @@ QtcLibrary {
"winutils.h",
"wizard.cpp",
"wizard.h",
"wizardpage.cpp",
"wizardpage.h",
"images/arrow.png",
"images/crumblepath-segment-end.png",
"images/crumblepath-segment-hover-end.png",
......
......@@ -28,13 +28,16 @@
****************************************************************************/
#include "wizard.h"
#include "hostosinfo.h"
#include "qtcassert.h"
#include "wizardpage.h"
#include <QHash>
#include <QIcon>
#include <QKeyEvent>
#include <QLabel>
#include <QMap>
#include <QStyle>
#include <QVBoxLayout>
#include <QVariant>
......@@ -310,6 +313,7 @@ public:
}
bool m_automaticProgressCreation;
WizardProgress *m_wizardProgress;
QSet<QString> m_fieldNames;
};
Wizard::Wizard(QWidget *parent, Qt::WindowFlags flags) :
......@@ -377,6 +381,17 @@ bool Wizard::validateCurrentPage()
return QWizard::validateCurrentPage();
}
bool Wizard::hasField(const QString &name) const
{
return d_ptr->m_fieldNames.contains(name);
}
void Wizard::registerFieldName(const QString &name)
{
QTC_ASSERT(!hasField(name), return);
d_ptr->m_fieldNames.insert(name);
}
bool Wizard::event(QEvent *event)
{
if (event->type() == QEvent::ShortcutOverride) {
......@@ -400,10 +415,14 @@ void Wizard::_q_pageAdded(int pageId)
{
Q_D(Wizard);
QWizardPage *p = page(pageId);
WizardPage *wp = qobject_cast<WizardPage *>(p);
if (wp)
wp->pageWasAdded();
if (!d->m_automaticProgressCreation)
return;
QWizardPage *p = page(pageId);
QVariant property = p->property(SHORT_TITLE_PROPERTY);
const QString title = property.isNull() ? p->title() : property.toString();
WizardProgressItem *item = d->m_wizardProgress->addItem(title);
......
......@@ -68,6 +68,10 @@ public:
return 0;
}
// will return true for all fields registered via Utils::WizardPage::registerFieldWithName(...)
bool hasField(const QString &name) const;
void registerFieldName(const QString &name);
signals:
void nextClicked(); /* workaround for QWizard behavior where page->initialize is
* called before currentIdChanged */
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "wizardpage.h"
#include "wizard.h"
/*! \class Utils::WizardPage
\brief QWizardPage with a couple of improvements
Adds a way to register fields so that a Utils::Wizard can check
whether those fields are actually defined and a new method
that is called once the page was added to the wizard.
*/
namespace Utils {
WizardPage::WizardPage(QWidget *parent) : QWizardPage(parent)
{ }
void WizardPage::pageWasAdded()
{
Wizard *wiz = qobject_cast<Wizard *>(wizard());
if (!wiz)
return;
for (auto i = m_toRegister.constBegin(); i != m_toRegister.constEnd(); ++i)
wiz->registerFieldName(*i);
m_toRegister.clear();
}
void WizardPage::registerFieldWithName(const QString &name, QWidget *widget,
const char *property, const char *changedSignal)
{
Wizard *wiz = qobject_cast<Wizard *>(wizard());
if (wiz)
wiz->registerFieldName(name);
else
m_toRegister.insert(name);
registerField(name, widget, property, changedSignal);
}
} // namespace Utils
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef WIZARDPAGE_H
#define WIZARDPAGE_H
#include "utils_global.h"
#include <QSet>
#include <QString>
#include <QWizardPage>
namespace Utils {
class Wizard;
class QTCREATOR_UTILS_EXPORT WizardPage : public QWizardPage
{
Q_OBJECT
public:
explicit WizardPage(QWidget *parent = 0);
virtual void pageWasAdded(); // called when this page was added to a Utils::Wizard
void registerFieldWithName(const QString &name, QWidget *widget,
const char *property = 0, const char *changedSignal = 0);
private:
QSet<QString> m_toRegister;
};
} // namespace Utils
#endif // WIZARDPAGE_H
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