mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4503 Framework : Add support for passing text data to command features
This commit is contained in:
parent
512ecfdf74
commit
5067c6ce9c
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<QObject> 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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user