2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectwindow.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
#include "kit.h"
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "kitmanager.h"
|
2016-07-22 15:53:01 +02:00
|
|
|
#include "panelswidget.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
#include "project.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectexplorer.h"
|
2014-07-28 14:35:53 +02:00
|
|
|
#include "projectpanelfactory.h"
|
2016-09-14 12:55:04 +02:00
|
|
|
#include "propertiespanel.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "session.h"
|
2010-12-10 19:02:19 +01:00
|
|
|
#include "target.h"
|
2016-07-22 15:53:01 +02:00
|
|
|
#include "targetsettingspanel.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <coreplugin/coreicons.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <utils/navigationtreeview.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/styledbar.h>
|
|
|
|
|
#include <utils/treemodel.h>
|
2016-09-16 13:27:22 +02:00
|
|
|
#include <utils/basetreeview.h>
|
2016-07-22 15:53:01 +02:00
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QDockWidget>
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QStyledItemDelegate>
|
2016-09-14 12:55:04 +02:00
|
|
|
#include <QTimer>
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <QTreeView>
|
2014-07-11 16:54:04 +02:00
|
|
|
#include <QVBoxLayout>
|
2009-09-29 18:06:13 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
2009-08-06 15:31:32 +02:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
class MiscSettingsGroupItem;
|
|
|
|
|
class RootItem;
|
|
|
|
|
|
|
|
|
|
// Standard third level for the generic case: i.e. all except for the Build/Run page
|
|
|
|
|
class MiscSettingsPanelItem : public TreeItem // TypedTreeItem<TreeItem, MiscSettingsGroupItem>
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
public:
|
2016-09-14 12:55:04 +02:00
|
|
|
MiscSettingsPanelItem(ProjectPanelFactory *factory, Project *project)
|
|
|
|
|
: m_factory(factory), m_project(project)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
~MiscSettingsPanelItem() { delete m_widget; }
|
|
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const override;
|
|
|
|
|
Qt::ItemFlags flags(int column) const override;
|
|
|
|
|
bool setData(int column, const QVariant &, int role) override;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
ProjectPanelFactory *m_factory = nullptr;
|
|
|
|
|
QPointer<Project> m_project;
|
|
|
|
|
|
|
|
|
|
mutable QPointer<QWidget> m_widget = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVariant MiscSettingsPanelItem::data(int column, int role) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(column)
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
if (m_factory)
|
|
|
|
|
return m_factory->displayName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == PanelWidgetRole) {
|
|
|
|
|
if (!m_widget) {
|
|
|
|
|
auto panelsWidget = new PanelsWidget;
|
|
|
|
|
auto panel = new PropertiesPanel;
|
|
|
|
|
panel->setDisplayName(m_factory->displayName());
|
|
|
|
|
QWidget *widget = m_factory->createWidget(m_project);
|
|
|
|
|
panel->setWidget(widget);
|
|
|
|
|
panel->setIcon(QIcon(m_factory->icon()));
|
|
|
|
|
panelsWidget->addPropertiesPanel(panel);
|
|
|
|
|
panelsWidget->setFocusProxy(widget);
|
|
|
|
|
m_widget = panelsWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QVariant::fromValue<QWidget *>(m_widget.data());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == ActiveItemRole) // We are the active one.
|
|
|
|
|
return QVariant::fromValue<TreeItem *>(const_cast<MiscSettingsPanelItem *>(this));
|
|
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags MiscSettingsPanelItem::flags(int column) const
|
|
|
|
|
{
|
|
|
|
|
if (m_factory && m_project) {
|
|
|
|
|
if (!m_factory->supports(m_project))
|
|
|
|
|
return Qt::ItemIsSelectable;
|
|
|
|
|
}
|
|
|
|
|
return TreeItem::flags(column);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MiscSettingsPanelItem::setData(int column, const QVariant &, int role)
|
|
|
|
|
{
|
|
|
|
|
if (role == ItemActivatedDirectlyRole) {
|
|
|
|
|
// Bubble up
|
|
|
|
|
return parent()->setData(column, QVariant::fromValue(static_cast<TreeItem *>(this)),
|
|
|
|
|
ItemActivatedFromBelowRole);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The lower part of the second tree level, i.e. the project settings list.
|
|
|
|
|
// The upper part is the TargetSettingsPanelItem .
|
|
|
|
|
class MiscSettingsGroupItem : public TreeItem // TypedTreeItem<MiscSettingsPanelItem, ProjectItem>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit MiscSettingsGroupItem(Project *project)
|
|
|
|
|
: m_project(project)
|
2016-07-22 15:53:01 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_project, return);
|
|
|
|
|
foreach (ProjectPanelFactory *factory, ProjectPanelFactory::factories())
|
2016-09-14 12:55:04 +02:00
|
|
|
appendChild(new MiscSettingsPanelItem(factory, project));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags flags(int) const override
|
|
|
|
|
{
|
|
|
|
|
return Qt::ItemIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const override
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
return ProjectWindow::tr("Project Settings");
|
|
|
|
|
|
|
|
|
|
case PanelWidgetRole:
|
|
|
|
|
case ActiveItemRole:
|
|
|
|
|
if (0 <= m_currentPanelIndex && m_currentPanelIndex < childCount())
|
|
|
|
|
return childAt(m_currentPanelIndex)->data(column, role);
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool setData(int column, const QVariant &data, int role) override
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(column)
|
|
|
|
|
|
|
|
|
|
if (role == ItemActivatedFromBelowRole) {
|
|
|
|
|
TreeItem *item = data.value<TreeItem *>();
|
|
|
|
|
QTC_ASSERT(item, return false);
|
|
|
|
|
m_currentPanelIndex = children().indexOf(item);
|
|
|
|
|
QTC_ASSERT(m_currentPanelIndex != -1, return false);
|
|
|
|
|
parent()->setData(0, QVariant::fromValue(static_cast<TreeItem *>(this)),
|
|
|
|
|
ItemActivatedFromBelowRole);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == ItemActivatedDirectlyRole) {
|
|
|
|
|
m_currentPanelIndex = 0; // Use the first ('Editor') page.
|
|
|
|
|
parent()->setData(0, QVariant::fromValue(static_cast<TreeItem *>(this)),
|
|
|
|
|
ItemActivatedFromBelowRole);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Project *project() const { return m_project; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_currentPanelIndex = -1;
|
|
|
|
|
|
|
|
|
|
Project * const m_project;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// The first tree level, i.e. projects (nowadays in the combobox in the top bar...)
|
|
|
|
|
class ProjectItem : public TreeItem // TypedTreeItem<TreeItem, RootItem>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit ProjectItem(Project *project) : m_project(project)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_project, return);
|
|
|
|
|
QString display = ProjectWindow::tr("Build & Run");
|
|
|
|
|
appendChild(m_targetsItem = new TargetGroupItem(display, project));
|
|
|
|
|
appendChild(m_miscItem = new MiscSettingsGroupItem(project));
|
2016-07-22 15:53:01 +02:00
|
|
|
}
|
2009-09-17 13:59:10 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
QVariant data(int column, int role) const override
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
return m_project->displayName();
|
|
|
|
|
|
|
|
|
|
case ProjectDisplayNameRole:
|
|
|
|
|
return m_project->displayName();
|
|
|
|
|
|
|
|
|
|
case Qt::DecorationRole: {
|
|
|
|
|
QVariant icon;
|
2016-09-14 12:55:04 +02:00
|
|
|
m_targetsItem->forChildrenAtLevel(1, [this, &icon](TreeItem *item) {
|
2016-07-22 15:53:01 +02:00
|
|
|
QVariant sicon = item->data(0, Qt::DecorationRole);
|
|
|
|
|
if (sicon.isValid())
|
|
|
|
|
icon = sicon;
|
|
|
|
|
});
|
|
|
|
|
return icon;
|
|
|
|
|
}
|
2009-10-07 15:46:07 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
case Qt::FontRole: {
|
|
|
|
|
QFont font;
|
|
|
|
|
font.setBold(m_project == SessionManager::startupProject());
|
|
|
|
|
return font;
|
|
|
|
|
}
|
2009-11-25 16:01:46 +01:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
case PanelWidgetRole:
|
|
|
|
|
case ActiveItemRole:
|
|
|
|
|
if (m_currentChildIndex == 0)
|
|
|
|
|
return m_targetsItem->data(column, role);
|
|
|
|
|
if (m_currentChildIndex == 1)
|
|
|
|
|
return m_miscItem->data(column, role);
|
2016-07-22 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
2009-09-17 13:59:10 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
bool setData(int column, const QVariant &data, int role) override
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(column)
|
2009-11-25 15:18:51 +01:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
if (role == ItemDeactivatedFromBelowRole) {
|
|
|
|
|
parent()->setData(0, QVariant::fromValue(static_cast<TreeItem *>(this)), role);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == ItemActivatedFromBelowRole) {
|
2016-07-22 15:53:01 +02:00
|
|
|
TreeItem *item = data.value<TreeItem *>();
|
2016-09-14 12:55:04 +02:00
|
|
|
QTC_ASSERT(item, return false);
|
|
|
|
|
int res = children().indexOf(item);
|
|
|
|
|
QTC_ASSERT(res >= 0, return false);
|
|
|
|
|
m_currentChildIndex = res;
|
|
|
|
|
parent()->setData(0, QVariant::fromValue(static_cast<TreeItem *>(this)), role);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-03-24 18:36:06 +01:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
if (role == ItemActivatedDirectlyRole) {
|
|
|
|
|
// Someone selected the project using the combobox or similar.
|
2016-07-22 15:53:01 +02:00
|
|
|
SessionManager::setStartupProject(m_project);
|
2016-09-14 12:55:04 +02:00
|
|
|
m_currentChildIndex = 0; // Use some Target page by defaults
|
|
|
|
|
m_targetsItem->setData(column, data, ItemActivatedFromAboveRole); // And propagate downwards.
|
|
|
|
|
parent()->setData(0, QVariant::fromValue(static_cast<TreeItem *>(this)),
|
|
|
|
|
ItemActivatedFromBelowRole);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == ItemActivatedFromAboveRole) {
|
|
|
|
|
// Someone selected the project using the combobox or similar.
|
|
|
|
|
// Do not change the previous active subitem,
|
|
|
|
|
SessionManager::setStartupProject(m_project);
|
|
|
|
|
// Downwards.
|
|
|
|
|
if (m_currentChildIndex == 0)
|
|
|
|
|
m_targetsItem->setData(column, data, role);
|
|
|
|
|
else if (m_currentChildIndex == 1)
|
|
|
|
|
m_miscItem->setData(column, data, role);
|
2012-04-16 19:18:26 +04:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-07 15:46:07 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
Project *project() const { return m_project; }
|
2012-07-12 13:31:35 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
private:
|
2016-09-14 12:55:04 +02:00
|
|
|
int m_currentChildIndex = 0; // Start with Build & Run.
|
|
|
|
|
Project *m_project;
|
|
|
|
|
TargetGroupItem *m_targetsItem;
|
|
|
|
|
MiscSettingsGroupItem *m_miscItem;
|
2016-07-22 15:53:01 +02:00
|
|
|
};
|
2010-03-05 09:36:05 +01:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
class RootItem : public TypedTreeItem<ProjectItem>
|
2014-07-14 17:39:46 +02:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
public:
|
|
|
|
|
QVariant data(int column, int role) const override
|
|
|
|
|
{
|
2016-09-14 12:55:04 +02:00
|
|
|
if (role == PanelWidgetRole || role == ActiveItemRole) {
|
2016-07-22 15:53:01 +02:00
|
|
|
if (0 <= m_currentProjectIndex && m_currentProjectIndex < childCount())
|
|
|
|
|
return childAt(m_currentProjectIndex)->data(column, role);
|
|
|
|
|
}
|
2010-12-10 19:02:19 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
2014-07-14 17:39:46 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
bool setData(int column, const QVariant &data, int role) override
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(column)
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
switch (role) {
|
|
|
|
|
case ItemActivatedFromBelowRole: {
|
|
|
|
|
TreeItem *t = data.value<TreeItem *>();
|
|
|
|
|
QTC_CHECK(t);
|
|
|
|
|
m_currentProjectIndex = children().indexOf(t);
|
|
|
|
|
updateAll();
|
|
|
|
|
updateExternals();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case ItemDeactivatedFromBelowRole: {
|
|
|
|
|
QTC_CHECK(data.isValid());
|
2016-07-22 15:53:01 +02:00
|
|
|
updateAll();
|
2016-09-14 12:55:04 +02:00
|
|
|
updateExternals();
|
2016-07-22 15:53:01 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2016-09-14 12:55:04 +02:00
|
|
|
case ItemActivatedFromAboveRole:
|
|
|
|
|
case ItemActivatedDirectlyRole: {
|
|
|
|
|
QTC_CHECK(!data.isValid());
|
|
|
|
|
updateAll();
|
|
|
|
|
updateExternals();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-14 17:39:46 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2014-07-14 17:39:46 +02:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
void setCurrentProject(int index)
|
|
|
|
|
{
|
|
|
|
|
m_currentProjectIndex = index;
|
|
|
|
|
m_tree->setRootIndex(childAt(index)->index());
|
|
|
|
|
updateExternals();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateExternals() const
|
|
|
|
|
{
|
|
|
|
|
QTimer::singleShot(0, [this] {
|
|
|
|
|
// Needs to be async to be run after selection changes
|
|
|
|
|
// triggered by the normal QTreeView machinery.
|
|
|
|
|
TreeItem *item = data(0, ActiveItemRole).value<TreeItem *>();
|
|
|
|
|
QTC_ASSERT(item, return);
|
|
|
|
|
QWidget *widget = item->data(0, PanelWidgetRole).value<QWidget *>();
|
|
|
|
|
m_updater(widget);
|
|
|
|
|
QModelIndex idx = item->index();
|
|
|
|
|
m_tree->selectionModel()->clear();
|
|
|
|
|
m_tree->selectionModel()->select(idx, QItemSelectionModel::Select);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
2016-07-22 15:53:01 +02:00
|
|
|
int m_currentProjectIndex = -1;
|
2016-09-14 12:55:04 +02:00
|
|
|
std::function<void(QWidget *)> m_updater;
|
|
|
|
|
QTreeView *m_tree = 0;
|
2016-07-22 15:53:01 +02:00
|
|
|
};
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2012-07-12 13:31:35 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
//
|
|
|
|
|
// SelectorModel
|
|
|
|
|
//
|
2010-01-21 13:46:19 +01:00
|
|
|
|
2016-06-24 09:36:42 +02:00
|
|
|
class SelectorModel : public TreeModel<RootItem, ProjectItem, TreeItem>
|
2010-01-21 13:46:19 +01:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
public:
|
|
|
|
|
SelectorModel(QObject *parent)
|
2016-06-24 09:36:42 +02:00
|
|
|
: TreeModel<RootItem, ProjectItem, TreeItem>(parent)
|
2016-09-14 12:55:04 +02:00
|
|
|
{}
|
2016-07-22 15:53:01 +02:00
|
|
|
};
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2009-10-07 15:46:07 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
//
|
|
|
|
|
// SelectorDelegate
|
|
|
|
|
//
|
2010-03-11 13:42:41 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
class SelectorDelegate : public QStyledItemDelegate
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
public:
|
|
|
|
|
SelectorDelegate() {}
|
|
|
|
|
|
|
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option,
|
|
|
|
|
const QModelIndex &index) const override
|
|
|
|
|
{
|
|
|
|
|
QSize s = QStyledItemDelegate::sizeHint(option, index);
|
|
|
|
|
auto model = static_cast<const SelectorModel *>(index.model());
|
2016-09-14 12:55:04 +02:00
|
|
|
if (TreeItem *item = model->itemForIndex(index)) {
|
|
|
|
|
switch (item->level()) {
|
|
|
|
|
case 2: s = QSize(s.width(), 3 * s.height()); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-22 15:53:01 +02:00
|
|
|
return s;
|
2010-08-26 18:47:32 +02:00
|
|
|
}
|
2010-02-22 15:47:47 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
void paint(QPainter *painter,
|
|
|
|
|
const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
|
|
|
|
{
|
|
|
|
|
auto model = static_cast<const SelectorModel *>(index.model());
|
|
|
|
|
QStyleOptionViewItem opt = option;
|
2016-09-14 12:55:04 +02:00
|
|
|
if (TreeItem *item = model->itemForIndex(index)) {
|
|
|
|
|
switch (item->level()) {
|
|
|
|
|
case 2:
|
|
|
|
|
opt.font.setBold(true);
|
|
|
|
|
opt.font.setPointSizeF(opt.font.pointSizeF() * 1.2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-07-22 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
QStyledItemDelegate::paint(painter, opt, index);
|
2010-03-25 16:16:38 +01:00
|
|
|
}
|
2016-07-22 15:53:01 +02:00
|
|
|
};
|
2010-03-25 16:16:38 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
//
|
|
|
|
|
// SelectorTree
|
|
|
|
|
//
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2016-09-16 13:27:22 +02:00
|
|
|
class SelectorTree : public BaseTreeView
|
2010-02-08 15:50:06 +01:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
public:
|
|
|
|
|
SelectorTree()
|
|
|
|
|
{
|
|
|
|
|
setWindowTitle("Project Kit Selector");
|
|
|
|
|
|
|
|
|
|
header()->hide();
|
|
|
|
|
setExpandsOnDoubleClick(false);
|
|
|
|
|
setHeaderHidden(true);
|
|
|
|
|
setItemsExpandable(false); // No user interaction.
|
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
|
setUniformRowHeights(false); // sic!
|
|
|
|
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
setActivationMode(SingleClickActivation);
|
|
|
|
|
setObjectName("ProjectNavigation");
|
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
2016-07-22 15:53:01 +02:00
|
|
|
};
|
|
|
|
|
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
//
|
|
|
|
|
// ProjectWindow
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
ProjectWindow::ProjectWindow()
|
2014-07-25 15:59:33 +02:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
setBackgroundRole(QPalette::Base);
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
m_selectorModel = new SelectorModel(this);
|
2016-09-14 12:55:04 +02:00
|
|
|
m_selectorModel->setHeader({ tr("Projects") });
|
|
|
|
|
m_selectorModel->rootItem()->m_updater = [this](QWidget *panel) {
|
|
|
|
|
if (QWidget *widget = centralWidget()) {
|
|
|
|
|
takeCentralWidget();
|
|
|
|
|
widget->hide(); // Don't delete.
|
|
|
|
|
}
|
|
|
|
|
if (panel) {
|
|
|
|
|
setCentralWidget(panel);
|
|
|
|
|
panel->show();
|
|
|
|
|
if (hasFocus()) // we get assigned focus from setFocusToCurrentMode, pass that on
|
|
|
|
|
panel->setFocus();
|
|
|
|
|
}
|
|
|
|
|
};
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
m_selectorTree = new SelectorTree;
|
|
|
|
|
m_selectorTree->setModel(m_selectorModel);
|
|
|
|
|
m_selectorTree->setItemDelegate(new SelectorDelegate);
|
2016-09-14 12:55:04 +02:00
|
|
|
m_selectorModel->rootItem()->m_tree = m_selectorTree;
|
2016-07-22 15:53:01 +02:00
|
|
|
connect(m_selectorTree, &QAbstractItemView::activated,
|
|
|
|
|
this, &ProjectWindow::itemActivated);
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
m_projectSelection = new QComboBox;
|
|
|
|
|
m_projectSelection->setModel(m_selectorModel);
|
|
|
|
|
// m_projectSelection->setProperty("hideicon", true);
|
|
|
|
|
// m_projectSelection->setProperty("notelideasterisk", true);
|
|
|
|
|
// m_projectSelection->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
connect(m_projectSelection, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
|
|
|
|
|
this, &ProjectWindow::projectSelected, Qt::QueuedConnection);
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
auto styledBar = new StyledBar; // The black blob on top of the side bar
|
|
|
|
|
styledBar->setObjectName("ProjectModeStyledBar");
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
auto styledBarLayout = new QHBoxLayout(styledBar);
|
|
|
|
|
styledBarLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
styledBarLayout->addWidget(m_projectSelection);
|
|
|
|
|
|
|
|
|
|
auto selectorView = new QWidget; // Black blob + Project tree + Combobox below.
|
|
|
|
|
selectorView->setObjectName("ProjectSelector"); // Needed for dock widget state saving
|
|
|
|
|
selectorView->setWindowTitle(tr("Project Selector"));
|
|
|
|
|
selectorView->setAutoFillBackground(true);
|
|
|
|
|
|
|
|
|
|
auto innerLayout = new QVBoxLayout;
|
|
|
|
|
innerLayout->setContentsMargins(14, 0, 14, 0);
|
|
|
|
|
//innerLayout->addWidget(m_projectSelection);
|
|
|
|
|
innerLayout->addWidget(m_selectorTree);
|
|
|
|
|
|
|
|
|
|
auto selectorLayout = new QVBoxLayout(selectorView);
|
|
|
|
|
selectorLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
selectorLayout->addWidget(styledBar);
|
|
|
|
|
selectorLayout->addLayout(innerLayout);
|
|
|
|
|
|
|
|
|
|
m_selectorDock = addDockForWidget(selectorView, true);
|
|
|
|
|
addDockWidget(Qt::LeftDockWidgetArea, m_selectorDock);
|
|
|
|
|
|
|
|
|
|
SessionManager *sessionManager = SessionManager::instance();
|
|
|
|
|
connect(sessionManager, &SessionManager::projectAdded,
|
|
|
|
|
this, &ProjectWindow::registerProject);
|
|
|
|
|
connect(sessionManager, &SessionManager::aboutToRemoveProject,
|
|
|
|
|
this, &ProjectWindow::deregisterProject);
|
|
|
|
|
connect(sessionManager, &SessionManager::startupProjectChanged,
|
|
|
|
|
this, &ProjectWindow::startupProjectChanged);
|
|
|
|
|
connect(m_selectorTree, &QWidget::customContextMenuRequested,
|
|
|
|
|
this, &ProjectWindow::openContextMenu);
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
void ProjectWindow::openContextMenu(const QPoint &pos)
|
2014-07-25 15:59:33 +02:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
auto menu = new QMenu;
|
|
|
|
|
menu->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
|
|
|
|
|
QModelIndex index = m_selectorTree->indexAt(pos);
|
|
|
|
|
m_selectorModel->setData(index, QVariant::fromValue(menu), ContextMenuItemAdderRole);
|
|
|
|
|
|
|
|
|
|
if (menu->actions().isEmpty())
|
|
|
|
|
delete menu;
|
|
|
|
|
else
|
|
|
|
|
menu->popup(m_selectorTree->mapToGlobal(pos));
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
void ProjectWindow::contextMenuEvent(QContextMenuEvent *event)
|
2014-07-25 15:59:33 +02:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
Q_UNUSED(event)
|
|
|
|
|
// Do nothing to avoid creation of the dock window selection menu.
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
void ProjectWindow::registerProject(Project *project)
|
2014-07-25 15:59:33 +02:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
QTC_ASSERT(itemForProject(project) == nullptr, return);
|
|
|
|
|
|
|
|
|
|
auto newTab = new ProjectItem(project);
|
|
|
|
|
|
|
|
|
|
m_selectorModel->rootItem()->appendChild(newTab);
|
|
|
|
|
|
|
|
|
|
// FIXME: Add a TreeModel::insert(item, comparator)
|
|
|
|
|
m_selectorModel->rootItem()->sortChildren([this](const ProjectItem *a, const ProjectItem *b) {
|
|
|
|
|
Project *pa = a->project();
|
|
|
|
|
Project *pb = b->project();
|
|
|
|
|
QString aName = pa->displayName();
|
|
|
|
|
QString bName = pb->displayName();
|
|
|
|
|
if (aName != bName)
|
|
|
|
|
return aName < bName;
|
2016-09-14 12:55:04 +02:00
|
|
|
FileName aPath = pa->projectFilePath();
|
|
|
|
|
FileName bPath = pb->projectFilePath();
|
2016-07-22 15:53:01 +02:00
|
|
|
if (aPath != bPath)
|
|
|
|
|
return aPath < bPath;
|
|
|
|
|
return pa < pb;
|
2014-07-25 15:59:33 +02:00
|
|
|
});
|
2016-07-22 15:53:01 +02:00
|
|
|
|
|
|
|
|
m_selectorTree->expandAll();
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
void ProjectWindow::deregisterProject(Project *project)
|
2014-07-25 15:59:33 +02:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
delete m_selectorModel->takeItem(itemForProject(project));
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
void ProjectWindow::startupProjectChanged(Project *project)
|
2014-07-25 15:59:33 +02:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
if (ProjectItem *projectItem = itemForProject(project)) {
|
2016-07-27 18:08:56 +02:00
|
|
|
int index = projectItem->indexInParent();
|
2016-07-22 15:53:01 +02:00
|
|
|
QTC_ASSERT(index != -1, return);
|
|
|
|
|
m_projectSelection->setCurrentIndex(index);
|
2016-09-14 12:55:04 +02:00
|
|
|
m_selectorModel->rootItem()->setCurrentProject(index);
|
2016-07-22 15:53:01 +02:00
|
|
|
}
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
void ProjectWindow::projectSelected(int index)
|
2014-07-25 15:59:33 +02:00
|
|
|
{
|
2016-09-14 12:55:04 +02:00
|
|
|
m_selectorModel->rootItem()->setCurrentProject(index);
|
2016-07-22 15:53:01 +02:00
|
|
|
}
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
void ProjectWindow::itemActivated(const QModelIndex &index)
|
|
|
|
|
{
|
2016-09-14 12:55:04 +02:00
|
|
|
m_selectorModel->setData(index, QVariant(), ItemActivatedDirectlyRole);
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
ProjectItem *ProjectWindow::itemForProject(Project *project) const
|
|
|
|
|
{
|
2016-06-24 09:36:42 +02:00
|
|
|
return m_selectorModel->findItemAtLevel<1>([project](ProjectItem *item) {
|
2016-07-22 15:53:01 +02:00
|
|
|
return item->project() == project;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|