mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
AppFwk: Clean-up of table view after refactoring
This commit is contained in:
parent
88297bdb9f
commit
ba9f7720e6
@ -42,6 +42,8 @@
|
||||
#include "cafPdmUiTableViewEditor.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include "cafPdmUiCommandSystemProxy.h"
|
||||
#include <QTableView>
|
||||
|
||||
|
||||
namespace caf
|
||||
@ -62,13 +64,15 @@ PdmUiTableView::PdmUiTableView(QWidget* parent, Qt::WindowFlags f)
|
||||
|
||||
m_listViewEditor = new PdmUiTableViewEditor();
|
||||
|
||||
m_listViewEditor->createWidgets(this);
|
||||
|
||||
{
|
||||
QWidget* widget = m_listViewEditor->createLabelWidget(this);
|
||||
QWidget* widget = m_listViewEditor->labelWidget();
|
||||
layout->addWidget(widget);
|
||||
}
|
||||
|
||||
{
|
||||
QWidget* widget = m_listViewEditor->createEditorWidget(this);
|
||||
QWidget* widget = m_listViewEditor->editorWidget();
|
||||
layout->addWidget(widget);
|
||||
}
|
||||
}
|
||||
@ -90,7 +94,18 @@ void PdmUiTableView::setChildArrayField(PdmChildArrayFieldHandle* childArrayFiel
|
||||
|
||||
if (childArrayField)
|
||||
{
|
||||
// Keep the possible custom context menu setting from the user of the table view.
|
||||
// setUIField will set it based on the PdmUIItem settings, but turning the custom menu off should not
|
||||
// be respected when using the field in a separate view.
|
||||
auto orgContextPolicy = m_listViewEditor->tableView()->contextMenuPolicy();
|
||||
|
||||
m_listViewEditor->setUiField(childArrayField->uiCapability());
|
||||
|
||||
auto newContextPolicy = m_listViewEditor->tableView()->contextMenuPolicy();
|
||||
if (newContextPolicy == Qt::DefaultContextMenu)
|
||||
{
|
||||
m_listViewEditor->tableView()->setContextMenuPolicy(orgContextPolicy);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -142,22 +157,6 @@ void PdmUiTableView::setSelectionRole(SelectionManager::SelectionRole role)
|
||||
m_listViewEditor->setSelectionRole(role);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableView::handleModelNotification(caf::PdmObjectHandle* itemThatChanged)
|
||||
{
|
||||
// Nothing to do for now
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableView::handleModelSelectionChange()
|
||||
{
|
||||
m_listViewEditor->handleModelSelectionChange();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -166,6 +165,18 @@ PdmObjectHandle* PdmUiTableView::pdmObjectFromModelIndex(const QModelIndex& mi)
|
||||
return m_listViewEditor->pdmObjectFromModelIndex(mi);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableView::addActionsToMenu(QMenu* menu, PdmChildArrayFieldHandle* childArrayField)
|
||||
{
|
||||
// This is function is required to execute before populating the menu
|
||||
// Several commands rely on the activeChildArrayFieldHandle in the selection manager
|
||||
SelectionManager::instance()->setActiveChildArrayFieldHandle(childArrayField);
|
||||
|
||||
caf::PdmUiCommandSystemProxy::instance()->populateMenuWithDefaultCommands("PdmUiTreeViewEditor", menu);
|
||||
}
|
||||
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <QWidget>
|
||||
|
||||
class QTableView;
|
||||
class QMenu;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@ -58,27 +59,23 @@ class PdmChildArrayFieldHandle;
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class PdmUiTableView : public QWidget, public DataModelObserver
|
||||
class PdmUiTableView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PdmUiTableView(QWidget* parent = nullptr, Qt::WindowFlags f = nullptr);
|
||||
~PdmUiTableView();
|
||||
|
||||
PdmObjectHandle* pdmObjectFromModelIndex(const QModelIndex& mi);
|
||||
|
||||
// SIG_CAF_HACK
|
||||
void setUiConfigurationName(QString uiConfigName);
|
||||
|
||||
void setChildArrayField(PdmChildArrayFieldHandle* childArrayField);
|
||||
|
||||
void setUiConfigurationName(QString uiConfigName);
|
||||
void enableHeaderText(bool enable);
|
||||
void setSelectionRole(SelectionManager::SelectionRole role);
|
||||
|
||||
PdmObjectHandle* pdmObjectFromModelIndex(const QModelIndex& mi);
|
||||
|
||||
QTableView* tableView();
|
||||
|
||||
void handleModelNotification(caf::PdmObjectHandle* itemThatChanged) override;
|
||||
void handleModelSelectionChange() override;
|
||||
static void addActionsToMenu(QMenu* menu, PdmChildArrayFieldHandle* childArrayField);
|
||||
|
||||
private:
|
||||
PdmUiTableViewEditor* m_listViewEditor;
|
||||
|
@ -33,15 +33,12 @@
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cafPdmUiTableViewEditor.h"
|
||||
|
||||
#include "cafPdmChildArrayField.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiCheckBoxDelegate.h"
|
||||
#include "cafPdmUiCommandSystemProxy.h"
|
||||
#include "cafPdmUiEditorHandle.h"
|
||||
#include "cafPdmUiTableViewDelegate.h"
|
||||
#include "cafPdmUiTableViewQModel.h"
|
||||
@ -54,41 +51,11 @@
|
||||
#include <QTableView>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
class FocusEventHandler : public QObject
|
||||
{
|
||||
public:
|
||||
explicit FocusEventHandler(PdmUiTableViewEditor* tableViewEditor)
|
||||
: QObject(tableViewEditor)
|
||||
{
|
||||
m_tableViewEditor = tableViewEditor;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override
|
||||
{
|
||||
if (event->type() == QEvent::FocusIn ||
|
||||
event->type() == QEvent::FocusOut)
|
||||
{
|
||||
m_tableViewEditor->tableViewWidgetFocusChanged(event);
|
||||
}
|
||||
|
||||
// standard event processing
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
PdmUiTableViewEditor* m_tableViewEditor;
|
||||
};
|
||||
|
||||
CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiTableViewEditor);
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -108,7 +75,6 @@ PdmUiTableViewEditor::PdmUiTableViewEditor()
|
||||
m_isBlockingSelectionManagerChanged = false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -130,10 +96,6 @@ QWidget* PdmUiTableViewEditor::createEditorWidget(QWidget* parent)
|
||||
m_tableView->setModel(m_tableModelPdm);
|
||||
|
||||
connect(m_tableView->selectionModel(), SIGNAL(selectionChanged( const QItemSelection & , const QItemSelection & )), SLOT(slotSelectionChanged( const QItemSelection & , const QItemSelection & )));
|
||||
connect(m_tableView->selectionModel(), SIGNAL(currentChanged( const QModelIndex & , const QModelIndex & )), SLOT(slotCurrentChanged( const QModelIndex& , const QModelIndex& )));
|
||||
|
||||
FocusEventHandler* tableViewWidgetFocusEventHandler = new FocusEventHandler(this);
|
||||
m_tableView->installEventFilter(tableViewWidgetFocusEventHandler);
|
||||
|
||||
return m_tableView;
|
||||
}
|
||||
@ -214,16 +176,6 @@ void PdmUiTableViewEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableViewEditor::onSelectionManagerSelectionChanged()
|
||||
{
|
||||
if (m_isBlockingSelectionManagerChanged) return;
|
||||
|
||||
handleModelSelectionChange();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -269,29 +221,15 @@ void PdmUiTableViewEditor::setSelectionRole(SelectionManager::SelectionRole role
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableViewEditor::slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous)
|
||||
void PdmUiTableViewEditor::onSelectionManagerSelectionChanged()
|
||||
{
|
||||
//if (isSelectionRoleDefined())
|
||||
//{
|
||||
// std::vector<PdmUiItem*> items;
|
||||
// QModelIndexList list;
|
||||
// list.append(current);
|
||||
// selectedUiItems(list, items);
|
||||
//
|
||||
// SelectionManager::instance()->setSelectedItems(items, m_selectionRole);
|
||||
//}
|
||||
}
|
||||
if (m_isBlockingSelectionManagerChanged) return;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableViewEditor::handleModelSelectionChange()
|
||||
{
|
||||
if (isSelectionRoleDefined())
|
||||
{
|
||||
std::vector<PdmUiItem*> items;
|
||||
SelectionManager::instance()->selectedItems(items, m_selectionRole);
|
||||
#if 1
|
||||
|
||||
QItemSelection totalSelection;
|
||||
for (auto item: items)
|
||||
{
|
||||
@ -299,33 +237,11 @@ void PdmUiTableViewEditor::handleModelSelectionChange()
|
||||
QItemSelection itemSelection = m_tableModelPdm->modelIndexFromPdmObject(pdmObj);
|
||||
totalSelection.merge(itemSelection, QItemSelectionModel::Select);
|
||||
}
|
||||
|
||||
m_tableView->selectionModel()->select(totalSelection, QItemSelectionModel::SelectCurrent);
|
||||
#else
|
||||
// TODO: Handle multiple selection
|
||||
if (items.size() == 1)
|
||||
{
|
||||
PdmObject* pdmObj = dynamic_cast<PdmObject*>(items[0]);
|
||||
QItemSelection itemSelection = m_tableModelPdm->modelIndexFromPdmObject(pdmObj);
|
||||
if (!itemSelection.empty())
|
||||
{
|
||||
m_tableView->selectionModel()->select(itemSelection, QItemSelectionModel::SelectCurrent);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableViewEditor::addActionsToMenu(QMenu* menu, PdmChildArrayFieldHandle* childArrayField)
|
||||
{
|
||||
// This is function is required to execute before populating the menu
|
||||
// Several commands rely on the activeChildArrayFieldHandle in the selection manager
|
||||
SelectionManager::instance()->setActiveChildArrayFieldHandle(childArrayField);
|
||||
|
||||
caf::PdmUiCommandSystemProxy::instance()->populateMenuWithDefaultCommands("PdmUiTreeViewEditor", menu);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// NOTE: If no selection role is defined, the selection manager is not changed, the selection in the
|
||||
@ -357,33 +273,6 @@ PdmObjectHandle* PdmUiTableViewEditor::pdmObjectFromModelIndex(const QModelIndex
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableViewEditor::tableViewWidgetFocusChanged(QEvent* focusEvent)
|
||||
{
|
||||
if (m_delegate->isEditorOpen())
|
||||
{
|
||||
// The table view emits focus out when a table cell editor is active
|
||||
// Do not update the selection when this state occurs
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSelectionRoleDefined())
|
||||
{
|
||||
if (focusEvent->type() == QEvent::FocusIn)
|
||||
{
|
||||
//updateSelectionManagerFromTableSelection();
|
||||
}
|
||||
else if (focusEvent->type() == QEvent::FocusOut)
|
||||
{
|
||||
// Clearing the selection here causes the Menu to not display all items
|
||||
// Not sure how this can be handled correctly
|
||||
// SelectionManager::instance()->clear(m_selectionRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -391,27 +280,6 @@ void PdmUiTableViewEditor::updateSelectionManagerFromTableSelection()
|
||||
{
|
||||
if (isSelectionRoleDefined())
|
||||
{
|
||||
#if 0
|
||||
std::vector<PdmUiItem*> items;
|
||||
|
||||
QModelIndexList modelIndexList = m_tableView->selectionModel()->selectedIndexes();
|
||||
for (const QModelIndex& mi : modelIndexList)
|
||||
{
|
||||
PdmFieldHandle* pdmFieldHandle = m_tableModelPdm->getField(mi);
|
||||
|
||||
if (pdmFieldHandle && pdmFieldHandle->uiCapability())
|
||||
{
|
||||
items.push_back(pdmFieldHandle->uiCapability());
|
||||
}
|
||||
}
|
||||
|
||||
if (items.size() > 1)
|
||||
{
|
||||
// Selection of a single row is handled by slotCurrentChanged()
|
||||
// Multiple selection of fields is handled here
|
||||
SelectionManager::instance()->setSelectedItems(items, m_selectionRole);
|
||||
}
|
||||
#else
|
||||
std::set<PdmUiItem*> selectedRowObjects;
|
||||
QModelIndexList modelIndexList = m_tableView->selectionModel()->selectedIndexes();
|
||||
for (const QModelIndex& mi : modelIndexList)
|
||||
@ -424,13 +292,11 @@ void PdmUiTableViewEditor::updateSelectionManagerFromTableSelection()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<PdmUiItem*> items{selectedRowObjects.begin(), selectedRowObjects.end()};
|
||||
std::vector<PdmUiItem*> items { selectedRowObjects.begin(), selectedRowObjects.end() };
|
||||
|
||||
m_isBlockingSelectionManagerChanged = true;
|
||||
SelectionManager::instance()->setSelectedItems(items, m_selectionRole);
|
||||
m_isBlockingSelectionManagerChanged = false;
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,6 @@
|
||||
|
||||
class QItemSelection;
|
||||
class QLabel;
|
||||
class QMenu;
|
||||
class QTableView;
|
||||
|
||||
namespace caf
|
||||
@ -109,30 +108,24 @@ public:
|
||||
void setSelectionRole(SelectionManager::SelectionRole role);
|
||||
|
||||
PdmObjectHandle* pdmObjectFromModelIndex(const QModelIndex& mi);
|
||||
QTableView* tableView();
|
||||
|
||||
|
||||
QWidget* createEditorWidget(QWidget * parent) override;
|
||||
QWidget* createLabelWidget(QWidget * parent) override;
|
||||
|
||||
QTableView* tableView();
|
||||
|
||||
void handleModelSelectionChange();
|
||||
|
||||
static void addActionsToMenu(QMenu* menu, PdmChildArrayFieldHandle* childArrayField);
|
||||
|
||||
protected:
|
||||
virtual void configureAndUpdateUi(const QString& uiConfigName) override;
|
||||
|
||||
virtual void onSelectionManagerSelectionChanged() override;
|
||||
|
||||
private:
|
||||
void selectedUiItems(const QModelIndexList& modelIndexList, std::vector<PdmUiItem*>& objects);
|
||||
bool isSelectionRoleDefined() const;
|
||||
void tableViewWidgetFocusChanged(QEvent* focusEvent);
|
||||
void updateSelectionManagerFromTableSelection();
|
||||
|
||||
PdmChildArrayFieldHandle* childArrayFieldHandle();
|
||||
|
||||
private slots:
|
||||
void slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous);
|
||||
void slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user