2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "newdialog.h"
|
|
|
|
|
#include "ui_newdialog.h"
|
2010-04-16 14:12:55 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2015-01-05 11:12:39 +01:00
|
|
|
#include <coreplugin/icontext.h>
|
2014-06-27 15:15:09 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAbstractProxyModel>
|
2014-06-27 15:15:09 +02:00
|
|
|
#include <QDebug>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QItemDelegate>
|
2014-06-27 15:15:09 +02:00
|
|
|
#include <QKeyEvent>
|
|
|
|
|
#include <QModelIndex>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPainter>
|
2014-06-27 15:15:09 +02:00
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
#include <QStandardItem>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
Q_DECLARE_METATYPE(Core::IWizardFactory*)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-04-16 14:12:55 +02:00
|
|
|
namespace {
|
|
|
|
|
|
2010-05-14 11:03:30 +02:00
|
|
|
const int ICON_SIZE = 22;
|
2015-11-16 10:40:40 +01:00
|
|
|
const char LAST_CATEGORY_KEY[] = "Core/NewDialog/LastCategory";
|
|
|
|
|
const char LAST_PLATFORM_KEY[] = "Core/NewDialog/LastPlatform";
|
2010-05-14 11:03:30 +02:00
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
class WizardFactoryContainer
|
2012-02-08 17:25:35 +01:00
|
|
|
{
|
2014-05-02 16:29:17 +02:00
|
|
|
public:
|
2014-05-02 17:38:42 +02:00
|
|
|
WizardFactoryContainer() : wizard(0), wizardOption(0) {}
|
|
|
|
|
WizardFactoryContainer(Core::IWizardFactory *w, int i): wizard(w), wizardOption(i) {}
|
|
|
|
|
Core::IWizardFactory *wizard;
|
2012-02-08 17:25:35 +01:00
|
|
|
int wizardOption;
|
|
|
|
|
};
|
|
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
inline Core::IWizardFactory *factoryOfItem(const QStandardItem *item = 0)
|
2012-02-08 17:25:35 +01:00
|
|
|
{
|
|
|
|
|
if (!item)
|
|
|
|
|
return 0;
|
2014-05-02 17:38:42 +02:00
|
|
|
return item->data(Qt::UserRole).value<WizardFactoryContainer>().wizard;
|
2012-02-08 17:25:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2014-05-02 17:38:42 +02:00
|
|
|
Core::IWizardFactory *wizard = factoryOfItem(qobject_cast<QStandardItemModel*>(sourceModel())->itemFromIndex(sourceIndex));
|
2012-02-08 17:25:35 +01:00
|
|
|
if (wizard)
|
2015-05-27 15:23:29 +02:00
|
|
|
return wizard->isAvailable(m_platform);
|
2012-02-08 17:25:35 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
Q_DECLARE_METATYPE(WizardFactoryContainer)
|
2010-04-16 14:12:55 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
2015-05-29 14:23:59 +02:00
|
|
|
bool NewDialog::m_isRunning = false;
|
2014-06-27 15:15:09 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
NewDialog::NewDialog(QWidget *parent) :
|
|
|
|
|
QDialog(parent),
|
2015-02-03 23:48:19 +02:00
|
|
|
m_ui(new Ui::NewDialog),
|
2010-05-19 18:30:45 +02:00
|
|
|
m_okButton(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-05-29 14:23:59 +02:00
|
|
|
QTC_CHECK(!m_isRunning);
|
|
|
|
|
|
|
|
|
|
m_isRunning = true;
|
|
|
|
|
|
2011-04-15 11:43:09 +02:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2014-07-16 10:42:40 +02:00
|
|
|
setWindowFlags(windowFlags());
|
2014-06-27 15:15:09 +02:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2015-01-05 11:12:39 +01:00
|
|
|
ICore::registerWindow(this, Context("Core.NewDialog"));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui->setupUi(this);
|
2012-05-22 13:40:38 +02:00
|
|
|
QPalette p = m_ui->frame->palette();
|
|
|
|
|
p.setColor(QPalette::Window, p.color(QPalette::Base));
|
|
|
|
|
m_ui->frame->setPalette(p);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok);
|
|
|
|
|
m_okButton->setDefault(true);
|
2013-11-05 15:55:42 +01: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);
|
|
|
|
|
|
2014-04-07 12:16:48 +02:00
|
|
|
m_ui->templatesView->setModel(m_filterProxyModel);
|
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
|
|
|
|
2015-05-29 17:37:20 +02:00
|
|
|
connect(m_ui->templateCategoryView->selectionModel(), &QItemSelectionModel::currentChanged,
|
|
|
|
|
this, &NewDialog::currentCategoryChanged);
|
2014-04-07 12:16:48 +02:00
|
|
|
|
2015-05-29 17:37:20 +02:00
|
|
|
connect(m_ui->templatesView->selectionModel(), &QItemSelectionModel::currentChanged,
|
|
|
|
|
this, &NewDialog::currentItemChanged);
|
2014-04-07 12:16:48 +02:00
|
|
|
|
2015-05-29 17:37:20 +02:00
|
|
|
connect(m_ui->templatesView, &QListView::doubleClicked, this, &NewDialog::accept);
|
|
|
|
|
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &NewDialog::accept);
|
|
|
|
|
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &NewDialog::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
|
2014-05-02 17:38:42 +02:00
|
|
|
static bool wizardFactoryLessThan(const IWizardFactory *f1, const IWizardFactory *f2)
|
2009-11-27 10:33:24 +01:00
|
|
|
{
|
2014-05-02 17:38:42 +02:00
|
|
|
if (const int cc = f1->category().compare(f2->category()))
|
2009-11-27 10:33:24 +01:00
|
|
|
return cc < 0;
|
2015-05-18 17:45:04 +02:00
|
|
|
return f1->id().toString().compare(f2->id().toString()) < 0;
|
2009-11-27 10:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-27 15:15:09 +02:00
|
|
|
void NewDialog::setWizardFactories(QList<IWizardFactory *> factories,
|
|
|
|
|
const QString &defaultLocation,
|
|
|
|
|
const QVariantMap &extraVariables)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-06-27 15:15:09 +02:00
|
|
|
m_defaultLocation = defaultLocation;
|
|
|
|
|
m_extraVariables = extraVariables;
|
2014-05-02 17:38:42 +02:00
|
|
|
qStableSort(factories.begin(), factories.end(), wizardFactoryLessThan);
|
2009-11-27 10:33:24 +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"));
|
2014-05-02 17:38:42 +02:00
|
|
|
projectKindItem->setData(IWizardFactory::ProjectWizard, Qt::UserRole);
|
2010-04-20 19:07:36 +02:00
|
|
|
projectKindItem->setFlags(0); // disable item to prevent focus
|
2015-05-19 11:44:04 +02:00
|
|
|
QStandardItem *filesKindItem = new QStandardItem(tr("Files and Classes"));
|
|
|
|
|
filesKindItem->setData(IWizardFactory::FileWizard, Qt::UserRole);
|
|
|
|
|
filesKindItem->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);
|
2015-05-19 11:44:04 +02:00
|
|
|
parentItem->appendRow(filesKindItem);
|
2010-04-16 14:12:55 +02:00
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (m_dummyIcon.isNull())
|
2012-02-08 17:25:35 +01:00
|
|
|
m_dummyIcon = QIcon(QLatin1String(Core::Constants::ICON_NEWFILE));
|
2010-04-16 14:12:55 +02:00
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
QStringList availablePlatforms = IWizardFactory::allAvailablePlatforms();
|
2013-07-12 11:12:08 +02:00
|
|
|
m_ui->comboBox->addItem(tr("All Templates"), QString());
|
2010-04-16 14:12:55 +02:00
|
|
|
|
2013-07-12 11:12:08 +02:00
|
|
|
foreach (const QString &platform, availablePlatforms) {
|
2014-05-02 17:38:42 +02:00
|
|
|
const QString displayNameForPlatform = IWizardFactory::displayNameForPlatform(platform);
|
2013-07-12 11:12:08 +02:00
|
|
|
m_ui->comboBox->addItem(tr("%1 Templates").arg(displayNameForPlatform), platform);
|
2012-02-08 17:25:35 +01:00
|
|
|
}
|
|
|
|
|
|
2015-05-29 11:53:52 +02:00
|
|
|
m_ui->comboBox->setCurrentIndex(0); // "All templates"
|
|
|
|
|
m_ui->comboBox->setEnabled(!availablePlatforms.isEmpty());
|
2013-07-12 11:12:08 +02:00
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
foreach (IWizardFactory *factory, factories) {
|
2013-07-12 11:12:08 +02:00
|
|
|
QStandardItem *kindItem;
|
2014-05-02 17:38:42 +02:00
|
|
|
switch (factory->kind()) {
|
|
|
|
|
case IWizardFactory::ProjectWizard:
|
2013-07-12 11:12:08 +02:00
|
|
|
kindItem = projectKindItem;
|
|
|
|
|
break;
|
2014-05-02 17:38:42 +02:00
|
|
|
case IWizardFactory::FileWizard:
|
2013-07-12 11:12:08 +02:00
|
|
|
default:
|
2015-05-19 11:44:04 +02:00
|
|
|
kindItem = filesKindItem;
|
2013-07-12 11:12:08 +02:00
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2014-05-02 17:38:42 +02:00
|
|
|
addItem(kindItem, factory);
|
2010-04-16 14:12:55 +02:00
|
|
|
}
|
2012-04-10 13:23:57 +02:00
|
|
|
if (projectKindItem->columnCount() == 0)
|
|
|
|
|
parentItem->removeRow(0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-27 15:15:09 +02:00
|
|
|
void NewDialog::showDialog()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-05-19 18:30:45 +02:00
|
|
|
QModelIndex idx;
|
|
|
|
|
|
2015-11-16 10:40:40 +01:00
|
|
|
QString lastPlatform = ICore::settings()->value(QLatin1String(LAST_PLATFORM_KEY)).toString();
|
|
|
|
|
QString lastCategory = ICore::settings()->value(QLatin1String(LAST_CATEGORY_KEY)).toString();
|
2014-07-29 07:42:13 +02:00
|
|
|
|
2015-11-16 10:40:40 +01:00
|
|
|
if (!lastPlatform.isEmpty()) {
|
|
|
|
|
int index = m_ui->comboBox->findData(lastPlatform);
|
|
|
|
|
if (index != -1)
|
|
|
|
|
m_ui->comboBox->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lastCategory.isEmpty())
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (QStandardItem* item, m_categoryItems) {
|
2015-11-16 10:40:40 +01:00
|
|
|
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();
|
2014-06-27 15:15:09 +02:00
|
|
|
show();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 14:23:59 +02:00
|
|
|
bool NewDialog::isRunning()
|
|
|
|
|
{
|
|
|
|
|
return m_isRunning;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-27 15:15:09 +02:00
|
|
|
bool NewDialog::event(QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::ShortcutOverride) {
|
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
|
|
|
|
if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
|
|
|
|
|
ke->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QDialog::event(event);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
NewDialog::~NewDialog()
|
|
|
|
|
{
|
2015-05-29 14:23:59 +02:00
|
|
|
QTC_CHECK(m_isRunning);
|
|
|
|
|
m_isRunning = false;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
delete m_ui;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
IWizardFactory *NewDialog::currentWizardFactory() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-02-08 17:25:35 +01:00
|
|
|
QModelIndex index = m_filterProxyModel->mapToSource(m_ui->templatesView->currentIndex());
|
2014-05-02 17:38:42 +02:00
|
|
|
return factoryOfItem(m_model->itemFromIndex(index));
|
2012-02-08 17:25:35 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
void NewDialog::addItem(QStandardItem *topLevelCategoryItem, IWizardFactory *factory)
|
2012-02-08 17:25:35 +01:00
|
|
|
{
|
2014-05-02 17:38:42 +02:00
|
|
|
const QString categoryName = factory->category();
|
2012-02-08 17:25:35 +01:00
|
|
|
QStandardItem *categoryItem = 0;
|
2014-05-02 17:44:34 +02:00
|
|
|
for (int i = 0; i < topLevelCategoryItem->rowCount(); i++) {
|
|
|
|
|
if (topLevelCategoryItem->child(i, 0)->data(Qt::UserRole) == categoryName)
|
|
|
|
|
categoryItem = topLevelCategoryItem->child(i, 0);
|
2012-02-08 17:25:35 +01:00
|
|
|
}
|
|
|
|
|
if (!categoryItem) {
|
|
|
|
|
categoryItem = new QStandardItem();
|
2014-05-02 17:44:34 +02:00
|
|
|
topLevelCategoryItem->appendRow(categoryItem);
|
2012-02-08 17:25:35 +01:00
|
|
|
m_categoryItems.append(categoryItem);
|
|
|
|
|
categoryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
2014-05-02 17:38:42 +02:00
|
|
|
categoryItem->setText(QLatin1String(" ") + factory->displayCategory());
|
|
|
|
|
categoryItem->setData(factory->category(), Qt::UserRole);
|
2012-02-08 17:25:35 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
QStandardItem *wizardItem = new QStandardItem(factory->displayName());
|
2012-02-08 17:25:35 +01:00
|
|
|
QIcon wizardIcon;
|
|
|
|
|
|
|
|
|
|
// spacing hack. Add proper icons instead
|
2014-05-02 17:38:42 +02:00
|
|
|
if (factory->icon().isNull())
|
2012-02-08 17:25:35 +01:00
|
|
|
wizardIcon = m_dummyIcon;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2014-05-02 17:38:42 +02:00
|
|
|
wizardIcon = factory->icon();
|
2012-02-08 17:25:35 +01:00
|
|
|
wizardItem->setIcon(wizardIcon);
|
2014-05-02 17:38:42 +02:00
|
|
|
wizardItem->setData(QVariant::fromValue(WizardFactoryContainer(factory, 0)), Qt::UserRole);
|
2012-02-08 17:25:35 +01:00
|
|
|
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
|
|
|
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));
|
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));
|
2014-05-02 17:38:42 +02:00
|
|
|
if (const IWizardFactory *wizard = factoryOfItem(cat)) {
|
2012-02-08 17:25:35 +01:00
|
|
|
QString desciption = wizard->description();
|
2014-03-19 09:41:43 +01:00
|
|
|
QStringList displayNamesForSupportedPlatforms;
|
2012-02-10 12:08:22 +01:00
|
|
|
foreach (const QString &platform, wizard->supportedPlatforms())
|
2014-05-02 17:38:42 +02:00
|
|
|
displayNamesForSupportedPlatforms << IWizardFactory::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>");
|
2014-05-02 17:38:42 +02:00
|
|
|
if (wizard->flags().testFlag(IWizardFactory::PlatformIndependent))
|
2012-02-08 17:25:35 +01:00
|
|
|
desciption += tr("Platform independent") + QLatin1String("</b>");
|
|
|
|
|
else
|
|
|
|
|
desciption += tr("Supported Platforms")
|
|
|
|
|
+ QLatin1String("</b>: <tt>")
|
2014-08-23 01:19:53 +02:00
|
|
|
+ displayNamesForSupportedPlatforms.join(QLatin1Char(' '))
|
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 {
|
2014-07-23 09:53:06 +02:00
|
|
|
m_ui->templateDescription->clear();
|
2012-02-08 17:25:35 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
updateOkButton();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-27 15:15:09 +02:00
|
|
|
void NewDialog::saveState()
|
|
|
|
|
{
|
|
|
|
|
QModelIndex idx = m_ui->templateCategoryView->currentIndex();
|
|
|
|
|
QStandardItem *currentItem = m_model->itemFromIndex(m_twoLevelProxyModel->mapToSource(idx));
|
|
|
|
|
if (currentItem)
|
2015-11-16 10:40:40 +01:00
|
|
|
ICore::settings()->setValue(QLatin1String(LAST_CATEGORY_KEY),
|
|
|
|
|
currentItem->data(Qt::UserRole));
|
|
|
|
|
ICore::settings()->setValue(QLatin1String(LAST_PLATFORM_KEY), m_ui->comboBox->currentData());
|
2014-06-27 15:15:09 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-29 17:37:20 +02:00
|
|
|
void NewDialog::accept()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-05-29 17:37:20 +02:00
|
|
|
saveState();
|
|
|
|
|
QDialog::accept();
|
2014-06-27 15:15:09 +02:00
|
|
|
|
2015-05-29 17:37:20 +02:00
|
|
|
if (m_ui->templatesView->currentIndex().isValid()) {
|
2014-06-27 15:15:09 +02:00
|
|
|
IWizardFactory *wizard = currentWizardFactory();
|
|
|
|
|
QTC_ASSERT(wizard, accept(); return);
|
2015-05-19 15:09:51 +02:00
|
|
|
QString path = wizard->runPath(m_defaultLocation);
|
2014-06-27 15:15:09 +02:00
|
|
|
wizard->runWizard(path, ICore::dialogParent(), selectedPlatform(), m_extraVariables);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewDialog::reject()
|
|
|
|
|
{
|
|
|
|
|
saveState();
|
|
|
|
|
QDialog::reject();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewDialog::updateOkButton()
|
|
|
|
|
{
|
2014-05-02 17:38:42 +02:00
|
|
|
m_okButton->setEnabled(currentWizardFactory() != 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
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());
|
|
|
|
|
}
|