mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-03 12:10:57 -06:00
Toggle on/off multiple selection using keyboard (space, enter, return)
p4#: 21327
This commit is contained in:
parent
2280a8cbfa
commit
5a79a41da8
@ -976,28 +976,46 @@ void RimUiTreeView::keyPressEvent(QKeyEvent* keyEvent)
|
||||
{
|
||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex());
|
||||
|
||||
if (dynamic_cast<RimCase*>(uiItem->dataObject().p()))
|
||||
if (uiItem)
|
||||
{
|
||||
if (keyEvent->matches(QKeySequence::Copy))
|
||||
if (dynamic_cast<RimCase*>(uiItem->dataObject().p()))
|
||||
{
|
||||
slotCopyPdmObjectToClipboard();
|
||||
keyEvent->setAccepted(true);
|
||||
if (keyEvent->matches(QKeySequence::Copy))
|
||||
{
|
||||
slotCopyPdmObjectToClipboard();
|
||||
keyEvent->setAccepted(true);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (dynamic_cast<RimIdenticalGridCaseGroup*>(uiItem->dataObject().p())
|
||||
|| dynamic_cast<RimCaseCollection*>(uiItem->dataObject().p())
|
||||
|| dynamic_cast<RimCase*>(uiItem->dataObject().p()))
|
||||
{
|
||||
if (keyEvent->matches(QKeySequence::Paste))
|
||||
{
|
||||
slotPastePdmObjects();
|
||||
keyEvent->setAccepted(true);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dynamic_cast<RimIdenticalGridCaseGroup*>(uiItem->dataObject().p())
|
||||
|| dynamic_cast<RimCaseCollection*>(uiItem->dataObject().p())
|
||||
|| dynamic_cast<RimCase*>(uiItem->dataObject().p()))
|
||||
switch (keyEvent->key())
|
||||
{
|
||||
if (keyEvent->matches(QKeySequence::Paste))
|
||||
case Qt::Key_Space:
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Select:
|
||||
{
|
||||
slotPastePdmObjects();
|
||||
keyEvent->setAccepted(true);
|
||||
if (checkAndHandleToggleOfMultipleSelection())
|
||||
{
|
||||
keyEvent->setAccepted(true);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1144,3 +1162,63 @@ bool RimUiTreeView::hasAnyStatisticsResults(RimIdenticalGridCaseGroup* gridCaseG
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeView::mousePressEvent(QMouseEvent* mouseEvent)
|
||||
{
|
||||
// TODO: Handle multiple selection and changing state using mouse
|
||||
// This is a bit tricky due to the fact that there is no obvious way to trap if the check box is pressed
|
||||
// and not other parts of the check box GUI item
|
||||
|
||||
/*
|
||||
if (checkAndHandleToggleOfMultipleSelection())
|
||||
{
|
||||
mouseEvent->setAccepted(true);
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
QTreeView::mousePressEvent(mouseEvent);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimUiTreeView::checkAndHandleToggleOfMultipleSelection()
|
||||
{
|
||||
QModelIndex curr = currentIndex();
|
||||
|
||||
// Check if the current model index supports checkable items
|
||||
if (model()->flags(curr) & Qt::ItemIsUserCheckable)
|
||||
{
|
||||
QModelIndexList selectedIndexes = selectionModel()->selectedIndexes();
|
||||
if (selectedIndexes.contains(curr))
|
||||
{
|
||||
QVariant currentState = model()->data(curr, Qt::CheckStateRole);
|
||||
|
||||
// Toggle between Qt::Checked and Qt::UnChecked
|
||||
// Qt::PartiallyChecked is not handled
|
||||
int state = currentState.toInt();
|
||||
if (state == Qt::Checked)
|
||||
{
|
||||
state = Qt::Unchecked;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = Qt::Checked;
|
||||
}
|
||||
|
||||
foreach (QModelIndex mi, selectedIndexes)
|
||||
{
|
||||
model()->setData(mi, state, Qt::CheckStateRole);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,13 @@ private:
|
||||
bool hasClipboardValidData();
|
||||
|
||||
virtual void keyPressEvent(QKeyEvent* keyEvent);
|
||||
virtual void mousePressEvent(QMouseEvent* mouseEvent);
|
||||
|
||||
virtual void dropEvent(QDropEvent* dropEvent);
|
||||
|
||||
|
||||
bool checkAndHandleToggleOfMultipleSelection();
|
||||
|
||||
private:
|
||||
QAction* m_pasteAction;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user