Commit 6653bb40 authored by David Thompson's avatar David Thompson Committed by Kitware Robot

Merge topic 'space-toggle-vis'

14038c83 Make the space key toggle visibility of selection...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: T.J. Corona's avatarT.J. Corona <tj.corona@kitware.com>
Merge-request: !1468
parents c52e461a 14038c83
......@@ -33,6 +33,7 @@
#include <QColorDialog>
#include <QItemSelection>
#include <QItemSelectionModel>
#include <QKeyEvent>
#include <QPointer>
#include <QTreeView>
......@@ -362,3 +363,52 @@ void qtResourceBrowser::editObjectColor(const QModelIndex& idx)
}
}
}
bool qtResourceBrowser::eventFilter(QObject* obj, QEvent* evnt)
{
QKeyEvent* evt;
if (obj == m_p->m_view && evnt->type() == QEvent::KeyPress &&
(evt = dynamic_cast<QKeyEvent*>(evnt)))
{
if (evt->key() == Qt::Key_Space)
{
// Iterate over the selected indices and toggle the visibility of
// every item to either on or off (determined by examining the first
// index's current state).
auto selected = m_p->m_view->selectionModel()->selection();
smtk::view::DescriptivePhrase::Ptr phrase;
bool toggleTo = false;
bool found = false;
for (auto idx : selected.indexes())
{
phrase = idx.data(qtDescriptivePhraseModel::PhrasePtrRole)
.value<smtk::view::DescriptivePhrase::Ptr>();
if (!phrase)
{
continue;
}
if (phrase->displayVisibility())
{
toggleTo = !phrase->relatedVisibility();
found = true;
break;
}
}
if (found)
{
for (auto idx : selected.indexes())
{
phrase = idx.data(qtDescriptivePhraseModel::PhrasePtrRole)
.value<smtk::view::DescriptivePhrase::Ptr>();
if (!phrase)
{
continue;
}
phrase->setRelatedVisibility(toggleTo);
}
return true;
}
}
}
return this->Superclass::eventFilter(obj, evnt);
}
......@@ -92,6 +92,7 @@ protected slots:
protected:
virtual void resetHover(smtk::resource::ComponentSet& add, smtk::resource::ComponentSet& del);
bool eventFilter(QObject*, QEvent*) override;
class Internal;
Internal* m_p;
......
......@@ -64,6 +64,7 @@ void qtResourceBrowser::Internal::setup(qtResourceBrowser* self,
m_layout->setObjectName("m_layout");
m_view = ctor(parent);
m_layout->addWidget(m_view);
m_view->installEventFilter(self);
// Keep or create a QAbstractItemModel subclass (which had better be
// related somehow to a qtDescriptivePhraseModel).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment