2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "newdialog.h"
|
|
|
|
|
#include "ui_newdialog.h"
|
|
|
|
|
#include "basefilewizard.h"
|
|
|
|
|
|
2010-04-16 14:12:55 +02:00
|
|
|
#include <utils/stylehelper.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2012-01-18 13:50:14 +01:00
|
|
|
#include <coreplugin/featureprovider.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-04-16 14:12:55 +02:00
|
|
|
#include <QtGui/QAbstractProxyModel>
|
2012-02-08 17:25:35 +01:00
|
|
|
#include <QtGui/QSortFilterProxyModel>
|
2010-04-20 19:07:36 +02:00
|
|
|
#include <QtGui/QItemSelectionModel>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QHeaderView>
|
|
|
|
|
#include <QtGui/QPushButton>
|
2010-04-13 19:21:14 +02:00
|
|
|
#include <QtGui/QStandardItem>
|
2010-04-16 14:12:55 +02:00
|
|
|
#include <QtGui/QItemDelegate>
|
|
|
|
|
#include <QtGui/QPainter>
|
2009-11-27 10:33:24 +01:00
|
|
|
#include <QtCore/QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::IWizard*)
|
|
|
|
|
|
2010-04-16 14:12:55 +02:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2010-05-14 11:03:30 +02:00
|
|
|
const int ICON_SIZE = 22;
|
|
|
|
|
|
2012-02-08 17:25:35 +01:00
|
|
|
struct WizardContainer
|
|
|
|
|
{
|
|
|
|
|
WizardContainer() : wizard(0), wizardOption(0) {}
|
|
|
|
|
WizardContainer(Core::IWizard *w, int i): wizard(w), wizardOption(i) {}
|
|
|
|
|
Core::IWizard *wizard;
|
|
|
|
|
int wizardOption;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline Core::IWizard *wizardOfItem(const QStandardItem *item = 0)
|
|
|
|
|
{
|
|
|
|
|
if (!item)
|
|
|
|
|
return 0;
|
|
|
|
|
return item->data(Qt::UserRole).value<WizardContainer>().wizard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PlatformFilterProxyModel : public QSortFilterProxyModel
|
|
|
|
|
{
|
|
|
|
|
// Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
PlatformFilterProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent) {}
|
|
|
|
|
|
|
|
|
|
void setPlatform(const QString& platform)
|
|
|
|
|
{
|
|
|
|
|
m_platform = platform;
|
|
|
|
|
invalidateFilter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
|
|
|
{
|
|
|
|
|
if (!sourceParent.isValid())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
|
|
|
|
|
Core::IWizard *wizard = wizardOfItem(qobject_cast<QStandardItemModel*>(sourceModel())->itemFromIndex(sourceIndex));
|
|
|
|
|
if (wizard)
|
|
|
|
|
return wizard->isAvailable(m_platform);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
QString m_platform;
|
|
|
|
|
};
|
|
|
|
|
|
2010-04-16 14:12:55 +02:00
|
|
|
class TwoLevelProxyModel : public QAbstractProxyModel
|
|
|
|
|
{
|
|
|
|
|
// Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
TwoLevelProxyModel(QObject *parent = 0): QAbstractProxyModel(parent) {}
|
|
|
|
|
|
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
QModelIndex ourModelIndex = sourceModel()->index(row, column, mapToSource(parent));
|
|
|
|
|
return createIndex(row, column, ourModelIndex.internalPointer());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex parent(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
return mapFromSource(mapToSource(index).parent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (index.isValid() && index.parent().isValid() && !index.parent().parent().isValid())
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return sourceModel()->rowCount(mapToSource(index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int columnCount(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
return sourceModel()->columnCount(mapToSource(index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex mapFromSource (const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
return createIndex(index.row(), index.column(), index.internalPointer());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex mapToSource (const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
return static_cast<TwoLevelProxyModel*>(sourceModel())->createIndex(index.row(), index.column(), index.internalPointer());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-05-03 20:14:32 +02:00
|
|
|
#define ROW_HEIGHT 24
|
2010-04-16 14:12:55 +02:00
|
|
|
|
|
|
|
|
class FancyTopLevelDelegate : public QItemDelegate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FancyTopLevelDelegate(QObject *parent = 0)
|
|
|
|
|
: QItemDelegate(parent) {}
|
|
|
|
|
|
|
|
|
|
void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
|
|
|
|
|
{
|
2010-04-20 19:07:36 +02:00
|
|
|
QStyleOptionViewItem newoption = option;
|
|
|
|
|
if (!(option.state & QStyle::State_Enabled)) {
|
2010-04-16 14:12:55 +02:00
|
|
|
QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
|
|
|
|
|
gradient.setColorAt(0, option.palette.window().color().lighter(106));
|
|
|
|
|
gradient.setColorAt(1, option.palette.window().color().darker(106));
|
|
|
|
|
painter->fillRect(rect, gradient);
|
|
|
|
|
painter->setPen(option.palette.window().color().darker(130));
|
|
|
|
|
if (rect.top())
|
|
|
|
|
painter->drawLine(rect.topRight(), rect.topLeft());
|
|
|
|
|
painter->drawLine(rect.bottomRight(), rect.bottomLeft());
|
|
|
|
|
|
2010-04-20 19:07:36 +02:00
|
|
|
// Fake enabled state
|
|
|
|
|
newoption.state |= newoption.state | QStyle::State_Enabled;
|
|
|
|
|
}
|
2010-04-16 14:12:55 +02:00
|
|
|
|
2010-04-20 19:07:36 +02:00
|
|
|
QItemDelegate::drawDisplay(painter, newoption, rect, text);
|
2010-04-16 14:12:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QSize size = QItemDelegate::sizeHint(option, index);
|
|
|
|
|
|
2010-05-03 20:14:32 +02:00
|
|
|
|
|
|
|
|
size = size.expandedTo(QSize(0, ROW_HEIGHT));
|
2010-04-16 14:12:55 +02:00
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-08 17:25:35 +01:00
|
|
|
Q_DECLARE_METATYPE(WizardContainer)
|
2010-04-16 14:12:55 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
|
|
|
|
NewDialog::NewDialog(QWidget *parent) :
|
|
|
|
|
QDialog(parent),
|
|
|
|
|
m_ui(new Core::Internal::Ui::NewDialog),
|
2010-05-19 18:30:45 +02:00
|
|
|
m_okButton(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-04-13 19:21:14 +02:00
|
|
|
typedef QMap<QString, QStandardItem *> CategoryItemMap;
|
2011-04-15 11:43:09 +02:00
|
|
|
|
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
m_okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok);
|
|
|
|
|
m_okButton->setDefault(true);
|
2010-04-16 14:12:55 +02:00
|
|
|
m_okButton->setText(tr("&Choose..."));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-04-13 19:21:14 +02:00
|
|
|
m_model = new QStandardItemModel(this);
|
2012-02-08 17:25:35 +01:00
|
|
|
m_twoLevelProxyModel = new TwoLevelProxyModel(this);
|
|
|
|
|
m_twoLevelProxyModel->setSourceModel(m_model);
|
|
|
|
|
m_filterProxyModel = new PlatformFilterProxyModel(this);
|
|
|
|
|
m_filterProxyModel->setSourceModel(m_model);
|
|
|
|
|
|
|
|
|
|
m_ui->templateCategoryView->setModel(m_twoLevelProxyModel);
|
2010-04-16 14:12:55 +02:00
|
|
|
m_ui->templateCategoryView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
m_ui->templateCategoryView->setItemDelegate(new FancyTopLevelDelegate);
|
|
|
|
|
|
2010-05-14 11:03:30 +02:00
|
|
|
m_ui->templatesView->setIconSize(QSize(ICON_SIZE, ICON_SIZE));
|
2010-04-13 19:21:14 +02:00
|
|
|
|
2010-04-16 14:12:55 +02:00
|
|
|
connect(m_ui->templateCategoryView, SIGNAL(clicked(const QModelIndex&)),
|
|
|
|
|
this, SLOT(currentCategoryChanged(const QModelIndex&)));
|
|
|
|
|
connect(m_ui->templatesView, SIGNAL(clicked(const QModelIndex&)),
|
2010-04-13 19:21:14 +02:00
|
|
|
this, SLOT(currentItemChanged(const QModelIndex&)));
|
2010-04-20 19:07:36 +02:00
|
|
|
|
|
|
|
|
connect(m_ui->templateCategoryView->selectionModel(),
|
|
|
|
|
SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
|
|
|
|
|
this, SLOT(currentCategoryChanged(const QModelIndex&)));
|
|
|
|
|
connect(m_ui->templatesView,
|
|
|
|
|
SIGNAL(doubleClicked(const QModelIndex&)),
|
|
|
|
|
this, SLOT(okButtonClicked()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
connect(m_okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
|
|
|
|
|
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
2012-02-08 17:25:35 +01:00
|
|
|
|
|
|
|
|
connect(m_ui->comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setSelectedPlatform(QString)));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-27 10:33:24 +01:00
|
|
|
// Sort by category. id
|
|
|
|
|
bool wizardLessThan(const IWizard *w1, const IWizard *w2)
|
|
|
|
|
{
|
|
|
|
|
if (const int cc = w1->category().compare(w2->category()))
|
|
|
|
|
return cc < 0;
|
|
|
|
|
return w1->id().compare(w2->id()) < 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewDialog::setWizards(QList<IWizard*> wizards)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-04-13 19:21:14 +02:00
|
|
|
typedef QMap<QString, QStandardItem *> CategoryItemMap;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-27 10:33:24 +01:00
|
|
|
qStableSort(wizards.begin(), wizards.end(), wizardLessThan);
|
|
|
|
|
|
2012-02-08 17:25:35 +01:00
|
|
|
CategoryItemMap platformMap;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-04-13 19:21:14 +02:00
|
|
|
m_model->clear();
|
2012-02-08 17:25:35 +01:00
|
|
|
QStandardItem *parentItem = m_model->invisibleRootItem();
|
|
|
|
|
|
2010-04-16 14:12:55 +02:00
|
|
|
QStandardItem *projectKindItem = new QStandardItem(tr("Projects"));
|
|
|
|
|
projectKindItem->setData(IWizard::ProjectWizard, Qt::UserRole);
|
2010-04-20 19:07:36 +02:00
|
|
|
projectKindItem->setFlags(0); // disable item to prevent focus
|
2010-04-19 18:00:05 +02:00
|
|
|
QStandardItem *filesClassesKindItem = new QStandardItem(tr("Files and Classes"));
|
2010-04-16 14:12:55 +02:00
|
|
|
filesClassesKindItem->setData(IWizard::FileWizard, Qt::UserRole);
|
2010-04-20 19:07:36 +02:00
|
|
|
filesClassesKindItem->setFlags(0); // disable item to prevent focus
|
2012-02-08 17:25:35 +01:00
|
|
|
|
2010-04-16 14:12:55 +02:00
|
|
|
parentItem->appendRow(projectKindItem);
|
|
|
|
|
parentItem->appendRow(filesClassesKindItem);
|
|
|
|
|
|
2010-04-20 19:07:36 +02:00
|
|
|
if (m_dummyIcon.isNull()) {
|
2012-02-08 17:25:35 +01:00
|
|
|
m_dummyIcon = QIcon(QLatin1String(Core::Constants::ICON_NEWFILE));
|
2010-04-20 19:07:36 +02:00
|
|
|
}
|
2010-04-16 14:12:55 +02:00
|
|
|
|
2012-02-08 17:25:35 +01:00
|
|
|
QStringList availablePlatforms = IWizard::allAvailablePlatforms();
|
2010-04-16 14:12:55 +02:00
|
|
|
|
2012-02-08 17:25:35 +01:00
|
|
|
if (availablePlatforms.count() > 1) {
|
|
|
|
|
m_ui->comboBox->addItem(tr("All templates"), QString());
|
|
|
|
|
foreach (const QString &platform, availablePlatforms) {
|
2012-02-10 12:08:22 +01:00
|
|
|
const QString displayNameForPlatform = IWizard::displayNameForPlatform(platform);
|
|
|
|
|
m_ui->comboBox->addItem(tr("%1 templates").arg(displayNameForPlatform), platform);
|
2012-02-08 17:25:35 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (availablePlatforms.isEmpty()) {
|
|
|
|
|
m_ui->comboBox->addItem(tr("All templates"), QString());
|
|
|
|
|
} else {
|
|
|
|
|
const QString platform = availablePlatforms.first();
|
2012-02-10 12:08:22 +01:00
|
|
|
const QString displayNameForPlatform = IWizard::displayNameForPlatform(platform);
|
|
|
|
|
m_ui->comboBox->addItem(tr("%1 templates").arg(displayNameForPlatform), platform);
|
2012-02-08 17:25:35 +01:00
|
|
|
}
|
|
|
|
|
m_ui->comboBox->setDisabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (IWizard *wizard, wizards) {
|
|
|
|
|
if (wizard->isAvailable(selectedPlatform())) {
|
2010-04-16 14:12:55 +02:00
|
|
|
QStandardItem *kindItem;
|
|
|
|
|
switch (wizard->kind()) {
|
|
|
|
|
case IWizard::ProjectWizard:
|
|
|
|
|
kindItem = projectKindItem;
|
|
|
|
|
break;
|
|
|
|
|
case IWizard::ClassWizard:
|
|
|
|
|
case IWizard::FileWizard:
|
|
|
|
|
default:
|
|
|
|
|
kindItem = filesClassesKindItem;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-02-08 17:25:35 +01:00
|
|
|
addItem(kindItem, wizard);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-04-16 14:12:55 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IWizard *NewDialog::showDialog()
|
|
|
|
|
{
|
2010-05-19 18:30:45 +02:00
|
|
|
static QString lastCategory;
|
|
|
|
|
QModelIndex idx;
|
|
|
|
|
|
|
|
|
|
if (!lastCategory.isEmpty())
|
|
|
|
|
foreach(QStandardItem* item, m_categoryItems) {
|
|
|
|
|
if (item->data(Qt::UserRole) == lastCategory) {
|
2012-02-08 17:25:35 +01:00
|
|
|
idx = m_twoLevelProxyModel->mapToSource(m_model->indexFromItem(item));
|
2010-05-19 18:30:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!idx.isValid())
|
2012-02-08 17:25:35 +01:00
|
|
|
idx = m_twoLevelProxyModel->index(0,0, m_twoLevelProxyModel->index(0,0));
|
2010-05-19 18:30:45 +02:00
|
|
|
|
|
|
|
|
m_ui->templateCategoryView->setCurrentIndex(idx);
|
|
|
|
|
|
2010-04-20 19:07:36 +02:00
|
|
|
// We need to set ensure that the category has default focus
|
|
|
|
|
m_ui->templateCategoryView->setFocus(Qt::NoFocusReason);
|
|
|
|
|
|
2012-02-08 17:25:35 +01:00
|
|
|
for (int row = 0; row < m_twoLevelProxyModel->rowCount(); ++row)
|
|
|
|
|
m_ui->templateCategoryView->setExpanded(m_twoLevelProxyModel->index(row, 0), true);
|
2010-04-16 14:12:55 +02:00
|
|
|
|
2010-05-11 11:30:10 +02:00
|
|
|
// Ensure that item description is visible on first show
|
|
|
|
|
currentItemChanged(m_ui->templatesView->rootIndex().child(0,0));
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
updateOkButton();
|
2010-05-19 18:30:45 +02:00
|
|
|
|
|
|
|
|
const int retVal = exec();
|
|
|
|
|
|
|
|
|
|
idx = m_ui->templateCategoryView->currentIndex();
|
2012-02-08 17:25:35 +01:00
|
|
|
lastCategory = m_model->itemFromIndex(m_twoLevelProxyModel->mapToSource(idx))->data(Qt::UserRole).toString();
|
2010-05-19 18:30:45 +02:00
|
|
|
|
|
|
|
|
if (retVal != Accepted)
|
2008-12-02 12:01:29 +01:00
|
|
|
return 0;
|
2010-05-19 18:30:45 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
return currentWizard();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-08 17:25:35 +01:00
|
|
|
QString NewDialog::selectedPlatform() const
|
|
|
|
|
{
|
|
|
|
|
int index = m_ui->comboBox->currentIndex();
|
|
|
|
|
|
|
|
|
|
return m_ui->comboBox->itemData(index).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NewDialog::selectedWizardOption() const
|
|
|
|
|
{
|
|
|
|
|
QStandardItem *item = m_model->itemFromIndex(m_ui->templatesView->currentIndex());
|
|
|
|
|
return item->data(Qt::UserRole).value<WizardContainer>().wizardOption;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
NewDialog::~NewDialog()
|
|
|
|
|
{
|
|
|
|
|
delete m_ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IWizard *NewDialog::currentWizard() const
|
|
|
|
|
{
|
2012-02-08 17:25:35 +01:00
|
|
|
QModelIndex index = m_filterProxyModel->mapToSource(m_ui->templatesView->currentIndex());
|
|
|
|
|
return wizardOfItem(m_model->itemFromIndex(index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewDialog::addItem(QStandardItem *topLEvelCategoryItem, IWizard *wizard)
|
|
|
|
|
{
|
|
|
|
|
const QString categoryName = wizard->category();
|
|
|
|
|
QStandardItem *categoryItem = 0;
|
|
|
|
|
for (int i = 0; i < topLEvelCategoryItem->rowCount(); i++) {
|
|
|
|
|
if (topLEvelCategoryItem->child(i, 0)->data(Qt::UserRole) == categoryName)
|
|
|
|
|
categoryItem = topLEvelCategoryItem->child(i, 0);
|
|
|
|
|
}
|
|
|
|
|
if (!categoryItem) {
|
|
|
|
|
categoryItem = new QStandardItem();
|
|
|
|
|
topLEvelCategoryItem->appendRow(categoryItem);
|
|
|
|
|
m_categoryItems.append(categoryItem);
|
|
|
|
|
categoryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
|
|
|
|
categoryItem->setText(QLatin1String(" ") + wizard->displayCategory());
|
|
|
|
|
categoryItem->setData(wizard->category(), Qt::UserRole);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStandardItem *wizardItem = new QStandardItem(wizard->displayName());
|
|
|
|
|
QIcon wizardIcon;
|
|
|
|
|
|
|
|
|
|
// spacing hack. Add proper icons instead
|
|
|
|
|
if (wizard->icon().isNull()) {
|
|
|
|
|
wizardIcon = m_dummyIcon;
|
|
|
|
|
} else {
|
|
|
|
|
wizardIcon = wizard->icon();
|
|
|
|
|
}
|
|
|
|
|
wizardItem->setIcon(wizardIcon);
|
|
|
|
|
wizardItem->setData(QVariant::fromValue(WizardContainer(wizard, 0)), Qt::UserRole);
|
|
|
|
|
wizardItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
|
|
|
|
|
categoryItem->appendRow(wizardItem);
|
|
|
|
|
|
2010-04-16 14:12:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewDialog::currentCategoryChanged(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
if (index.parent() != m_model->invisibleRootItem()->index()) {
|
2012-02-08 17:25:35 +01:00
|
|
|
m_ui->templatesView->setModel(m_filterProxyModel);
|
|
|
|
|
QModelIndex sourceIndex = m_twoLevelProxyModel->mapToSource(index);
|
|
|
|
|
sourceIndex = m_filterProxyModel->mapFromSource(sourceIndex);
|
|
|
|
|
m_ui->templatesView->setRootIndex(sourceIndex);
|
2010-04-20 19:07:36 +02:00
|
|
|
// Focus the first item by default
|
|
|
|
|
m_ui->templatesView->setCurrentIndex(m_ui->templatesView->rootIndex().child(0,0));
|
|
|
|
|
|
|
|
|
|
connect(m_ui->templatesView->selectionModel(),
|
|
|
|
|
SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
|
|
|
|
|
this, SLOT(currentItemChanged(const QModelIndex&)));
|
2010-04-16 14:12:55 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-13 19:21:14 +02:00
|
|
|
void NewDialog::currentItemChanged(const QModelIndex &index)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-02-08 17:25:35 +01:00
|
|
|
QModelIndex sourceIndex = m_filterProxyModel->mapToSource(index);
|
|
|
|
|
QStandardItem* cat = (m_model->itemFromIndex(sourceIndex));
|
|
|
|
|
if (const IWizard *wizard = wizardOfItem(cat)) {
|
|
|
|
|
QString desciption = wizard->description();
|
2012-02-10 12:08:22 +01:00
|
|
|
QStringList displayNamesForSupporttedPlatforms;
|
|
|
|
|
foreach (const QString &platform, wizard->supportedPlatforms())
|
|
|
|
|
displayNamesForSupporttedPlatforms << IWizard::displayNameForPlatform(platform);
|
2012-02-08 17:25:35 +01:00
|
|
|
if (!Qt::mightBeRichText(desciption))
|
|
|
|
|
desciption.replace(QLatin1Char('\n'), QLatin1String("<br>"));
|
|
|
|
|
desciption += QLatin1String("<br><br><b>");
|
|
|
|
|
if (wizard->flags().testFlag(IWizard::PlatformIndependent))
|
|
|
|
|
desciption += tr("Platform independent") + QLatin1String("</b>");
|
|
|
|
|
else
|
|
|
|
|
desciption += tr("Supported Platforms")
|
|
|
|
|
+ QLatin1String("</b>: <tt>")
|
2012-02-10 12:08:22 +01:00
|
|
|
+ displayNamesForSupporttedPlatforms.join(QLatin1String(" "))
|
2012-02-08 17:25:35 +01:00
|
|
|
+ QLatin1String("</tt>");
|
|
|
|
|
|
|
|
|
|
m_ui->templateDescription->setHtml(desciption);
|
|
|
|
|
|
2012-02-10 15:40:53 +01:00
|
|
|
if (!wizard->descriptionImage().isEmpty()) {
|
|
|
|
|
m_ui->imageLabel->setVisible(true);
|
|
|
|
|
m_ui->imageLabel->setPixmap(wizard->descriptionImage());
|
|
|
|
|
} else {
|
|
|
|
|
m_ui->imageLabel->setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-08 17:25:35 +01:00
|
|
|
} else {
|
2010-04-16 14:12:55 +02:00
|
|
|
m_ui->templateDescription->setText(QString());
|
2012-02-08 17:25:35 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
updateOkButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewDialog::okButtonClicked()
|
|
|
|
|
{
|
2010-04-16 14:12:55 +02:00
|
|
|
if (m_ui->templatesView->currentIndex().isValid())
|
2008-12-02 12:01:29 +01:00
|
|
|
accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewDialog::updateOkButton()
|
|
|
|
|
{
|
|
|
|
|
m_okButton->setEnabled(currentWizard() != 0);
|
|
|
|
|
}
|
2012-02-08 17:25:35 +01:00
|
|
|
|
|
|
|
|
void NewDialog::setSelectedPlatform(const QString & /*platform*/)
|
|
|
|
|
{
|
|
|
|
|
//The static cast allows us to keep PlatformFilterProxyModel anonymous
|
|
|
|
|
static_cast<PlatformFilterProxyModel*>(m_filterProxyModel)->setPlatform(selectedPlatform());
|
|
|
|
|
}
|