~ubuntu-sdk-team/qtcreator-plugin-remotelinux/trunk

« back to all changes in this revision

Viewing changes to src/qnx/bardescriptoreditorwidget.cpp

  • Committer: CI bot
  • Author(s): Benjamin Zeller
  • Date: 2014-06-16 10:28:43 UTC
  • mfrom: (4.2.4 remotelinux)
  • Revision ID: ps-jenkins@lists.canonical.com-20140616102843-8juvmjvzwlzsboyw
Migrating to Qt5.3 and QtC 3.1 

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <coreplugin/icore.h>
45
45
#include <projectexplorer/iprojectproperties.h>
46
46
#include <projectexplorer/projectwindow.h>
 
47
#include <projectexplorer/task.h>
 
48
#include <projectexplorer/taskhub.h>
47
49
#include <texteditor/plaintexteditor.h>
48
 
#include <texteditor/texteditoractionhandler.h>
49
50
#include <texteditor/texteditorsettings.h>
50
51
#include <texteditor/texteditorconstants.h>
 
52
#include <utils/qtcassert.h>
51
53
 
52
54
using namespace Qnx;
53
55
using namespace Qnx::Internal;
54
56
 
55
 
BarDescriptorEditorWidget::BarDescriptorEditorWidget(
56
 
        QWidget *parent, TextEditor::TextEditorActionHandler *handler)
 
57
BarDescriptorEditorWidget::BarDescriptorEditorWidget(BarDescriptorEditor *editor, QWidget *parent)
57
58
    : QStackedWidget(parent)
58
 
    , m_editor(0)
59
 
    , m_handler(handler)
60
 
    , m_dirty(false)
 
59
    , m_editor(editor)
61
60
{
62
61
    Core::IContext *myContext = new Core::IContext(this);
63
62
    myContext->setWidget(this);
70
69
    initSourcePage();
71
70
 
72
71
    setCurrentIndex(0);
 
72
 
 
73
    connect(m_entryPointWidget,         SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
74
    connect(m_packageInformationWidget, SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
75
    connect(m_authorInformationWidget,  SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
76
    connect(m_generalWidget,            SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
77
    connect(m_permissionsWidget,        SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
78
    connect(m_environmentWidget,        SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
79
    connect(m_assetsWidget,             SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
80
 
 
81
    connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_entryPointWidget,         SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
82
    connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_packageInformationWidget, SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
83
    connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_authorInformationWidget,  SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
84
    connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_generalWidget,            SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
85
    connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_permissionsWidget,        SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
86
    connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_environmentWidget,        SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
87
    connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_assetsWidget,             SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
 
88
 
 
89
    connect(m_xmlSourceWidget, SIGNAL(textChanged()), this, SLOT(updateDocumentContent()));
 
90
    connect(barDescriptorDocument(), SIGNAL(changed()), this, SLOT(updateSourceView()));
73
91
}
74
92
 
75
93
void BarDescriptorEditorWidget::initGeneralPage()
98
116
    authorInformationPanel->setDisplayName(tr("Author Information"));
99
117
    authorInformationPanel->setWidget(m_authorInformationWidget);
100
118
    generalPanel->addPropertiesPanel(authorInformationPanel);
101
 
 
102
 
    connect(m_entryPointWidget, SIGNAL(changed()), this, SLOT(setDirty()));
103
 
    connect(m_packageInformationWidget, SIGNAL(changed()), this, SLOT(setDirty()));
104
 
    connect(m_authorInformationWidget, SIGNAL(changed()), this, SLOT(setDirty()));
105
119
}
106
120
 
107
121
void BarDescriptorEditorWidget::initApplicationPage()
130
144
    environmentPanel->setDisplayName(tr("Environment"));
131
145
    environmentPanel->setWidget(m_environmentWidget);
132
146
    applicationPanel->addPropertiesPanel(environmentPanel);
133
 
 
134
 
    connect(m_generalWidget, SIGNAL(changed()), this, SLOT(setDirty()));
135
 
    connect(m_permissionsWidget, SIGNAL(changed()), this, SLOT(setDirty()));
136
 
    connect(m_environmentWidget, SIGNAL(changed()), this, SLOT(setDirty()));
137
147
}
138
148
 
139
149
void BarDescriptorEditorWidget::initAssetsPage()
148
158
    assetsPropertiesPanel->setWidget(m_assetsWidget);
149
159
    assetsPanel->addPropertiesPanel(assetsPropertiesPanel);
150
160
 
151
 
    connect(m_assetsWidget, SIGNAL(changed()), this, SLOT(setDirty()));
152
 
 
153
161
    m_entryPointWidget->setAssetsModel(m_assetsWidget->assetsModel());
154
162
    connect(m_entryPointWidget, SIGNAL(imageAdded(QString)), m_assetsWidget, SLOT(addAsset(QString)));
155
163
    connect(m_entryPointWidget, SIGNAL(imageRemoved(QString)), m_assetsWidget, SLOT(removeAsset(QString)));
161
169
    addWidget(m_xmlSourceWidget);
162
170
 
163
171
    TextEditor::TextEditorSettings::initializeEditor(m_xmlSourceWidget);
164
 
    m_handler->setupActions(m_xmlSourceWidget);
165
172
    m_xmlSourceWidget->configure(QLatin1String(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE));
166
 
    connect(m_xmlSourceWidget, SIGNAL(textChanged()), this, SLOT(setDirty()));
167
173
}
168
174
 
169
175
void BarDescriptorEditorWidget::initPanelSize(ProjectExplorer::PanelsWidget *panelsWidget)
172
178
    panelsWidget->widget()->setMinimumWidth(0);
173
179
}
174
180
 
175
 
Core::IEditor *BarDescriptorEditorWidget::editor() const
176
 
{
177
 
    if (!m_editor) {
178
 
        m_editor = const_cast<BarDescriptorEditorWidget *>(this)->createEditor();
179
 
        connect(this, SIGNAL(changed()), m_editor->document(), SIGNAL(changed()));
180
 
    }
181
 
 
182
 
    return m_editor;
183
 
}
184
 
 
185
 
BarDescriptorEditorPackageInformationWidget *BarDescriptorEditorWidget::packageInformationWidget() const
186
 
{
187
 
    return m_packageInformationWidget;
188
 
}
189
 
 
190
 
BarDescriptorEditorAuthorInformationWidget *BarDescriptorEditorWidget::authorInformationWidget() const
191
 
{
192
 
    return m_authorInformationWidget;
193
 
}
194
 
 
195
 
BarDescriptorEditorEntryPointWidget *BarDescriptorEditorWidget::entryPointWidget() const
196
 
{
197
 
    return m_entryPointWidget;
198
 
}
199
 
 
200
 
BarDescriptorEditorGeneralWidget *BarDescriptorEditorWidget::generalWidget() const
201
 
{
202
 
    return m_generalWidget;
203
 
}
204
 
 
205
 
BarDescriptorEditorPermissionsWidget *BarDescriptorEditorWidget::permissionsWidget() const
206
 
{
207
 
    return m_permissionsWidget;
208
 
}
209
 
 
210
 
BarDescriptorEditorEnvironmentWidget *BarDescriptorEditorWidget::environmentWidget() const
211
 
{
212
 
    return m_environmentWidget;
213
 
}
214
 
 
215
 
BarDescriptorEditorAssetsWidget *BarDescriptorEditorWidget::assetsWidget() const
216
 
{
217
 
    return m_assetsWidget;
218
 
}
219
 
 
220
181
TextEditor::BaseTextEditorWidget *BarDescriptorEditorWidget::sourceWidget() const
221
182
{
222
183
    return m_xmlSourceWidget;
224
185
 
225
186
void BarDescriptorEditorWidget::setFilePath(const QString &filePath)
226
187
{
227
 
    Core::IDocument *doc = m_xmlSourceWidget->editorDocument();
228
 
    if (doc) {
 
188
    Core::IDocument *doc = m_xmlSourceWidget->baseTextDocument();
 
189
    if (doc)
229
190
        doc->setFilePath(filePath);
230
 
        // setFilePath() call leads to a textChanged() signal emitted
231
 
        // and therefore having this editor-widget to become dirty
232
 
        // therefore we have to explicitly unset the dirty flag
233
 
        setDirty(false);
 
191
}
 
192
 
 
193
void BarDescriptorEditorWidget::updateDocumentContent()
 
194
{
 
195
    ProjectExplorer::TaskHub::clearTasks(Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR);
 
196
    QString errorMsg;
 
197
    int errorLine;
 
198
 
 
199
    disconnect(barDescriptorDocument(), SIGNAL(changed()), this, SLOT(updateSourceView()));
 
200
    bool result = barDescriptorDocument()->loadContent(m_xmlSourceWidget->toPlainText(), true, &errorMsg, &errorLine);
 
201
    connect(barDescriptorDocument(), SIGNAL(changed()), this, SLOT(updateSourceView()));
 
202
 
 
203
    if (!result) {
 
204
        ProjectExplorer::TaskHub::addTask(ProjectExplorer::Task::Error, errorMsg, Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR,
 
205
                                          Utils::FileName::fromString(barDescriptorDocument()->filePath()), errorLine);
 
206
        ProjectExplorer::TaskHub::requestPopup();
234
207
    }
235
208
}
236
209
 
237
 
QString BarDescriptorEditorWidget::xmlSource() const
238
 
{
239
 
    return m_xmlSourceWidget->toPlainText();
240
 
}
241
 
 
242
 
void BarDescriptorEditorWidget::setXmlSource(const QString &xmlSource)
243
 
{
244
 
    bool blocked = m_xmlSourceWidget->blockSignals(true);
245
 
    m_xmlSourceWidget->setPlainText(xmlSource);
246
 
    m_xmlSourceWidget->blockSignals(blocked);
247
 
}
248
 
 
249
 
bool BarDescriptorEditorWidget::isDirty() const
250
 
{
251
 
    return m_dirty;
252
 
}
253
 
 
254
 
void BarDescriptorEditorWidget::clear()
255
 
{
256
 
    m_entryPointWidget->clear();
257
 
    m_packageInformationWidget->clear();
258
 
    m_authorInformationWidget->clear();
259
 
 
260
 
    m_generalWidget->clear();
261
 
    m_permissionsWidget->clear();
262
 
    m_environmentWidget->clear();
263
 
 
264
 
    m_assetsWidget->clear();
265
 
 
266
 
    bool blocked = m_xmlSourceWidget->blockSignals(true);
267
 
    m_xmlSourceWidget->clear();
268
 
    m_xmlSourceWidget->blockSignals(blocked);
269
 
}
270
 
 
271
 
void BarDescriptorEditorWidget::setDirty(bool dirty)
272
 
{
273
 
    m_dirty = dirty;
274
 
    emit changed();
275
 
}
276
 
 
277
 
BarDescriptorEditor *BarDescriptorEditorWidget::createEditor()
278
 
{
279
 
    return new BarDescriptorEditor(this);
 
210
void BarDescriptorEditorWidget::updateSourceView()
 
211
{
 
212
    bool blocked = m_xmlSourceWidget->blockSignals(true);
 
213
 
 
214
    int line;
 
215
    int column;
 
216
    int position = m_xmlSourceWidget->position();
 
217
    m_xmlSourceWidget->convertPosition(position, &line, &column);
 
218
 
 
219
    m_xmlSourceWidget->setPlainText(barDescriptorDocument()->xmlSource());
 
220
 
 
221
    m_xmlSourceWidget->gotoLine(line, column);
 
222
 
 
223
    m_xmlSourceWidget->blockSignals(blocked);
 
224
}
 
225
 
 
226
BarDescriptorDocument *BarDescriptorEditorWidget::barDescriptorDocument() const
 
227
{
 
228
    return qobject_cast<BarDescriptorDocument*>(m_editor->document());
280
229
}