Skip to content

Commit

Permalink
Kits: new entity
Browse files Browse the repository at this point in the history
Started working on kits. Basically - the idea is that all tasks (and
binaries) will be run under a user editable script, which contains some
variables - that would be substitutioned on runtime.
  • Loading branch information
diegoiast committed Aug 2, 2024
1 parent 7c959c0 commit 4b76489
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 23 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ set(qtedit4_sources
src/plugins/ProjectManager/output.ui
src/plugins/ProjectManager/GenericItems.cpp
src/plugins/ProjectManager/GenericItems.h
src/plugins/ProjectManager/kitdefinitions.h
src/plugins/ProjectManager/kitdefinitions.cpp
src/plugins/ProjectManager/kitdefinitionmodel.h
src/plugins/ProjectManager/kitdefinitionmodel.cpp
src/main.cpp
)

Expand All @@ -66,7 +70,6 @@ else()
add_executable(qtedit4 ${qtedit4_sources})
endif()

# lib/qmdilib/demos/plugin-demo/plugins/editor
target_include_directories(qtedit4 PUBLIC
${qmdilib_SOURCE_DIR}/demos/plugin-demo
${qutepart_SOURCE_DIR}/include
Expand Down
42 changes: 28 additions & 14 deletions src/plugins/ProjectManager/ProjectManagerGUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="comboBox"/>
<widget class="QComboBox" name="projectComboBox"/>
</item>
<item>
<widget class="QToolButton" name="removeDirectory">
Expand All @@ -42,7 +42,7 @@
</font>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
<enum>Qt::FocusPolicy::StrongFocus</enum>
</property>
<property name="text">
<string>-</string>
Expand Down Expand Up @@ -72,12 +72,12 @@
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
<enum>QSizePolicy::Policy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -87,6 +87,20 @@
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="kitComboBox"/>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
Expand All @@ -101,7 +115,7 @@
<string>...</string>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
<enum>QToolButton::ToolButtonPopupMode::MenuButtonPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
Expand All @@ -111,10 +125,10 @@
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
<enum>QSizePolicy::Policy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -136,7 +150,7 @@
<string>...</string>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
<enum>QToolButton::ToolButtonPopupMode::MenuButtonPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
Expand All @@ -146,10 +160,10 @@
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
<enum>QSizePolicy::Policy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -174,7 +188,7 @@
<item>
<widget class="QListView" name="filesView">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
Expand All @@ -197,10 +211,10 @@
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
<enum>QSizePolicy::Policy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down
25 changes: 17 additions & 8 deletions src/plugins/ProjectManager/ProjectManagerPlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
#include <QMessageBox>
#include <QSettings>
#include <QSortFilterProxyModel>
#include <QStandardPaths>

#include "GenericItems.h"
#include "ProjectBuildConfig.h"
#include "ProjectManagerPlg.h"
#include "ProjectSearch.h"
#include "kitdefinitionmodel.h"
#include "pluginmanager.h"
#include "qmdihost.h"
#include "qmdiserver.h"
Expand Down Expand Up @@ -186,7 +188,7 @@ void ProjectManagerPlugin::on_client_merged(qmdiHost *host) {
connect(gui->filesView, &QAbstractItemView::clicked, this,
&ProjectManagerPlugin::onItemClicked);

connect(gui->comboBox, &QComboBox::currentIndexChanged, this,
connect(gui->projectComboBox, &QComboBox::currentIndexChanged, this,
&ProjectManagerPlugin::on_newProjectSelected);
manager->createNewPanel(Panels::West, tr("Project"), w);

Expand Down Expand Up @@ -269,8 +271,15 @@ void ProjectManagerPlugin::on_client_merged(qmdiHost *host) {
});
manager->addAction(projectSearch);

kitsModel = new KitDefinitionModel();
gui->kitComboBox->setModel(kitsModel);

auto dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
auto kits = findKitDefinitions(dataPath.toStdString());
kitsModel->setKitDefinitions(kits);

projectModel = new ProjectBuildModel();
gui->comboBox->setModel(projectModel);
gui->projectComboBox->setModel(projectModel);

runAction = new QAction(QIcon::fromTheme("document-save"), tr("&Run"), this);
buildAction = new QAction(QIcon::fromTheme("document-save-as"), tr("&Run task"), this);
Expand Down Expand Up @@ -349,7 +358,7 @@ void ProjectManagerPlugin::saveConfig(QSettings &settings) {
}

std::shared_ptr<ProjectBuildConfig> ProjectManagerPlugin::getCurrentConfig() const {
auto currentIndex = gui->comboBox->currentIndex();
auto currentIndex = gui->projectComboBox->currentIndex();
if (currentIndex < 0) {
return {};
}
Expand Down Expand Up @@ -391,7 +400,7 @@ void ProjectManagerPlugin::on_addProject_clicked() {
}

void ProjectManagerPlugin::on_removeProject_clicked() {
auto index = gui->comboBox->currentIndex();
auto index = gui->projectComboBox->currentIndex();
if (index < 0) {
return;
}
Expand Down Expand Up @@ -430,17 +439,17 @@ void ProjectManagerPlugin::on_newProjectSelected(int index) {
updateExecutablesUI(config);
}

void ProjectManagerPlugin::do_runExecutable(const ExecutableInfo *selectedTarget) {
void ProjectManagerPlugin::do_runExecutable(const ExecutableInfo *info) {
if (runProcess.processId() != 0) {
runProcess.kill();
return;
}

auto hash = getConfigHash();
auto project = getCurrentConfig();
auto executablePath = findExecForPlatform(selectedTarget->executables);
auto executablePath = findExecForPlatform(info->executables);
auto currentTask = expand(executablePath, hash);
auto workingDirectory = expand(selectedTarget->runDirectory, hash);
auto workingDirectory = expand(info->runDirectory, hash);
if (workingDirectory.isEmpty()) {
workingDirectory = project->buildDir;
}
Expand Down Expand Up @@ -567,7 +576,7 @@ void ProjectManagerPlugin::on_projectFile_modified(const QString &path) {
return;
}
*inMemoryConfig = *onDiskConfig;
emit on_newProjectSelected(gui->comboBox->currentIndex());
emit on_newProjectSelected(gui->projectComboBox->currentIndex());

// TODO - new file created is not working yet.
qDebug("Config file modified - %s", path.toStdString().data());
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/ProjectManager/ProjectManagerPlg.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "iplugin.h"
#include "kitdefinitions.h"
#include <QFileSystemWatcher>
#include <QProcess>

Expand All @@ -13,6 +14,7 @@ class ProjectBuildModel;
class FoldersModel;
class DirectoryModel;
class FilterOutProxyModel;
class KitDefinitionModel;

struct ProjectBuildConfig;
struct TaskInfo;
Expand Down Expand Up @@ -64,6 +66,7 @@ class ProjectManagerPlugin : public IPlugin {

QProcess runProcess;

KitDefinitionModel *kitsModel = nullptr;
ProjectBuildModel *projectModel = nullptr;
DirectoryModel *directoryModel;
FilterOutProxyModel *filesFilterModel;
Expand Down
32 changes: 32 additions & 0 deletions src/plugins/ProjectManager/kitdefinitionmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "kitdefinitionmodel.h"

KitDefinitionModel::KitDefinitionModel(QObject *parent)
: QAbstractListModel(parent)
{}

void KitDefinitionModel::setKitDefinitions(const std::vector<KitDefinition> &kits)
{
kitDefinitions = kits;
// Notify the view that the model data has changed
beginResetModel();
endResetModel();
}

int KitDefinitionModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return kitDefinitions.size();
}

QVariant KitDefinitionModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= kitDefinitions.size()) {
return QVariant();
}

const auto &kit = kitDefinitions[index.row()];
if (role == Qt::DisplayRole) {
return QString::fromStdString(kit.name); // Display the name in the combo box
}
return QVariant();
}
19 changes: 19 additions & 0 deletions src/plugins/ProjectManager/kitdefinitionmodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "kitdefinitions.h"
#include <QAbstractListModel>
#include <QString>
#include <vector>

class KitDefinitionModel : public QAbstractListModel {
Q_OBJECT

public:
KitDefinitionModel(QObject *parent = nullptr);
void setKitDefinitions(const std::vector<KitDefinition> &kits);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

private:
std::vector<KitDefinition> kitDefinitions; // Store a copy of the vector
};
Loading

0 comments on commit 4b76489

Please sign in to comment.