Skip to content

Commit

Permalink
Add module select widget, add it to launch config dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
russelltg committed May 7, 2017
1 parent bd368d0 commit b5ede80
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set(GUI_SRCS
structedit.cpp
moduletreemodel.cpp
moduleselectiondialog.cpp
moduleselectwidget.cpp
)

set(GUI_RESOURCES
Expand All @@ -103,6 +104,7 @@ set(GUI_HEADERS
structedit.hpp
moduletreemodel.hpp
moduleselectiondialog.hpp
moduleselectwidget.hpp
)

add_executable(chigraphgui ${GUI_SRCS} ${GUI_HEADERS} ${GUI_RESOURCES})
Expand Down
2 changes: 1 addition & 1 deletion src/chigraphguiui.rc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<Action name="open" />
<Action name="open-recent" />
<Action name="save" />
<Action name="configure-launches" />
</Menu>
<Menu name="process">
<text>Process</text>
<Action name="run" />
<Action name="configure-launches" />
<Action name="cancel" />
</Menu>
<Merge />
Expand Down
9 changes: 5 additions & 4 deletions src/launchconfigurationdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "launchconfigurationdialog.hpp"
#include "moduleselectwidget.hpp"

#include <KLocalizedString>

Expand Down Expand Up @@ -52,8 +53,8 @@ LaunchConfigurationDialog::LaunchConfigurationDialog(LaunchConfigurationManager&

// module
{
mModuleEdit = new QLineEdit;
connect(mModuleEdit, &QLineEdit::textChanged, this,
mModuleEdit = new ModuleSelectWidget(manager.context());
connect(mModuleEdit, &ModuleSelectWidget::moduleChanged, this,
&LaunchConfigurationDialog::moduleChanged);
layout->addRow(i18n("Module"), mModuleEdit);
}
Expand Down Expand Up @@ -123,8 +124,8 @@ void LaunchConfigurationDialog::argsChanged(const QString& newArgs) {
if (currentlyEditing.valid()) { currentlyEditing.setArguments(newArgs); }
}

void LaunchConfigurationDialog::moduleChanged(const QString& newModule) {
if (currentlyEditing.valid()) { currentlyEditing.setModule(newModule); }
void LaunchConfigurationDialog::moduleChanged(const boost::filesystem::path& newModule) {
if (currentlyEditing.valid()) { currentlyEditing.setModule(QString::fromStdString(newModule.string())); }
}

void LaunchConfigurationDialog::nameChanged(const QString& newName) {
Expand Down
8 changes: 6 additions & 2 deletions src/launchconfigurationdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

#include "launchconfigurationmanager.hpp"

#include <boost/filesystem/path.hpp>

class QListWidget;
class QLineEdit;

class ModuleSelectWidget;

class LaunchConfigurationDialog : public QDialog {
Q_OBJECT
public:
Expand All @@ -21,7 +25,7 @@ private slots:

void nameChanged(const QString& newName);
void wdChanged(const QString& newWd);
void moduleChanged(const QString& newModule);
void moduleChanged(const boost::filesystem::path& newModule);
void argsChanged(const QString& newArgs);

private:
Expand All @@ -30,7 +34,7 @@ private slots:

QLineEdit* mNameEdit;
QLineEdit* mWdEdit;
QLineEdit* mModuleEdit;
ModuleSelectWidget* mModuleEdit;
QLineEdit* mArgsEdit;

QListWidget* mConfigList;
Expand Down
24 changes: 13 additions & 11 deletions src/launchconfigurationmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "launchconfigurationmanager.hpp"

#include <chi/Context.hpp>

#include <KConfigGroup>
#include <KSharedConfig>

Expand All @@ -8,14 +10,16 @@

LaunchConfiguration::LaunchConfiguration(KConfigGroup grp) : mConfigGroup{grp} {}

LaunchConfigurationManager::LaunchConfigurationManager() {
KConfigGroup config(KSharedConfig::openConfig(), "launchconfigurations");
LaunchConfigurationManager::LaunchConfigurationManager(chi::Context& context) : mContext{&context} {
KConfigGroup contextConfig(KSharedConfig::openConfig(), context.workspacePath().string().c_str());

mConfigGroup = contextConfig.group("launchconfigurations");

auto configurations = config.readEntry("configurations", QStringList());
auto currentName = config.readEntry("current", QString());
auto configurations = mConfigGroup.readEntry("configurations", QStringList());
auto currentName = mConfigGroup.readEntry("current", QString());

for (const auto& configName : configurations) {
mConfigurations.emplace_back(KConfigGroup{KSharedConfig::openConfig(), configName});
mConfigurations.emplace_back(mConfigGroup.group(configName));

if (configName == currentName) { mCurrent = mConfigurations[mConfigurations.size() - 1]; }
}
Expand All @@ -26,11 +30,10 @@ LaunchConfiguration LaunchConfigurationManager::newConfiguration() {
auto uuid = QUuid::createUuid();

// add it to the list
KConfigGroup configs(KSharedConfig::openConfig(), "launchconfigurations");
configs.writeEntry("configurations",
configs.readEntry("configurations", QStringList()) << uuid.toString());
mConfigGroup.writeEntry("configurations",
mConfigGroup.readEntry("configurations", QStringList()) << uuid.toString());

auto group = KConfigGroup{KSharedConfig::openConfig(), uuid.toString()};
auto group = mConfigGroup.group(uuid.toString());

mConfigurations.emplace_back(group);

Expand All @@ -40,6 +43,5 @@ LaunchConfiguration LaunchConfigurationManager::newConfiguration() {
void LaunchConfigurationManager::setCurrentConfiguration(LaunchConfiguration config) {
mCurrent = config;

KConfigGroup kconfig(KSharedConfig::openConfig(), "launchconfigurations");
kconfig.writeEntry("current", config.id());
mConfigGroup.writeEntry("current", config.id());
}
9 changes: 8 additions & 1 deletion src/launchconfigurationmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <KConfigGroup>

#include <chi/Fwd.hpp>

struct LaunchConfiguration {
// constructs an invalid configuration
LaunchConfiguration() {}
Expand Down Expand Up @@ -40,7 +42,7 @@ struct LaunchConfiguration {
class LaunchConfigurationManager : public QObject {
Q_OBJECT
public:
LaunchConfigurationManager();
LaunchConfigurationManager(chi::Context& context);

LaunchConfigurationManager(const LaunchConfigurationManager&) = delete;
LaunchConfigurationManager(LaunchConfigurationManager&&) = delete;
Expand All @@ -61,10 +63,15 @@ class LaunchConfigurationManager : public QObject {
}
return {};
}

chi::Context& context() const { return *mContext; }

private:
LaunchConfiguration mCurrent;
std::vector<LaunchConfiguration> mConfigurations;
KConfigGroup mConfigGroup;

chi::Context* mContext;
};

#endif // CHIGRAPHGUI_LAUNCH_CONFIGURATION_HPP
25 changes: 16 additions & 9 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ MainWindow::MainWindow(QWidget* parent) : KXmlGuiWindow(parent) {
setWindowIcon(QIcon(":/icons/chigraphsmall.png"));

mChigContext = std::make_unique<chi::Context>(qApp->arguments()[0].toStdString().c_str());
mLaunchManager = std::make_unique<LaunchConfigurationManager>(*mChigContext);

mFunctionTabs = new FunctionTabView;
mFunctionTabs->setMovable(true);
Expand Down Expand Up @@ -222,7 +223,7 @@ MainWindow::MainWindow(QWidget* parent) : KXmlGuiWindow(parent) {
runConfigDialogAction->setText(i18n("Configure Launches"));
actColl->addAction(QStringLiteral("configure-launches"), runConfigDialogAction);
connect(runConfigDialogAction, &QAction::triggered, this, [this] {
LaunchConfigurationDialog d(mLaunchManager);
LaunchConfigurationDialog d(launchManager());

d.exec();

Expand All @@ -235,11 +236,11 @@ MainWindow::MainWindow(QWidget* parent) : KXmlGuiWindow(parent) {
connect(mConfigSelectAction,
static_cast<void (KSelectAction::*)(const QString&)>(&KSelectAction::triggered), this,
[this](const QString& str) {
mLaunchManager.setCurrentConfiguration(mLaunchManager.configByName(str));
launchManager().setCurrentConfiguration(launchManager().configByName(str));
});
updateUsableConfigs();
if (mLaunchManager.currentConfiguration().valid()) {
mConfigSelectAction->setCurrentAction(mLaunchManager.currentConfiguration().name(),
if (launchManager().currentConfiguration().valid()) {
mConfigSelectAction->setCurrentAction(launchManager().currentConfiguration().name(),
Qt::CaseSensitive);
}

Expand Down Expand Up @@ -291,25 +292,31 @@ void MainWindow::openWorkspaceDialog() {

void MainWindow::openWorkspace(const QUrl& url) {
mChigContext = std::make_unique<chi::Context>(url.toLocalFile().toStdString());
mLaunchManager = std::make_unique<LaunchConfigurationManager>(*mChigContext);
updateUsableConfigs();

workspaceOpened(*mChigContext);
}

void MainWindow::moduleDirtied(chi::GraphModule& mod) { mModuleBrowser->moduleDirtied(mod); }

void MainWindow::updateUsableConfigs() {
// save the current so we can set it back later
QString selectedText = mConfigSelectAction->currentText();

// repopulate
mConfigSelectAction->clear();

for (const auto& config : mLaunchManager.configurations()) {
for (const auto& config : launchManager().configurations()) {
mConfigSelectAction->addAction(config.name());
}

// set it back
mConfigSelectAction->setCurrentAction(selectedText, Qt::CaseSensitive);
auto currentConfig = launchManager().currentConfiguration();

if (currentConfig.valid()) {

// set it to the current config
mConfigSelectAction->setCurrentAction(currentConfig.name(), Qt::CaseSensitive);

}
}

void MainWindow::closeEvent(QCloseEvent* event) {
Expand Down
4 changes: 2 additions & 2 deletions src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MainWindow : public KXmlGuiWindow {
chi::Context& context() const { return *mChigContext; }
FunctionTabView& tabView() const { return *mFunctionTabs; }

LaunchConfigurationManager& launchManager() { return mLaunchManager; }
LaunchConfigurationManager& launchManager() { return *mLaunchManager; }

std::pair<chi::Result, chi::GraphModule*> loadModule(const QString& name);

Expand Down Expand Up @@ -65,7 +65,7 @@ public slots:

void updateUsableConfigs();

LaunchConfigurationManager mLaunchManager;
std::unique_ptr<LaunchConfigurationManager> mLaunchManager;

KRecentFilesAction* mOpenRecentAction; // keep this so we can save the entries

Expand Down
28 changes: 28 additions & 0 deletions src/moduleselectwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "moduleselectwidget.hpp"

#include "moduleselectiondialog.hpp"

ModuleSelectWidget::ModuleSelectWidget(chi::Context& ctx)
{
connect(this, &QPushButton::clicked, this, [this, &ctx](bool) {

auto modName = ModuleSelectionDialog::getModule(this, ctx);

if (modName.empty()) {
return;
}

setModule(modName);

});

setIcon(QIcon::fromTheme(QStringLiteral("package-available")));
}

void ModuleSelectWidget::setModule(const boost::filesystem::path& newModule)
{
setText(QString::fromStdString(newModule.string()));

emit moduleChanged(newModule);
}

24 changes: 24 additions & 0 deletions src/moduleselectwidget.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#ifndef CHIGRAPHGUI_MODULE_SELECT_WIDGET_HPP
#define CHIGRAPHGUI_MODULE_SELECT_WIDGET_HPP

#include <QPushButton>

#include <chi/Fwd.hpp>

#include <boost/filesystem/path.hpp>

class ModuleSelectWidget : public QPushButton {
Q_OBJECT
public:

ModuleSelectWidget(chi::Context& ctx);

void setModule(const boost::filesystem::path& newModule);

signals:
void moduleChanged(const boost::filesystem::path& moduleName);
};

#endif // CHIGRAPHGUI_MODULE_SELECT_WIDGET_HPP
2 changes: 2 additions & 0 deletions src/moduletreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ QVariant ModuleTreeModel::data(const QModelIndex& index, int role) const {
return QIcon::fromTheme(QStringLiteral("code-context"));
case WorkspaceTree::STRUCT:
return QIcon::fromTheme(QStringLiteral("code-class"));
case WorkspaceTree::FOLDER:
return QIcon::fromTheme(QStringLiteral("stock_folder"));
default:
return {};
}
Expand Down

0 comments on commit b5ede80

Please sign in to comment.