// example.hpp //
namespace magnesia::activities::example {
class Example : public Activity {
public:
explicit Example(QWidget* parent = nullptr);
};
// how to create the example tab from the Add Activity
class ConfigWidget : public magnesia::ConfigWidget {
public:
explicit ConfigWidget(QWidget* parent = nullptr);
};
inline constexpr ActivityMetadata metadata{
.name = u"Example",
.create_config_widget = []() -> magnesia::ConfigWidget* {
return new ConfigWidget;
},
};
}
// example.cpp //
namespace magnesia::activities::example {
Example::Example(QWidget* parent) : Activity(parent) {
auto* layout = new QHBoxLayout;
layout->addWidget(new QLabel("Hello World!"));
setLayout(layout);
}
ConfigWidget::ConfigWidget(QWidget* parent)
: magnesia::ConfigWidget(parent) {
auto* layout = new QVBoxLayout;
auto* create_button = new QPushButton("Open Example");
connect(create_button, &QPushButton::clicked, this,
[] {
Application::instance().openActivity(new Example, "Example");
});
layout->addWidget(create_button);
setLayout(layout);
}
}
// register activity //
namespace magnesia::activities {
inline constexpr std::array all{
// --snip--
example::metadata,
// --snip--
};
}
defineSettingDomain(
"general", { // domain name
QSharedPointer<magnesia::IntSetting> { // type of setting
new magnesia::IntSetting {
"opcua_poll_intervall", // internal name
"OPC UA Polling Interval", // human readable name
"in milliseconds", // description
500, 10, 30000}}, // default, min, max
QSharedPointer<magnesia::EnumSetting>{
new magnesia::EnumSetting{
"default_color", "Default Color", "The color to use everywhere.",
magnesia::EnumSettingValue{"green"},
{
magnesia::EnumSettingValue{"green"},
magnesia::EnumSettingValue{"blue"},
magnesia::EnumSettingValue{"red"},
}}}
});
Application::instance()
.getSettingsManager()
.setIntSetting({"opcua_poll_intervall", "general"}, 700);
Application::instance()
.getSettingsManager()
.getIntSetting({"opcua_poll_intervall", "general"})
.value();
Application::instance()
.getSettingsManager()
.resetSetting({"opcua_poll_intervall", "general"});
StorageId cert_id = Application::instance()
.getStorageManager()
.storeCertificate(my_cert);
QSslCertificate cert = Application::instance()
.getStorageManager()
.getCertificate(cert_id).value();
QList<std::pair<StorageId, QSslCertificate>> certs =
Application::instance().getStorageManager().getAllCertificates();
signals:
void certificateChanged(StorageId, StorageChange);
void keyChanged(StorageId, StorageChange);
void applicationCertificateChanged(StorageId, StorageChange);
void layoutChanged(StorageId, LayoutGroup, Domain, StorageChange);
void historicServerConnectionChanged(StorageId, StorageChange);
void kvChanged(QString, Domain, StorageChange);
enum class StorageChange {
Created,
Modified,
Deleted,
};
// example.hpp //
namespace magnesia::activities::dataviewer::panels::example {
class ExamplePanel : public Panel {
public:
explicit ExamplePanel(DataViewer*, QWidget* = nullptr);
[[nodiscard]] const PanelMetadata& metadata() const noexcept override;
};
inline constexpr PanelMetadata metadata{
.id = u"example",
.name = u"Example",
.create = create_helper<ExamplePanel>,
};
}
// example.cpp //
namespace magnesia::activities::dataviewer::panels::example {
ExamplePanel::ExamplePanel(DataViewer* dataviewer, QWidget* parent)
: Panel(dataviewer, Panels::example, parent) {
auto* layout = new QHBoxLayout;
layout->addWidget(new QLabel("Hello World!"));
setLayout(layout);
}
const PanelMetadata& ExamplePanel::metadata() const noexcept {
return example::metadata;
};
}
// register panel //
namespace magnesia::activities::dataviewer::panels {
inline constexpr std::array all{
// --snip--
example::metadata,
};
enum class Panels : unsigned {
// --snip--
example = 0x1 << 5,
};
}
namespace magnesia::activities::settings {
class SettingsUrlHandler: public URLHandler {
public:
explicit SettingsUrlHandler(Settings* activity);
bool handleURL(const QUrl& url) override;
private:
Settings* m_activity{nullptr};
};
}
Application::instance().getRouter().
route("settings:focus-domain?domain=general");