Commit dceb1c3a authored by Tobias Nätterlund's avatar Tobias Nätterlund Committed by Tobias Nätterlund

QNX: Refactored bar descriptor editor

The Bar descriptor editor now uses the PanelWidget with PropertiesPanels
instead, to make it more similar to the rest of the Qt Creator UI.

Split the BarDescriptorEditorWidget class into multiple, smaller,
classes. Also moved the Entry Text & Images panel to the General tab,
as the Application tab was getting too crowded.

Change-Id: I691ccf3638aaad4b5f0ad0d040094f2144d2cec0
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent e3b03d77
......@@ -39,7 +39,8 @@
namespace Qnx {
namespace Internal {
struct BarDescriptorAsset {
class BarDescriptorAsset {
public:
QString source;
QString destination;
bool entry;
......
......@@ -39,6 +39,13 @@ namespace Qnx {
namespace Internal {
class BarDescriptorEditorWidget;
class BarDescriptorEditorAssetsWidget;
class BarDescriptorEditorAuthorInformationWidget;
class BarDescriptorEditorEntryPointWidget;
class BarDescriptorEditorEnvironmentWidget;
class BarDescriptorEditorGeneralWidget;
class BarDescriptorEditorPackageInformationWidget;
class BarDescriptorEditorPermissionsWidget;
class BarDescriptorDocumentAbstractNodeHandler
{
......@@ -54,7 +61,15 @@ public:
int order() const;
protected:
BarDescriptorEditorWidget *editorWidget() const;
BarDescriptorEditorPackageInformationWidget *packageInformationWidget() const;
BarDescriptorEditorAuthorInformationWidget *authorInformationWidget() const;
BarDescriptorEditorEntryPointWidget *entryPointWidget() const;
BarDescriptorEditorGeneralWidget *generalWidget() const;
BarDescriptorEditorPermissionsWidget *permissionsWidget() const;
BarDescriptorEditorEnvironmentWidget *environmentWidget() const;
BarDescriptorEditorAssetsWidget *assetsWidget() const;
virtual bool fromNode(const QDomNode &node) = 0;
......
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "bardescriptoreditorabstractpanelwidget.h"
#include <utils/pathchooser.h>
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QTextEdit>
using namespace Qnx;
using namespace Qnx::Internal;
BarDescriptorEditorAbstractPanelWidget::BarDescriptorEditorAbstractPanelWidget(QWidget *parent) :
QWidget(parent)
{
}
void BarDescriptorEditorAbstractPanelWidget::setComboBoxBlocked(QComboBox *comboBox, int index)
{
bool blocked = comboBox->blockSignals(true);
comboBox->setCurrentIndex(index);
comboBox->blockSignals(blocked);
}
void BarDescriptorEditorAbstractPanelWidget::setCheckBoxBlocked(QCheckBox *checkBox, bool checked)
{
bool blocked = checkBox->blockSignals(true);
checkBox->setChecked(checked);
checkBox->blockSignals(blocked);
}
void BarDescriptorEditorAbstractPanelWidget::setLineEditBlocked(QLineEdit *lineEdit, const QString &text)
{
bool blocked = lineEdit->blockSignals(true);
lineEdit->setText(text);
lineEdit->blockSignals(blocked);
}
void BarDescriptorEditorAbstractPanelWidget::setTextEditBlocked(QTextEdit *textEdit, const QString &text)
{
bool blocked = textEdit->blockSignals(true);
textEdit->setPlainText(text);
textEdit->blockSignals(blocked);
}
void BarDescriptorEditorAbstractPanelWidget::setPathChooserBlocked(Utils::PathChooser *pathChooser, const QString &path)
{
bool blocked = pathChooser->blockSignals(true);
pathChooser->setPath(path);
pathChooser->blockSignals(blocked);
}
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QNX_INTERNAL_BARDESCRIPTOREDITORABSTRACTPANELWIDGET_H
#define QNX_INTERNAL_BARDESCRIPTOREDITORABSTRACTPANELWIDGET_H
#include <QWidget>
namespace Utils {
class PathChooser;
}
QT_BEGIN_NAMESPACE
class QCheckBox;
class QComboBox;
class QLineEdit;
class QTextEdit;
QT_END_NAMESPACE
namespace Qnx {
namespace Internal {
class BarDescriptorEditorAbstractPanelWidget : public QWidget
{
Q_OBJECT
public:
explicit BarDescriptorEditorAbstractPanelWidget(QWidget *parent = 0);
virtual void clear() = 0;
signals:
void changed();
protected:
void setComboBoxBlocked(QComboBox *comboBox, int index);
void setCheckBoxBlocked(QCheckBox *checkBox, bool checked);
void setLineEditBlocked(QLineEdit *lineEdit, const QString &text);
void setTextEditBlocked(QTextEdit *textEdit, const QString &text);
void setPathChooserBlocked(Utils::PathChooser *pathChooser, const QString &path);
};
} // namespace Internal
} // namespace Qnx
#endif // QNX_INTERNAL_BARDESCRIPTOREDITORABSTRACTPANELWIDGET_H
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "bardescriptoreditorassetswidget.h"
#include "ui_bardescriptoreditorassetswidget.h"
#include "bardescriptordocument.h"
#include <utils/qtcassert.h>
#include <QFileDialog>
#include <QStandardItemModel>
using namespace Qnx;
using namespace Qnx::Internal;
BarDescriptorEditorAssetsWidget::BarDescriptorEditorAssetsWidget(QWidget *parent) :
BarDescriptorEditorAbstractPanelWidget(parent),
m_ui(new Ui::BarDescriptorEditorAssetsWidget)
{
m_ui->setupUi(this);
QStringList headerLabels;
headerLabels << tr("Path") << tr("Destination") << tr("Entry-Point");
m_assetsModel = new QStandardItemModel(this);
m_assetsModel->setHorizontalHeaderLabels(headerLabels);
m_ui->assets->setModel(m_assetsModel);
connect(m_ui->addAsset, SIGNAL(clicked()), this, SLOT(addNewAsset()));
connect(m_ui->removeAsset, SIGNAL(clicked()), this, SLOT(removeSelectedAsset()));
connect(m_assetsModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateEntryCheckState(QStandardItem*)));
connectAssetsModel();
}
BarDescriptorEditorAssetsWidget::~BarDescriptorEditorAssetsWidget()
{
delete m_ui;
}
void BarDescriptorEditorAssetsWidget::clear()
{
// We can't just block signals, as the view depends on them
disconnectAssetsModel();
m_assetsModel->removeRows(0, m_assetsModel->rowCount());
connectAssetsModel();
}
void BarDescriptorEditorAssetsWidget::addAsset(const BarDescriptorAsset &asset)
{
disconnectAssetsModel();
addAssetInternal(asset);
connectAssetsModel();
}
QList<BarDescriptorAsset> BarDescriptorEditorAssetsWidget::assets() const
{
QList<BarDescriptorAsset> result;
for (int i = 0; i < m_assetsModel->rowCount(); ++i) {
BarDescriptorAsset asset;
asset.source = m_assetsModel->item(i, 0)->text();
asset.destination = m_assetsModel->item(i, 1)->text();
asset.entry = m_assetsModel->item(i, 2)->checkState() == Qt::Checked;
result << asset;
}
return result;
}
QStandardItemModel *BarDescriptorEditorAssetsWidget::assetsModel() const
{
return m_assetsModel;
}
void BarDescriptorEditorAssetsWidget::addAsset(const QString &fullPath)
{
if (fullPath.isEmpty())
return;
BarDescriptorAsset asset;
asset.source = fullPath;
asset.destination = QFileInfo(fullPath).fileName();
asset.entry = false;
addAssetInternal(asset);
}
void BarDescriptorEditorAssetsWidget::removeAsset(const QString &fullPath)
{
QList<QStandardItem*> assetItems = m_assetsModel->findItems(fullPath);
foreach (QStandardItem *assetItem, assetItems) {
QList<QStandardItem*> assetRow = m_assetsModel->takeRow(assetItem->row());
while (!assetRow.isEmpty())
delete assetRow.takeLast();
}
}
void BarDescriptorEditorAssetsWidget::addNewAsset()
{
const QString fileName = QFileDialog::getOpenFileName(this, tr("Select File to Add"));
if (fileName.isEmpty())
return;
addAsset(fileName);
}
void BarDescriptorEditorAssetsWidget::removeSelectedAsset()
{
QModelIndexList selectedIndexes = m_ui->assets->selectionModel()->selectedRows();
if (selectedIndexes.isEmpty())
return;
foreach (const QModelIndex &index, selectedIndexes)
m_assetsModel->removeRow(index.row());
}
void BarDescriptorEditorAssetsWidget::updateEntryCheckState(QStandardItem *item)
{
if (item->column() != 2 || item->checkState() == Qt::Unchecked)
return;
disconnect(m_assetsModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateEntryCheckState(QStandardItem*)));
for (int i = 0; i < m_assetsModel->rowCount(); ++i) {
QStandardItem *other = m_assetsModel->item(i, 2);
if (other == item)
continue;
// Only one asset can be the entry point
other->setCheckState(Qt::Unchecked);
}
connect(m_assetsModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateEntryCheckState(QStandardItem*)));
}
void BarDescriptorEditorAssetsWidget::connectAssetsModel()
{
connect(m_assetsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
connect(m_assetsModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SIGNAL(changed()));
connect(m_assetsModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SIGNAL(changed()));
}
void BarDescriptorEditorAssetsWidget::disconnectAssetsModel()
{
disconnect(m_assetsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
disconnect(m_assetsModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SIGNAL(changed()));
disconnect(m_assetsModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SIGNAL(changed()));
}
void BarDescriptorEditorAssetsWidget::addAssetInternal(const BarDescriptorAsset &asset)
{
const QString path = asset.source;
const QString dest = asset.destination;
QTC_ASSERT(!path.isEmpty(), return);
QTC_ASSERT(!dest.isEmpty(), return);
if (hasAsset(asset))
return;
QList<QStandardItem *> items;
items << new QStandardItem(path);
items << new QStandardItem(dest);
QStandardItem *entryItem = new QStandardItem();
entryItem->setCheckable(true);
entryItem->setCheckState(asset.entry ? Qt::Checked : Qt::Unchecked);
items << entryItem;
m_assetsModel->appendRow(items);
}
bool BarDescriptorEditorAssetsWidget::hasAsset(const BarDescriptorAsset &asset)
{
for (int i = 0; i < m_assetsModel->rowCount(); ++i) {
QStandardItem *sourceItem = m_assetsModel->item(i, 0);
QStandardItem *destItem = m_assetsModel->item(i, 1);
if (sourceItem->text() == asset.source && destItem->text() == asset.destination)
return true;
}
return false;
}
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QNX_INTERNAL_BARDESCRIPTOREDITORASSETSWIDGET_H
#define QNX_INTERNAL_BARDESCRIPTOREDITORASSETSWIDGET_H
#include "bardescriptoreditorabstractpanelwidget.h"
QT_BEGIN_NAMESPACE
class QStandardItem;
class QStandardItemModel;
QT_END_NAMESPACE
namespace Qnx {
namespace Internal {
namespace Ui {
class BarDescriptorEditorAssetsWidget;
}
class BarDescriptorAsset;
class BarDescriptorEditorAssetsWidget : public BarDescriptorEditorAbstractPanelWidget
{
Q_OBJECT
public:
explicit BarDescriptorEditorAssetsWidget(QWidget *parent = 0);
~BarDescriptorEditorAssetsWidget();
void clear();
void addAsset(const BarDescriptorAsset &asset);
QList<BarDescriptorAsset> assets() const;
QStandardItemModel *assetsModel() const;
public slots:
void addAsset(const QString &fullPath);
void removeAsset(const QString &fullPath);
private slots:
void addNewAsset();
void removeSelectedAsset();
void updateEntryCheckState(QStandardItem *item);
private:
void connectAssetsModel();
void disconnectAssetsModel();
void addAssetInternal(const BarDescriptorAsset &asset);
bool hasAsset(const BarDescriptorAsset &asset);
Ui::BarDescriptorEditorAssetsWidget *m_ui;
QStandardItemModel *m_assetsModel;
};
} // namespace Internal
} // namespace Qnx
#endif // QNX_INTERNAL_BARDESCRIPTOREDITORASSETSWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Qnx::Internal::BarDescriptorEditorAssetsWidget</class>
<widget class="QWidget" name="Qnx::Internal::BarDescriptorEditorAssetsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<height>245</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeView" name="assets">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPushButton" name="addAsset">
<property name="text">
<string>Add...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeAsset">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "bardescriptoreditorauthorinformationwidget.h"
#include "ui_bardescriptoreditorauthorinformationwidget.h"
#include "blackberrydebugtokenreader.h"
#include "blackberrydeviceconfiguration.h"
#include "qnxconstants.h"
#include <projectexplorer/devicesupport/devicemanager.h>
#include <utils/qtcassert.h>
#include <QInputDialog>
#include <QMessageBox>
using namespace Qnx;
using namespace Qnx::Internal;
BarDescriptorEditorAuthorInformationWidget::BarDescriptorEditorAuthorInformationWidget(QWidget *parent) :
BarDescriptorEditorAbstractPanelWidget(parent),
m_ui(new Ui::BarDescriptorEditorAuthorInformationWidget)
{
m_ui->setupUi(this);
m_ui->setFromDebugToken->setVisible(BlackBerryDebugTokenReader::isSupported());
connect(m_ui->author, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
connect(m_ui->authorId, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
connect(m_ui->setFromDebugToken, SIGNAL(clicked()), this, SLOT(setAuthorFromDebugToken()));
}
BarDescriptorEditorAuthorInformationWidget::~BarDescriptorEditorAuthorInformationWidget()
{
delete m_ui;
}
void BarDescriptorEditorAuthorInformationWidget::clear()
{
setLineEditBlocked(m_ui->author, QString());
setLineEditBlocked(m_ui->authorId, QString());
}
QString BarDescriptorEditorAuthorInformationWidget::author() const
{
return m_ui->author->text();
}
void BarDescriptorEditorAuthorInformationWidget::setAuthor(const QString &author)
{
setLineEditBlocked(m_ui->author, author);
}
QString BarDescriptorEditorAuthorInformationWidget::authorId() const
{
return m_ui->authorId->text();
}
void BarDescriptorEditorAuthorInformationWidget::setAuthorId(const QString &authorId)
{
setLineEditBlocked(m_ui->authorId, authorId);
}
void BarDescriptorEditorAuthorInformationWidget::setAuthorFromDebugToken()
{
// To select debug token, make it fancier once the debug token management is done in
// Qt Creator