From 5067c6ce9c5dc25be54cf9e7e822487bdb9d41e9 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sun, 23 Jun 2019 15:02:45 +0200 Subject: [PATCH] #4503 Framework : Add support for passing text data to command features --- .../Application/RiaFeatureCommandContext.cpp | 77 ++++++++++++++++++- .../Application/RiaFeatureCommandContext.h | 28 +++++-- 2 files changed, 98 insertions(+), 7 deletions(-) diff --git a/ApplicationCode/Application/RiaFeatureCommandContext.cpp b/ApplicationCode/Application/RiaFeatureCommandContext.cpp index d671195dca..7337bbaad9 100644 --- a/ApplicationCode/Application/RiaFeatureCommandContext.cpp +++ b/ApplicationCode/Application/RiaFeatureCommandContext.cpp @@ -18,6 +18,8 @@ #include "RiaFeatureCommandContext.h" +#include + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -44,6 +46,52 @@ QObject* RiaFeatureCommandContext::object() const return m_pointerToQObject; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiaFeatureCommandContext::titleString() const +{ + if (m_pointerToQObject) + { + QVariant variant = m_pointerToQObject->property(titleStringIdentifier().data()); + + return variant.toString(); + } + + return QString(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiaFeatureCommandContext::contentString() const +{ + if (m_pointerToQObject) + { + QVariant variant = m_pointerToQObject->property(contentStringIdentifier().data()); + + return variant.toString(); + } + + return QString(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::string RiaFeatureCommandContext::titleStringIdentifier() +{ + return "titleStringIdentifier"; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::string RiaFeatureCommandContext::contentStringIdentifier() +{ + return "contentStringIdentifier"; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -56,9 +104,9 @@ RiaFeatureCommandContext* RiaFeatureCommandContext::instance() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiaFeatureCommandContextHelper::RiaFeatureCommandContextHelper(QObject* object) +RiaFeatureCommandContextHelper::RiaFeatureCommandContextHelper(QObject* externalObject) { - RiaFeatureCommandContext::instance()->setObject(object); + RiaFeatureCommandContext::instance()->setObject(externalObject); } //-------------------------------------------------------------------------------------------------- @@ -68,3 +116,28 @@ RiaFeatureCommandContextHelper::~RiaFeatureCommandContextHelper() { RiaFeatureCommandContext::instance()->setObject(nullptr); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaFeatureCommandContextTextHelper::RiaFeatureCommandContextTextHelper(const QString& title, const QString& text) +{ + m_object = new QObject; + + m_object->setProperty(RiaFeatureCommandContext::titleStringIdentifier().data(), title); + m_object->setProperty(RiaFeatureCommandContext::contentStringIdentifier().data(), text); + + RiaFeatureCommandContext::instance()->setObject(m_object); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaFeatureCommandContextTextHelper::~RiaFeatureCommandContextTextHelper() +{ + if (m_object) + { + m_object->deleteLater(); + m_object = nullptr; + } +} diff --git a/ApplicationCode/Application/RiaFeatureCommandContext.h b/ApplicationCode/Application/RiaFeatureCommandContext.h index 9ac89ddb4d..3c31ebd4be 100644 --- a/ApplicationCode/Application/RiaFeatureCommandContext.h +++ b/ApplicationCode/Application/RiaFeatureCommandContext.h @@ -29,16 +29,21 @@ class RiaFeatureCommandContext friend class RiaFeatureCommandContextHelper; public: - QObject* object() const; - static RiaFeatureCommandContext* instance(); + QObject* object() const; + void setObject(QObject* object); + + QString titleString() const; + QString contentString() const; + + static std::string titleStringIdentifier(); + static std::string contentStringIdentifier(); + private: RiaFeatureCommandContext(); ~RiaFeatureCommandContext(); - void setObject(QObject* object); - private: QPointer m_pointerToQObject; }; @@ -49,6 +54,19 @@ private: class RiaFeatureCommandContextHelper { public: - RiaFeatureCommandContextHelper(QObject* object); + RiaFeatureCommandContextHelper(QObject* externalObject); ~RiaFeatureCommandContextHelper(); }; + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class RiaFeatureCommandContextTextHelper +{ +public: + RiaFeatureCommandContextTextHelper(const QString& title, const QString& text); + ~RiaFeatureCommandContextTextHelper(); + +private: + QObject* m_object; +};