mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3285 Make context menu on table views work correctly with multiple contexts.
This commit is contained in:
@@ -153,9 +153,17 @@ void PdmUiTableView::enableHeaderText(bool enable)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableView::setSelectionLevel(int selectionLevel)
|
||||
void PdmUiTableView::setTableSelectionLevel(int selectionLevel)
|
||||
{
|
||||
m_listViewEditor->setSelectionLevel(selectionLevel);
|
||||
m_listViewEditor->setTableSelectionLevel(selectionLevel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableView::setRowSelectionLevel(int selectionLevel)
|
||||
{
|
||||
m_listViewEditor->setRowSelectionLevel(selectionLevel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -68,7 +68,8 @@ public:
|
||||
void setChildArrayField(PdmChildArrayFieldHandle* childArrayField);
|
||||
void setUiConfigurationName(QString uiConfigName);
|
||||
void enableHeaderText(bool enable);
|
||||
void setSelectionLevel(int selectionLevel);
|
||||
void setTableSelectionLevel(int selectionLevel);
|
||||
void setRowSelectionLevel(int selectionLevel);
|
||||
|
||||
PdmObjectHandle* pdmObjectFromModelIndex(const QModelIndex& mi);
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ PdmUiTableViewEditor::PdmUiTableViewEditor()
|
||||
|
||||
m_checkboxDelegate = new PdmUiCheckBoxDelegate(this);
|
||||
|
||||
m_selectionLevel = SelectionManager::FIRST_LEVEL;
|
||||
m_tableSelectionLevel = SelectionManager::BASE_LEVEL;
|
||||
m_rowSelectionLevel = SelectionManager::FIRST_LEVEL;
|
||||
m_isBlockingSelectionManagerChanged = false;
|
||||
}
|
||||
|
||||
@@ -96,6 +97,7 @@ QWidget* PdmUiTableViewEditor::createEditorWidget(QWidget* parent)
|
||||
m_tableView = new QTableView(parent);
|
||||
m_tableView->setShowGrid(true);
|
||||
m_tableView->setModel(m_tableModelPdm);
|
||||
m_tableView->installEventFilter(this);
|
||||
|
||||
connect(m_tableView->selectionModel(), SIGNAL(selectionChanged( const QItemSelection & , const QItemSelection & )), SLOT(slotSelectionChanged( const QItemSelection & , const QItemSelection & )));
|
||||
|
||||
@@ -147,7 +149,8 @@ void PdmUiTableViewEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
childArrayFH->ownerObject()->uiCapability()->editorAttribute(childArrayFH, uiConfigName, &editorAttrib);
|
||||
editorAttribLoaded = true;
|
||||
|
||||
this->setSelectionLevel(editorAttrib.selectionLevel);
|
||||
this->setTableSelectionLevel(editorAttrib.tableSelectionLevel);
|
||||
this->setRowSelectionLevel(editorAttrib.rowSelectionLevel);
|
||||
this->enableHeaderText(editorAttrib.enableHeaderText);
|
||||
|
||||
QPalette myPalette(m_tableView->palette());
|
||||
@@ -263,9 +266,17 @@ void PdmUiTableViewEditor::enableHeaderText(bool enable)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableViewEditor::setSelectionLevel(int selectionLevel)
|
||||
void PdmUiTableViewEditor::setTableSelectionLevel(int selectionLevel)
|
||||
{
|
||||
m_selectionLevel = selectionLevel;
|
||||
m_tableSelectionLevel = selectionLevel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTableViewEditor::setRowSelectionLevel(int selectionLevel)
|
||||
{
|
||||
m_rowSelectionLevel = selectionLevel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -275,10 +286,10 @@ void PdmUiTableViewEditor::onSelectionManagerSelectionChanged(int selectionLevel
|
||||
{
|
||||
if (m_isBlockingSelectionManagerChanged) return;
|
||||
|
||||
if (isSelectionRoleDefined() && (m_selectionLevel == selectionLevel))
|
||||
if (isSelectionRoleDefined() && (m_rowSelectionLevel == selectionLevel))
|
||||
{
|
||||
std::vector<PdmUiItem*> items;
|
||||
SelectionManager::instance()->selectedItems(items, m_selectionLevel);
|
||||
SelectionManager::instance()->selectedItems(items, m_rowSelectionLevel);
|
||||
|
||||
QItemSelection totalSelection;
|
||||
for (auto item: items)
|
||||
@@ -307,7 +318,7 @@ void PdmUiTableViewEditor::slotSelectionChanged(const QItemSelection & selected,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiTableViewEditor::isSelectionRoleDefined() const
|
||||
{
|
||||
return m_selectionLevel != SelectionManager::UNDEFINED;
|
||||
return m_rowSelectionLevel != SelectionManager::UNDEFINED;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -344,20 +355,29 @@ void PdmUiTableViewEditor::updateSelectionManagerFromTableSelection()
|
||||
|
||||
std::vector<PdmUiItem*> items { selectedRowObjects.begin(), selectedRowObjects.end() };
|
||||
|
||||
if (items.empty() && childArrayFieldHandle() && childArrayFieldHandle()->ownerObject())
|
||||
{
|
||||
// If no rows are selected, add the owner object to the selection.
|
||||
// This enables features to retrieve the owner object to add of new objects into
|
||||
// an empty table or table without selection
|
||||
items.push_back(childArrayFieldHandle()->ownerObject()->uiCapability());
|
||||
}
|
||||
|
||||
m_isBlockingSelectionManagerChanged = true;
|
||||
SelectionManager::instance()->setSelectedItems(items, m_selectionLevel);
|
||||
if (childArrayFieldHandle() && childArrayFieldHandle()->ownerObject())
|
||||
{
|
||||
SelectionManager::instance()->setSelectedItem(childArrayFieldHandle()->ownerObject()->uiCapability(), m_tableSelectionLevel);
|
||||
}
|
||||
SelectionManager::instance()->setSelectedItems(items, m_rowSelectionLevel);
|
||||
m_isBlockingSelectionManagerChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiTableViewEditor::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::FocusIn)
|
||||
{
|
||||
this->updateSelectionManagerFromTableSelection();
|
||||
}
|
||||
// standard event processing
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -82,7 +82,8 @@ class PdmUiTableViewEditorAttribute : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
PdmUiTableViewEditorAttribute()
|
||||
: selectionLevel(1)
|
||||
: tableSelectionLevel(0)
|
||||
, rowSelectionLevel(1)
|
||||
, enableHeaderText(true)
|
||||
, minimumHeight(-1)
|
||||
, forceColumnWidthResize(false)
|
||||
@@ -92,6 +93,8 @@ public:
|
||||
}
|
||||
|
||||
int selectionLevel;
|
||||
int tableSelectionLevel;
|
||||
int rowSelectionLevel;
|
||||
bool enableHeaderText;
|
||||
std::vector<int> columnWidths;
|
||||
int minimumHeight; ///< Not used if If < 0
|
||||
@@ -114,7 +117,8 @@ public:
|
||||
~PdmUiTableViewEditor();
|
||||
|
||||
void enableHeaderText(bool enable);
|
||||
void setSelectionLevel(int selectionLevel);
|
||||
void setTableSelectionLevel(int selectionLevel);
|
||||
void setRowSelectionLevel(int selectionLevel);
|
||||
|
||||
PdmObjectHandle* pdmObjectFromModelIndex(const QModelIndex& mi);
|
||||
QTableView* tableView();
|
||||
@@ -131,6 +135,7 @@ private:
|
||||
bool isSelectionRoleDefined() const;
|
||||
void updateSelectionManagerFromTableSelection();
|
||||
|
||||
bool eventFilter(QObject* obj, QEvent* event);
|
||||
PdmChildArrayFieldHandle* childArrayFieldHandle();
|
||||
|
||||
private slots:
|
||||
@@ -149,7 +154,8 @@ private:
|
||||
PdmUiCheckBoxDelegate* m_checkboxDelegate;
|
||||
|
||||
bool m_useDefaultContextMenu;
|
||||
int m_selectionLevel;
|
||||
int m_tableSelectionLevel;
|
||||
int m_rowSelectionLevel;
|
||||
bool m_isBlockingSelectionManagerChanged;
|
||||
|
||||
caf::PdmChildArrayFieldHandle* m_previousFieldHandle;
|
||||
|
||||
Reference in New Issue
Block a user