#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 <QVariant>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -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;
}
}