1
/****************************************************************************
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of Qt Creator.
8
** Commercial License Usage
9
** Licensees holding valid commercial Qt licenses may use this file in
10
** accordance with the commercial license agreement provided with the
11
** Software or, alternatively, in accordance with the terms contained in
12
** a written agreement between you and Digia. For licensing terms and
13
** conditions see http://qt.digia.com/licensing. For further information
14
** use the contact form at http://qt.digia.com/contact-us.
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file. Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
** In addition, as a special exception, Digia gives you certain additional
25
** rights. These rights are described in the Digia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
****************************************************************************/
30
#include "customwidgetwidgetswizardpage.h"
31
#include "ui_customwidgetwidgetswizardpage.h"
32
#include "classdefinition.h"
34
#include <coreplugin/coreconstants.h>
38
#include <QStackedLayout>
41
namespace QmakeProjectManager {
44
CustomWidgetWidgetsWizardPage::CustomWidgetWidgetsWizardPage(QWidget *parent) :
46
m_ui(new Ui::CustomWidgetWidgetsWizardPage),
47
m_tabStackLayout(new QStackedLayout),
51
m_ui->tabStackWidget->setLayout(m_tabStackLayout);
52
m_ui->addButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_PLUS)));
53
connect(m_ui->addButton, SIGNAL(clicked()), m_ui->classList, SLOT(startEditingNewClassItem()));
54
m_ui->deleteButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_MINUS)));
55
connect(m_ui->deleteButton, SIGNAL(clicked()), m_ui->classList, SLOT(removeCurrentClass()));
56
m_ui->deleteButton->setEnabled(false);
58
// Disabled dummy for <new class> column>.
59
ClassDefinition *dummy = new ClassDefinition;
60
dummy->setFileNamingParameters(m_fileNamingParameters);
61
dummy->setEnabled(false);
62
m_tabStackLayout->addWidget(dummy);
64
connect(m_ui->classList, SIGNAL(currentRowChanged(int)),
65
this, SLOT(slotCurrentRowChanged(int)));
68
CustomWidgetWidgetsWizardPage::~CustomWidgetWidgetsWizardPage()
73
bool CustomWidgetWidgetsWizardPage::isComplete() const
78
void CustomWidgetWidgetsWizardPage::initializePage()
80
// Takes effect only if visible.
81
QTimer::singleShot(0, m_ui->classList, SLOT(startEditingNewClassItem()));
84
void CustomWidgetWidgetsWizardPage::slotCurrentRowChanged(int row)
86
const bool onDummyItem = row == m_tabStackLayout->count() - 1;
87
m_ui->deleteButton->setEnabled(!onDummyItem);
88
m_tabStackLayout->setCurrentIndex(row);
91
void CustomWidgetWidgetsWizardPage::on_classList_classAdded(const QString &name)
93
ClassDefinition *cdef = new ClassDefinition;
94
cdef->setFileNamingParameters(m_fileNamingParameters);
95
const int index = m_uiClassDefs.count();
96
m_tabStackLayout->insertWidget(index, cdef);
97
m_tabStackLayout->setCurrentIndex(index);
98
m_uiClassDefs.append(cdef);
99
cdef->enableButtons();
100
on_classList_classRenamed(index, name);
101
// First class or collection class, re-check.
102
slotCheckCompleteness();
105
void CustomWidgetWidgetsWizardPage::on_classList_classDeleted(int index)
107
delete m_tabStackLayout->widget(index);
108
m_uiClassDefs.removeAt(index);
109
if (m_uiClassDefs.empty())
110
slotCheckCompleteness();
113
void CustomWidgetWidgetsWizardPage::on_classList_classRenamed(int index, const QString &name)
115
m_uiClassDefs[index]->setClassName(name);
118
QString CustomWidgetWidgetsWizardPage::classNameAt(int i) const
120
return m_ui->classList->className(i);
123
QList<PluginOptions::WidgetOptions> CustomWidgetWidgetsWizardPage::widgetOptions() const
125
QList<PluginOptions::WidgetOptions> rc;
126
for (int i = 0; i < m_uiClassDefs.count(); i++) {
127
const ClassDefinition *cdef = m_uiClassDefs[i];
128
rc.push_back(cdef->widgetOptions(classNameAt(i)));
133
void CustomWidgetWidgetsWizardPage::slotCheckCompleteness()
135
// Complete if either a single custom widget or a collection
136
// with a collection class name specified.
137
bool completeNow = !m_uiClassDefs.isEmpty();
138
if (completeNow != m_complete) {
139
m_complete = completeNow;
140
emit completeChanged();