~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/qmakeprojectmanager/customwidgetwizard/customwidgetwidgetswizardpage.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-12-02 09:16:15 UTC
  • mfrom: (1.1.29)
  • Revision ID: timo.jyrinki@canonical.com-20131202091615-xbj1os1f604ber1m
New upstream release candidate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of Qt Creator.
 
7
**
 
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.
 
15
**
 
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.
 
23
**
 
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.
 
27
**
 
28
****************************************************************************/
 
29
 
 
30
#include "customwidgetwidgetswizardpage.h"
 
31
#include "ui_customwidgetwidgetswizardpage.h"
 
32
#include "classdefinition.h"
 
33
 
 
34
#include <coreplugin/coreconstants.h>
 
35
 
 
36
#include <QTimer>
 
37
 
 
38
#include <QStackedLayout>
 
39
#include <QIcon>
 
40
 
 
41
namespace QmakeProjectManager {
 
42
namespace Internal {
 
43
 
 
44
CustomWidgetWidgetsWizardPage::CustomWidgetWidgetsWizardPage(QWidget *parent) :
 
45
    QWizardPage(parent),
 
46
    m_ui(new Ui::CustomWidgetWidgetsWizardPage),
 
47
    m_tabStackLayout(new QStackedLayout),
 
48
    m_complete(false)
 
49
{
 
50
    m_ui->setupUi(this);
 
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);
 
57
 
 
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);
 
63
 
 
64
    connect(m_ui->classList, SIGNAL(currentRowChanged(int)),
 
65
            this, SLOT(slotCurrentRowChanged(int)));
 
66
}
 
67
 
 
68
CustomWidgetWidgetsWizardPage::~CustomWidgetWidgetsWizardPage()
 
69
{
 
70
    delete m_ui;
 
71
}
 
72
 
 
73
bool CustomWidgetWidgetsWizardPage::isComplete() const
 
74
{
 
75
    return m_complete;
 
76
}
 
77
 
 
78
void CustomWidgetWidgetsWizardPage::initializePage()
 
79
{
 
80
    // Takes effect only if visible.
 
81
    QTimer::singleShot(0, m_ui->classList, SLOT(startEditingNewClassItem()));
 
82
}
 
83
 
 
84
void CustomWidgetWidgetsWizardPage::slotCurrentRowChanged(int row)
 
85
{
 
86
    const bool onDummyItem = row == m_tabStackLayout->count() - 1;
 
87
    m_ui->deleteButton->setEnabled(!onDummyItem);
 
88
    m_tabStackLayout->setCurrentIndex(row);
 
89
}
 
90
 
 
91
void CustomWidgetWidgetsWizardPage::on_classList_classAdded(const QString &name)
 
92
{
 
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();
 
103
}
 
104
 
 
105
void CustomWidgetWidgetsWizardPage::on_classList_classDeleted(int index)
 
106
{
 
107
    delete m_tabStackLayout->widget(index);
 
108
    m_uiClassDefs.removeAt(index);
 
109
    if (m_uiClassDefs.empty())
 
110
        slotCheckCompleteness();
 
111
}
 
112
 
 
113
void CustomWidgetWidgetsWizardPage::on_classList_classRenamed(int index, const QString &name)
 
114
{
 
115
    m_uiClassDefs[index]->setClassName(name);
 
116
}
 
117
 
 
118
QString CustomWidgetWidgetsWizardPage::classNameAt(int i) const
 
119
{
 
120
    return m_ui->classList->className(i);
 
121
}
 
122
 
 
123
QList<PluginOptions::WidgetOptions> CustomWidgetWidgetsWizardPage::widgetOptions() const
 
124
{
 
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)));
 
129
    }
 
130
    return rc;
 
131
}
 
132
 
 
133
void CustomWidgetWidgetsWizardPage::slotCheckCompleteness()
 
134
{
 
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();
 
141
    }
 
142
}
 
143
}
 
144
}