Added default target variant option in project configuration

This commit is contained in:
Nav
2021-04-08 20:42:23 +01:00
parent b781900a3f
commit c1c32fd1cc
7 changed files with 43 additions and 4 deletions

View File

@@ -42,6 +42,7 @@ int Application::run(const std::vector<std::string>& arguments) {
if (this->insightConfig.insightEnabled) { if (this->insightConfig.insightEnabled) {
this->insight.setApplicationConfig(this->applicationConfig); this->insight.setApplicationConfig(this->applicationConfig);
this->insight.setEnvironmentConfig(this->environmentConfig); this->insight.setEnvironmentConfig(this->environmentConfig);
this->insight.setInsightConfig(this->insightConfig);
this->insight.run(); this->insight.run();
Logger::debug("Insight closed"); Logger::debug("Insight closed");
this->shutdown(); this->shutdown();

View File

@@ -79,6 +79,11 @@ void TargetConfig::init(QJsonObject jsonObject) {
} }
this->name = jsonObject.find("name")->toString().toLower().toStdString(); this->name = jsonObject.find("name")->toString().toLower().toStdString();
if (jsonObject.contains("variantName")) {
this->variantName = jsonObject.find("variantName").value().toString().toLower().toStdString();
}
this->jsonObject = jsonObject; this->jsonObject = jsonObject;
} }

View File

@@ -47,6 +47,9 @@ namespace Bloom
void init(QJsonObject jsonObject); void init(QJsonObject jsonObject);
std::string name; std::string name;
std::string variantName;
QJsonObject jsonObject; QJsonObject jsonObject;
}; };

View File

@@ -61,7 +61,7 @@ void Insight::startup() {
qRegisterMetaType<Bloom::Targets::TargetState>(); qRegisterMetaType<Bloom::Targets::TargetState>();
qRegisterMetaType<std::map<int, Bloom::Targets::TargetPinState>>(); qRegisterMetaType<std::map<int, Bloom::Targets::TargetPinState>>();
this->mainWindow.init(*(this->application), targetDescriptor); this->mainWindow.init(*(this->application), targetDescriptor, this->insightConfig, this->environmentConfig.targetConfig);
this->mainWindow.show(); this->mainWindow.show();
/* /*

View File

@@ -26,6 +26,7 @@ namespace Bloom
private: private:
ApplicationConfig applicationConfig; ApplicationConfig applicationConfig;
EnvironmentConfig environmentConfig; EnvironmentConfig environmentConfig;
InsightConfig insightConfig;
EventManager& eventManager; EventManager& eventManager;
EventListenerPointer eventListener = std::make_shared<EventListener>("InsightEventListener"); EventListenerPointer eventListener = std::make_shared<EventListener>("InsightEventListener");
@@ -54,6 +55,10 @@ namespace Bloom
this->environmentConfig = environmentConfig; this->environmentConfig = environmentConfig;
} }
void setInsightConfig(const InsightConfig& insightConfig) {
this->insightConfig = insightConfig;
}
/** /**
* Entry point for Insight. * Entry point for Insight.
*/ */

View File

@@ -16,7 +16,12 @@ using Targets::TargetVariant;
using Targets::TargetPackage; using Targets::TargetPackage;
void InsightWindow::init(QApplication& application, TargetDescriptor targetDescriptor) { void InsightWindow::init(
QApplication& application,
TargetDescriptor targetDescriptor,
const InsightConfig& config,
const TargetConfig& targetConfig
) {
this->targetDescriptor = targetDescriptor; this->targetDescriptor = targetDescriptor;
auto mainWindowUiFile = QFile(":/compiled/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui"); auto mainWindowUiFile = QFile(":/compiled/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui");
@@ -106,7 +111,21 @@ void InsightWindow::init(QApplication& application, TargetDescriptor targetDescr
Logger::debug("Number of target variants supported by Insight: " + std::to_string(supportedVariants.size())); Logger::debug("Number of target variants supported by Insight: " + std::to_string(supportedVariants.size()));
if (!supportedVariants.empty()) { if (!supportedVariants.empty()) {
this->selectVariant(&supportedVariants.front()); auto selectedVariant = std::find_if(
supportedVariants.begin(),
supportedVariants.end(),
[&targetConfig](const TargetVariant& variant) {
auto variantName = QString::fromStdString(variant.name).toLower().toStdString();
return !targetConfig.variantName.empty() && targetConfig.variantName == variantName;
}
);
/*
* If ths user specified a valid variant name in their config file, use that as the default, otherwise just
* use the first supported variant.
*/
this->selectVariant((selectedVariant != supportedVariants.end()) ? &(*selectedVariant)
: &supportedVariants.front());
} else { } else {
if (this->targetDescriptor.variants.empty()) { if (this->targetDescriptor.variants.empty()) {

View File

@@ -7,6 +7,7 @@
#include <optional> #include <optional>
#include "AboutWindow.hpp" #include "AboutWindow.hpp"
#include "src/ApplicationConfig.hpp"
#include "TargetWidgets/TargetPackageWidget.hpp" #include "TargetWidgets/TargetPackageWidget.hpp"
#include "src/Targets/TargetState.hpp" #include "src/Targets/TargetState.hpp"
#include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetDescriptor.hpp"
@@ -71,7 +72,12 @@ namespace Bloom
public: public:
InsightWindow() = default; InsightWindow() = default;
void init(QApplication& application, Targets::TargetDescriptor targetDescriptor); void init(
QApplication& application,
Targets::TargetDescriptor targetDescriptor,
const InsightConfig& config,
const TargetConfig& targetConfig
);
void show(); void show();