mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-21 22:13:25 -06:00
AppFwk : Add support for push buttons in table editor
This commit is contained in:
parent
a33a2411ef
commit
9dd730f8f6
@ -35,6 +35,7 @@
|
||||
#include "cafPdmUiTreeView.h"
|
||||
#include "cafSelectionManager.h"
|
||||
#include "cafPdmUiTreeSelectionEditor.h"
|
||||
#include "cafPdmUiPushButtonEditor.h"
|
||||
|
||||
|
||||
|
||||
@ -213,6 +214,7 @@ public:
|
||||
CAF_PDM_InitObject("Small Demo Object A", "", "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, "Toggle Field", "", "Toggle Field tooltip", " Toggle Field whatsthis");
|
||||
CAF_PDM_InitField(&m_pushButtonField, "Push", false, "Button Field", "", "", " ");
|
||||
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("Small Demo Object A"), "Name Text Field", "", "", "");
|
||||
@ -249,6 +251,8 @@ public:
|
||||
caf::PdmField< caf::AppEnum<TestEnumType> > m_highlightedEnum;
|
||||
|
||||
caf::PdmField<bool> m_toggleField;
|
||||
caf::PdmField<bool> m_pushButtonField;
|
||||
|
||||
virtual caf::PdmFieldHandle* objectToggleField()
|
||||
{
|
||||
return &m_toggleField;
|
||||
@ -264,6 +268,10 @@ public:
|
||||
{
|
||||
std::cout << "Highlight value " << m_highlightedEnum() << std::endl;
|
||||
}
|
||||
else if (changedField == &m_pushButtonField)
|
||||
{
|
||||
std::cout << "Push Button pressed " << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly)
|
||||
@ -335,6 +343,18 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
virtual void defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override
|
||||
{
|
||||
caf::PdmUiTableViewEditorAttribute* attr = dynamic_cast<caf::PdmUiTableViewEditorAttribute*>(attribute);
|
||||
if (attr)
|
||||
{
|
||||
attr->registerPushButtonTextForFieldKeyword(m_pushButtonField.keyword(), "Edit");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CAF_PDM_SOURCE_INIT(SmallDemoPdmObjectA, "SmallDemoPdmObjectA");
|
||||
|
@ -160,5 +160,36 @@ PdmObjectHandle* PdmUiTableView::pdmObjectFromModelIndex(const QModelIndex& mi)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableViewEditorAttribute::registerPushButtonTextForFieldKeyword(const QString& keyword, const QString& text)
|
||||
{
|
||||
m_fieldKeywordAndPushButtonText[keyword] = text;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiTableViewEditorAttribute::showPushButtonForFieldKeyword(const QString& keyword) const
|
||||
{
|
||||
if (m_fieldKeywordAndPushButtonText.count(keyword) > 0) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString PdmUiTableViewEditorAttribute::pushButtonText(const QString& keyword) const
|
||||
{
|
||||
if (showPushButtonForFieldKeyword(keyword))
|
||||
{
|
||||
return m_fieldKeywordAndPushButtonText.at(keyword);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "cafNotificationCenter.h"
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QModelIndex>
|
||||
@ -53,6 +54,21 @@ class PdmObjectHandle;
|
||||
class PdmUiTableViewEditor;
|
||||
class PdmChildArrayFieldHandle;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class PdmUiTableViewEditorAttribute : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
void registerPushButtonTextForFieldKeyword(const QString& keyword, const QString& text);
|
||||
|
||||
bool showPushButtonForFieldKeyword(const QString& keyword) const;
|
||||
QString pushButtonText(const QString& keyword) const;
|
||||
|
||||
private:
|
||||
std::map<QString, QString> m_fieldKeywordAndPushButtonText;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
|
@ -183,6 +183,8 @@ void PdmUiTableViewEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
QString text = "";
|
||||
m_tableHeadingIcon->setPixmap(m_pdmListField->uiCapability()->uiIcon(uiConfigName).pixmap(16, 16));
|
||||
m_tableHeading->setText(m_pdmListField->uiCapability()->uiName(uiConfigName) + QString(" (%1)").arg(m_pdmListField->size()));
|
||||
|
||||
m_tableModelPdm->createPersistentPushButtonWidgets(m_tableView);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -85,6 +85,8 @@ public:
|
||||
QTableView* tableView();
|
||||
|
||||
void handleModelSelectionChange();
|
||||
void updatePersistentEditors() const;
|
||||
|
||||
protected:
|
||||
virtual void configureAndUpdateUi(const QString& uiConfigName);
|
||||
|
||||
|
@ -45,8 +45,13 @@
|
||||
#include "cafPdmUiFieldEditorHelper.h"
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
#include "cafPdmUiTableItemEditor.h"
|
||||
#include "cafPdmUiTableView.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QTableView>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@ -328,31 +333,20 @@ void PdmUiTableViewModel::setPdmData(PdmChildArrayFieldHandle* listField, const
|
||||
m_pdmList = listField;
|
||||
m_currentConfigName = configName;
|
||||
|
||||
PdmUiOrdering configForFirstRow;
|
||||
PdmUiOrdering configForFirstObject;
|
||||
|
||||
if (m_pdmList)
|
||||
if (m_pdmList && m_pdmList->size() > 0)
|
||||
{
|
||||
PdmUiOrdering dummy;
|
||||
|
||||
for (size_t i = 0; i < listField->size(); i++)
|
||||
PdmObjectHandle* pdmObjHandle = m_pdmList->at(0);
|
||||
PdmUiObjectHandle* uiObject = pdmObjHandle->uiCapability();
|
||||
if (uiObject)
|
||||
{
|
||||
PdmObjectHandle* pdmObjHandle = m_pdmList->at(i);
|
||||
PdmUiObjectHandle* uiObject = uiObj(pdmObjHandle);
|
||||
if (uiObject)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
uiObject->uiOrdering(configName, configForFirstRow);
|
||||
}
|
||||
else
|
||||
{
|
||||
uiObject->uiOrdering(configName, dummy);
|
||||
}
|
||||
}
|
||||
uiObject->uiOrdering(configName, configForFirstObject);
|
||||
uiObject->objectEditorAttribute(m_currentConfigName, &m_attributes);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<PdmUiItem*>& uiItems = configForFirstRow.uiItems();
|
||||
const std::vector<PdmUiItem*>& uiItems = configForFirstObject.uiItems();
|
||||
|
||||
// Set all fieldViews to be unvisited
|
||||
std::map<QString, PdmUiFieldEditorHandle*>::iterator it;
|
||||
@ -558,9 +552,15 @@ PdmObjectHandle* PdmUiTableViewModel::pdmObjectForRow(int row) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiTableViewModel::isRepresentingBoolean(const QModelIndex &index) const
|
||||
{
|
||||
if (getField(index))
|
||||
PdmFieldHandle* fieldHandle = getField(index);
|
||||
if (fieldHandle)
|
||||
{
|
||||
QVariant val = getField(index)->uiCapability()->uiValue();
|
||||
if (m_attributes.showPushButtonForFieldKeyword(fieldHandle->keyword()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant val = fieldHandle->uiCapability()->uiValue();
|
||||
if (val.type() == QVariant::Bool)
|
||||
{
|
||||
return true;
|
||||
@ -570,6 +570,30 @@ bool PdmUiTableViewModel::isRepresentingBoolean(const QModelIndex &index) const
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableViewModel::createPersistentPushButtonWidgets(QTableView* tableView)
|
||||
{
|
||||
if (rowCount() > 0)
|
||||
{
|
||||
for (int col = 0; col < columnCount(); col++)
|
||||
{
|
||||
PdmFieldHandle* fieldHandle = getField(createIndex(0, col));
|
||||
if (m_attributes.showPushButtonForFieldKeyword(fieldHandle->keyword()))
|
||||
{
|
||||
for (int row = 0; row < rowCount(); row++)
|
||||
{
|
||||
QModelIndex mi = createIndex(row, col);
|
||||
|
||||
tableView->setIndexWidget(mi, new TableViewPushButton(getField(mi)->uiCapability(), m_attributes.pushButtonText(fieldHandle->keyword())));
|
||||
tableView->openPersistentEditor(mi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -618,4 +642,30 @@ int PdmUiTableViewModel::getFieldIndex(PdmFieldHandle* field) const
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TableViewPushButton::TableViewPushButton(caf::PdmUiFieldHandle* field, const QString& text, QWidget* parent /*= 0*/)
|
||||
: QPushButton(text, parent),
|
||||
m_fieldHandle(field)
|
||||
{
|
||||
connect(this, SIGNAL(pressed()), SLOT(slotPressed()));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void TableViewPushButton::slotPressed()
|
||||
{
|
||||
if (m_fieldHandle)
|
||||
{
|
||||
QVariant val = m_fieldHandle->uiValue();
|
||||
if (val.type() == QVariant::Bool)
|
||||
{
|
||||
bool currentValue = val.toBool();
|
||||
caf::PdmUiCommandSystemProxy::instance()->setUiValueToField(m_fieldHandle, !currentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace caf
|
||||
|
@ -38,8 +38,12 @@
|
||||
|
||||
#include "cafPdmUiTreeOrdering.h"
|
||||
|
||||
#include "cafPdmUiFieldHandle.h"
|
||||
#include "cafPdmUiTableView.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QItemSelection>
|
||||
#include <QPushButton>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@ -52,6 +56,21 @@ class PdmUiTableItemEditor;
|
||||
class PdmUiTreeOrdering;
|
||||
class PdmUiTreeViewEditor;
|
||||
|
||||
|
||||
class TableViewPushButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TableViewPushButton(caf::PdmUiFieldHandle* field, const QString& text, QWidget* parent = 0);
|
||||
|
||||
private slots:
|
||||
void slotPressed();
|
||||
|
||||
private:
|
||||
caf::PdmUiFieldHandle* m_fieldHandle;
|
||||
};
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@ -80,12 +99,12 @@ public:
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
|
||||
void selectedUiItems(std::vector<PdmUiItem*>& objects);
|
||||
|
||||
void notifyDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||
|
||||
bool isRepresentingBoolean(const QModelIndex &index) const;
|
||||
|
||||
void createPersistentPushButtonWidgets(QTableView* tableView);
|
||||
|
||||
private:
|
||||
int getFieldIndex(PdmFieldHandle* field) const;
|
||||
void recreateTableItemEditors();
|
||||
@ -102,6 +121,8 @@ private:
|
||||
std::vector<int> m_modelColumnIndexToFieldIndex;
|
||||
|
||||
std::vector<PdmUiTableItemEditor*> m_tableItemEditors;
|
||||
|
||||
PdmUiTableViewEditorAttribute m_attributes;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user