mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1875 Custom Object Editor : Add test object with many top level groups
This commit is contained in:
parent
59e818f2b8
commit
443e5625a6
@ -13,6 +13,7 @@ option(USE_COMMAND_FRAMEWORK "Use Caf Command Framework" ON)
|
||||
set ( QT_MOC_HEADERS
|
||||
MainWindow.h
|
||||
WidgetLayoutTest.h
|
||||
ManyGroups.h
|
||||
)
|
||||
|
||||
qt4_wrap_cpp( MOC_FILES_CPP
|
||||
@ -52,6 +53,7 @@ set( PROJECT_FILES
|
||||
Main.cpp
|
||||
MainWindow.cpp
|
||||
WidgetLayoutTest.cpp
|
||||
ManyGroups.cpp
|
||||
)
|
||||
|
||||
|
||||
|
159
Fwk/AppFwk/cafTests/cafTestApplication/ManyGroups.cpp
Normal file
159
Fwk/AppFwk/cafTests/cafTestApplication/ManyGroups.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
|
||||
#include "ManyGroups.h"
|
||||
#include "cafPdmUiTreeSelectionEditor.h"
|
||||
|
||||
CAF_PDM_SOURCE_INIT(ManyGroups, "LargeObject");
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
ManyGroups::ManyGroups()
|
||||
{
|
||||
CAF_PDM_InitObject("Many Groups", ":/images/win/filenew.png", "This object is a demo of the CAF framework", "This object is a demo of the CAF framework");
|
||||
|
||||
CAF_PDM_InitField(&m_toggleField, "Toggle", false, "Add Items To Multi Select", "", "Toggle Field tooltip", " Toggle Field whatsthis");
|
||||
CAF_PDM_InitField(&m_doubleField, "BigNumber", 0.0, "Big Number", "", "Enter a big number here", "This is a place you can enter a big real value if you want");
|
||||
CAF_PDM_InitField(&m_intField, "IntNumber", 0, "Small Number", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
|
||||
CAF_PDM_InitField(&m_textField, "TextField", QString(""), "Text", "", "Text tooltip", "This is a place you can enter a small integer value if you want");
|
||||
|
||||
m_proxyDoubleField.registerSetMethod(this, &ManyGroups::setDoubleMember);
|
||||
m_proxyDoubleField.registerGetMethod(this, &ManyGroups::doubleMember);
|
||||
CAF_PDM_InitFieldNoDefault(&m_proxyDoubleField, "ProxyDouble", "Proxy Double", "", "", "");
|
||||
|
||||
m_proxyDoubleField = 0;
|
||||
if (!(m_proxyDoubleField == 3)) { std::cout << "Double is not 3 " << std::endl; }
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_multiSelectList, "SelectedItems", "Multi Select Field", "", "", "");
|
||||
m_multiSelectList.xmlCapability()->setIOReadable(false);
|
||||
m_multiSelectList.xmlCapability()->setIOWritable(false);
|
||||
m_multiSelectList.uiCapability()->setUiEditorTypeName(caf::PdmUiTreeSelectionEditor::uiEditorTypeName());
|
||||
|
||||
m_multiSelectList.v().push_back("First");
|
||||
m_multiSelectList.v().push_back("Second");
|
||||
m_multiSelectList.v().push_back("Third");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmFieldHandle* ManyGroups::objectToggleField()
|
||||
{
|
||||
return &m_toggleField;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void ManyGroups::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
|
||||
{
|
||||
if (changedField == &m_toggleField)
|
||||
{
|
||||
std::cout << "Toggle Field changed" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<caf::PdmOptionItemInfo> ManyGroups::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly)
|
||||
{
|
||||
QList<caf::PdmOptionItemInfo> options;
|
||||
|
||||
if (fieldNeedingOptions == &m_multiSelectList)
|
||||
{
|
||||
QString text;
|
||||
|
||||
text = "First";
|
||||
options.push_back(caf::PdmOptionItemInfo(text, text));
|
||||
|
||||
text = "Second";
|
||||
options.push_back(caf::PdmOptionItemInfo::createHeader(text, false, QIcon(QString(":/images/win/textbold.png"))));
|
||||
|
||||
{
|
||||
text = "Second_a";
|
||||
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text, true);
|
||||
itemInfo.setLevel(1);
|
||||
options.push_back(itemInfo);
|
||||
}
|
||||
|
||||
{
|
||||
text = "Second_b";
|
||||
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text, false, QIcon(QString(":/images/win/filenew.png")));
|
||||
itemInfo.setLevel(1);
|
||||
options.push_back(itemInfo);
|
||||
}
|
||||
|
||||
int additionalSubItems = 2;
|
||||
for (auto i = 0; i < additionalSubItems; i++)
|
||||
{
|
||||
text = "Second_b_" + QString::number(i);
|
||||
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text);
|
||||
itemInfo.setLevel(1);
|
||||
options.push_back(itemInfo);
|
||||
}
|
||||
|
||||
static int s_additionalSubItems = 0;
|
||||
if (m_toggleField())
|
||||
{
|
||||
s_additionalSubItems++;
|
||||
}
|
||||
for (auto i = 0; i < s_additionalSubItems; i++)
|
||||
{
|
||||
text = "Second_b_" + QString::number(i);
|
||||
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text);
|
||||
itemInfo.setLevel(1);
|
||||
options.push_back(itemInfo);
|
||||
}
|
||||
|
||||
text = "Third";
|
||||
options.push_back(caf::PdmOptionItemInfo(text, text));
|
||||
|
||||
text = "Fourth";
|
||||
options.push_back(caf::PdmOptionItemInfo(text, text));
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void ManyGroups::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
||||
{
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup("First");
|
||||
|
||||
caf::PdmUiGroup* subGroup = group->addNewGroup("First_Content");
|
||||
|
||||
subGroup->add(&m_doubleField);
|
||||
subGroup->add(&m_intField);
|
||||
|
||||
caf::PdmUiGroup* subGroup2 = group->addNewGroup("First_Content_2");
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup("Second");
|
||||
caf::PdmUiGroup* subGroup = group->addNewGroup("Second_Content");
|
||||
}
|
||||
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup("Third");
|
||||
caf::PdmUiGroup* subGroup = group->addNewGroup("Third_Content");
|
||||
}
|
||||
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup("Fourth");
|
||||
caf::PdmUiGroup* subGroup = group->addNewGroup("Fourth_Content");
|
||||
|
||||
subGroup->add(&m_textField);
|
||||
}
|
||||
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup("Fifth");
|
||||
caf::PdmUiGroup* subGroup = group->addNewGroup("Fifth_Content");
|
||||
|
||||
subGroup->add(&m_proxyDoubleField);
|
||||
}
|
||||
}
|
44
Fwk/AppFwk/cafTests/cafTestApplication/ManyGroups.h
Normal file
44
Fwk/AppFwk/cafTests/cafTestApplication/ManyGroups.h
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmProxyValueField.h"
|
||||
|
||||
|
||||
class ManyGroups : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
public:
|
||||
|
||||
ManyGroups();
|
||||
|
||||
caf::PdmField<double> m_doubleField;
|
||||
caf::PdmField<int> m_intField;
|
||||
caf::PdmField<QString> m_textField;
|
||||
caf::PdmProxyValueField<double> m_proxyDoubleField;
|
||||
|
||||
caf::PdmField<std::vector<QString> > m_multiSelectList;
|
||||
|
||||
caf::PdmField<bool> m_toggleField;
|
||||
virtual caf::PdmFieldHandle* objectToggleField();
|
||||
|
||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
||||
|
||||
void setDoubleMember(const double& d) { m_doubleMember = d; std::cout << "setDoubleMember" << std::endl; }
|
||||
double doubleMember() const { std::cout << "doubleMember" << std::endl; return m_doubleMember; }
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override;
|
||||
|
||||
private:
|
||||
double m_doubleMember;
|
||||
|
||||
protected:
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user