forked from qt-creator/qt-creator
QmlDesigner: Implement kit changing in status bar
Task-number: QDS-8975 Change-Id: Ie28585b76697f785bea2d5bb3360a6949c9c55d8 Reviewed-by: Brook Cronin <brook.cronin@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -48,18 +48,20 @@ Item {
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
|
||||
TopLevelComboBox {
|
||||
id: kits
|
||||
style: StudioTheme.Values.statusbarControlStyle
|
||||
|
||||
width: 160
|
||||
width: 200
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
//anchors.left: settingButton.right
|
||||
//anchors.leftMargin: 32
|
||||
model: [ "Qt 6", "Qt 5", "Boot2Qt", "Android" ]
|
||||
//onActivated: backend.setCurrentWorkspace(workspaces.currentText)
|
||||
anchors.left: settingButton.right
|
||||
anchors.leftMargin: 32
|
||||
model: backend.kits
|
||||
onActivated: backend.setCurrentKit(kits.currentIndex)
|
||||
openUpwards: true
|
||||
enabled: backend.isInDesignMode
|
||||
enabled: backend.isInDesignMode && backend.isQt6
|
||||
property int kitIndex: backend.currentKit
|
||||
onKitIndexChanged: kits.currentIndex = backend.currentKit
|
||||
}
|
||||
|
||||
Text {
|
||||
@@ -78,8 +80,8 @@ Item {
|
||||
style: StudioTheme.Values.statusbarControlStyle
|
||||
width: 160
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
// anchors.left: kits.right
|
||||
// anchors.leftMargin: 32
|
||||
anchors.left: kits.right
|
||||
anchors.leftMargin: 32
|
||||
model: backend.styles
|
||||
onActivated: backend.setCurrentStyle(styles.currentIndex)
|
||||
openUpwards: true
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
@@ -208,6 +209,29 @@ void ToolBarBackend::setCurrentStyle(int index)
|
||||
view->resetPuppet();
|
||||
}
|
||||
|
||||
void ToolBarBackend::setCurrentKit(int index)
|
||||
{
|
||||
auto project = ProjectExplorer::SessionManager::startupProject();
|
||||
QTC_ASSERT(project, return );
|
||||
|
||||
const auto kits = ProjectExplorer::KitManager::kits();
|
||||
|
||||
QTC_ASSERT(kits.count() > index, return );
|
||||
QTC_ASSERT(index >= 0, return );
|
||||
|
||||
const auto kit = kits.at(index);
|
||||
|
||||
auto newTarget = project->target(kit);
|
||||
if (!newTarget)
|
||||
newTarget = project->addTargetForKit(kit);
|
||||
|
||||
ProjectExplorer::SessionManager::setActiveTarget(project,
|
||||
newTarget,
|
||||
ProjectExplorer::SetActive::Cascade);
|
||||
|
||||
emit currentKitChanged();
|
||||
}
|
||||
|
||||
bool ToolBarBackend::canGoBack() const
|
||||
{
|
||||
QTC_ASSERT(designModeWidget(), return false);
|
||||
@@ -296,6 +320,25 @@ ToolBarBackend::ToolBarBackend(QObject *parent)
|
||||
connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged, this, [this]() {
|
||||
emit isInDesignModeChanged();
|
||||
});
|
||||
|
||||
connect(ProjectExplorer::SessionManager::instance(),
|
||||
&ProjectExplorer::SessionManager::startupProjectChanged,
|
||||
[this](ProjectExplorer::Project *project) {
|
||||
disconnect(m_kitConnection);
|
||||
emit isQt6Changed();
|
||||
if (project) {
|
||||
m_kitConnection = connect(project,
|
||||
&ProjectExplorer::Project::activeTargetChanged,
|
||||
this,
|
||||
&ToolBarBackend::currentKitChanged);
|
||||
emit currentKitChanged();
|
||||
}
|
||||
});
|
||||
|
||||
connect(ProjectExplorer::KitManager::instance(),
|
||||
&ProjectExplorer::KitManager::kitsChanged,
|
||||
this,
|
||||
&ToolBarBackend::kitsChanged);
|
||||
}
|
||||
|
||||
void ToolBarBackend::registerDeclarativeType()
|
||||
@@ -379,6 +422,33 @@ int ToolBarBackend::currentStyle() const
|
||||
return index;
|
||||
}
|
||||
|
||||
QStringList ToolBarBackend::kits() const
|
||||
{
|
||||
return Utils::transform(ProjectExplorer::KitManager::kits(),
|
||||
[](ProjectExplorer::Kit *kit) { return kit->displayName(); });
|
||||
}
|
||||
|
||||
int ToolBarBackend::currentKit() const
|
||||
{
|
||||
if (auto target = ProjectExplorer::SessionManager::startupTarget()) {
|
||||
auto kit = target->kit();
|
||||
if (kit)
|
||||
return kits().indexOf(kit->displayName());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ToolBarBackend::isQt6() const
|
||||
{
|
||||
const QmlProjectManager::QmlBuildSystem *buildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(
|
||||
ProjectExplorer::SessionManager::startupTarget()->buildSystem());
|
||||
QTC_ASSERT(buildSystem, return false);
|
||||
|
||||
const bool isQt6Project = buildSystem && buildSystem->qt6Project();
|
||||
|
||||
return isQt6Project;
|
||||
}
|
||||
|
||||
void ToolBarBackend::setupWorkspaces()
|
||||
{
|
||||
m_workspaces.clear();
|
||||
|
||||
@@ -78,6 +78,9 @@ class ToolBarBackend : public QObject
|
||||
Q_PROPERTY(bool isInDesignMode READ isInDesignMode NOTIFY isInDesignModeChanged)
|
||||
Q_PROPERTY(bool isDesignModeEnabled READ isDesignModeEnabled NOTIFY isDesignModeEnabledChanged)
|
||||
Q_PROPERTY(int currentStyle READ currentStyle NOTIFY currentStyleChanged)
|
||||
Q_PROPERTY(QStringList kits READ kits NOTIFY kitsChanged)
|
||||
Q_PROPERTY(int currentKit READ currentKit NOTIFY currentKitChanged)
|
||||
Q_PROPERTY(bool isQt6 READ isQt6 NOTIFY isQt6Changed)
|
||||
|
||||
public:
|
||||
ToolBarBackend(QObject *parent = nullptr);
|
||||
@@ -95,6 +98,7 @@ public:
|
||||
Q_INVOKABLE void editGlobalAnnoation();
|
||||
Q_INVOKABLE void showZoomMenu(int x, int y);
|
||||
Q_INVOKABLE void setCurrentStyle(int index);
|
||||
Q_INVOKABLE void setCurrentKit(int index);
|
||||
|
||||
bool canGoBack() const;
|
||||
bool canGoForward() const;
|
||||
@@ -113,6 +117,12 @@ public:
|
||||
bool isDesignModeEnabled() const;
|
||||
int currentStyle() const;
|
||||
|
||||
QStringList kits() const;
|
||||
|
||||
int currentKit() const;
|
||||
|
||||
bool isQt6() const;
|
||||
|
||||
signals:
|
||||
void navigationHistoryChanged();
|
||||
void openDocumentsChanged();
|
||||
@@ -122,6 +132,9 @@ signals:
|
||||
void isInDesignModeChanged();
|
||||
void isDesignModeEnabledChanged();
|
||||
void currentStyleChanged();
|
||||
void kitsChanged();
|
||||
void currentKitChanged();
|
||||
void isQt6Changed();
|
||||
|
||||
private:
|
||||
void setupWorkspaces();
|
||||
@@ -130,6 +143,7 @@ private:
|
||||
|
||||
QStringList m_openDocuments;
|
||||
QStringList m_workspaces;
|
||||
QMetaObject::Connection m_kitConnection;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
Reference in New Issue
Block a user