#4503 Framework : Add support for passing text data to command features

This commit is contained in:
Magne Sjaastad 2019-06-23 15:02:45 +02:00
parent 512ecfdf74
commit 5067c6ce9c
2 changed files with 98 additions and 7 deletions

View File

@ -18,6 +18,8 @@
#include "RiaFeatureCommandContext.h" #include "RiaFeatureCommandContext.h"
#include <QVariant>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -44,6 +46,52 @@ QObject* RiaFeatureCommandContext::object() const
return m_pointerToQObject; 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); 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;
}
}

View File

@ -29,16 +29,21 @@ class RiaFeatureCommandContext
friend class RiaFeatureCommandContextHelper; friend class RiaFeatureCommandContextHelper;
public: public:
QObject* object() const;
static RiaFeatureCommandContext* instance(); 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: private:
RiaFeatureCommandContext(); RiaFeatureCommandContext();
~RiaFeatureCommandContext(); ~RiaFeatureCommandContext();
void setObject(QObject* object);
private: private:
QPointer<QObject> m_pointerToQObject; QPointer<QObject> m_pointerToQObject;
}; };
@ -49,6 +54,19 @@ private:
class RiaFeatureCommandContextHelper class RiaFeatureCommandContextHelper
{ {
public: public:
RiaFeatureCommandContextHelper(QObject* object); RiaFeatureCommandContextHelper(QObject* externalObject);
~RiaFeatureCommandContextHelper(); ~RiaFeatureCommandContextHelper();
}; };
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaFeatureCommandContextTextHelper
{
public:
RiaFeatureCommandContextTextHelper(const QString& title, const QString& text);
~RiaFeatureCommandContextTextHelper();
private:
QObject* m_object;
};