Commit 5c4db951 authored by David Thompson's avatar David Thompson

Add some controls to qtReferenceItem.

parent e68160fc
......@@ -241,6 +241,7 @@ bool pqSMTKOperationPanel::editOperation(smtk::operation::OperationPtr op)
// Create a new UI.
m_attrUIMgr = new smtk::extension::qtUIManager(
m_editing, m_wrapper ? m_wrapper->smtkResourceManager() : nullptr);
m_attrUIMgr->setSelection(m_wrapper ? m_wrapper->smtkSelection() : nullptr);
// If the operation did not have its manager set, fall back to the
// operation manager we were told to use when listing available operations:
if (!m_attrUIMgr->operationManager())
......
......@@ -132,6 +132,7 @@ qt5_wrap_cpp(MOC_BUILT_SOURCES ${QAttrLibMocHeaders})
qt5_wrap_ui(SMTKQTEXT_UI_BUILT_SOURCES ${QAttrLibUIs})
qt5_add_resources(RCS_RESOURCES
qtDescriptivePhraseModelIcons.qrc
qtReferenceItemIcons.qrc
qtAttributeIcons.qrc
)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -178,6 +178,65 @@ void qtReferenceItem::synchronizeAndHide(bool escaping)
m_p->m_popup->hide();
}
void qtReferenceItem::copyFromSelection()
{
if (!m_itemInfo.uiManager())
{
return;
}
auto seln = m_itemInfo.uiManager()->selection();
if (seln)
{
auto selnSet = seln->currentSelectionByValueAs<smtk::resource::PersistentObjectArray>(1);
if (m_itemInfo.itemAs<smtk::attribute::ReferenceItem>()->setObjectValues(
selnSet.begin(), selnSet.end()))
{
this->synchronize(UpdateSource::GUI_FROM_ITEM);
this->updateSynopsisLabels();
}
}
}
void qtReferenceItem::copyToSelection()
{
if (!m_itemInfo.uiManager())
{
return;
}
auto seln = m_itemInfo.uiManager()->selection();
if (seln)
{
smtk::resource::PersistentObjectArray nextSeln;
nextSeln.reserve(m_p->m_members.size());
for (const auto& entry : m_p->m_members)
{
nextSeln.push_back(entry.first);
}
seln->modifySelection(nextSeln, "qtReferenceItem", 1); // FIXME: Use an app-specified bit
}
}
void qtReferenceItem::clearItem()
{
m_itemInfo.item()->reset();
this->synchronize(UpdateSource::GUI_FROM_ITEM);
this->updateSynopsisLabels();
}
void qtReferenceItem::sneakilyHideButtons()
{
m_p->m_copyFromSelection->setVisible(false);
m_p->m_clear->setVisible(false);
m_p->m_copyToSelection->setVisible(false);
}
void qtReferenceItem::cleverlyShowButtons()
{
m_p->m_copyFromSelection->setVisible(true);
m_p->m_clear->setVisible(true);
m_p->m_copyToSelection->setVisible(true);
}
smtk::view::PhraseModelPtr qtReferenceItem::createPhraseModel() const
{
auto showsWhat = this->acceptableTypes();
......@@ -343,6 +402,30 @@ void qtReferenceItem::updateUI()
entryLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
// An entry consists of ...
// ... a button to grab the selection
QIcon copyFromSelection(":/icons/reference-item/copy-from-selection.png");
m_p->m_copyFromSelection = new QPushButton(copyFromSelection, "");
m_p->m_copyFromSelection->setSizePolicy(sizeFixedPolicy);
m_p->m_copyFromSelection->setToolTip("Replace this item's members with the selection.");
entryLayout->addWidget(m_p->m_copyFromSelection);
QObject::connect(m_p->m_copyFromSelection, SIGNAL(clicked()), this, SLOT(copyFromSelection()));
// ... a button to empty the item's members
QIcon clearItem(":/icons/reference-item/clear.png");
m_p->m_clear = new QPushButton(clearItem, "");
m_p->m_clear->setSizePolicy(sizeFixedPolicy);
m_p->m_clear->setToolTip("Clear this item's members.");
entryLayout->addWidget(m_p->m_clear);
QObject::connect(m_p->m_clear, SIGNAL(clicked()), this, SLOT(clearItem()));
// ... a button to populate the selection with the item's members
QIcon copyToSelection(":/icons/reference-item/copy-to-selection.png");
m_p->m_copyToSelection = new QPushButton(copyToSelection, "");
m_p->m_copyToSelection->setSizePolicy(sizeFixedPolicy);
m_p->m_copyToSelection->setToolTip("Replace the selection with this item's members.");
entryLayout->addWidget(m_p->m_copyToSelection);
QObject::connect(m_p->m_copyToSelection, SIGNAL(clicked()), this, SLOT(copyToSelection()));
// ... a synopsis (label).
bool ok;
QString synText = QString::fromStdString(this->synopsis(ok));
......@@ -399,6 +482,7 @@ void qtReferenceItem::updateUI()
}
this->synchronize(UpdateSource::GUI_FROM_ITEM);
this->sneakilyHideButtons();
this->updateSynopsisLabels();
}
......@@ -495,9 +579,11 @@ bool qtReferenceItem::eventFilter(QObject* src, QEvent* event)
{
case QEvent::Enter:
this->linkHover(true);
this->cleverlyShowButtons();
break;
case QEvent::Leave:
this->linkHover(false);
this->sneakilyHideButtons();
break;
case QEvent::FocusIn:
this->linkHover(true);
......
......@@ -78,6 +78,12 @@ protected slots:
*/
virtual void synchronizeAndHide(bool escaping = false);
virtual void copyFromSelection();
virtual void copyToSelection();
virtual void clearItem();
virtual void sneakilyHideButtons();
virtual void cleverlyShowButtons();
protected:
/**\brief Subclasses override this to create a model of the appropriate type.
*
......
......@@ -58,12 +58,13 @@ public:
// Main widget contents
QGridLayout* m_grid;
QCheckBox* m_optional; // Added if the item is optional to reflect IsEnabled().
QLabel* m_label; // The item's label (or name if no label).
QLabel* m_synopsis; // A live summary of the item's entries and acceptability
QPushButton* m_editBtn; // A button to show a popup used to edit the item's entries
QPushButton* m_exportSeln; // A button to one-shot export the item's entries to an app. selection
QPushButton* m_importSeln; // A button to one-shot import an application selection to the entries
QCheckBox* m_optional; // Added if the item is optional to reflect IsEnabled().
QLabel* m_label; // The item's label (or name if no label).
QLabel* m_synopsis; // A live summary of the item's entries and acceptability
QPushButton* m_copyFromSelection; // A button to copy the selection into the item's entries
QPushButton* m_copyToSelection; // A button to copy the item's entries into the selection
QPushButton* m_clear; // A button to clear the item's entries
QPushButton* m_editBtn; // A button to show a popup used to edit the item's entries
QPushButton* m_linkSeln; // A button to link an app. selection to the item's entries permanently.
// Popup widget contents
......
<RCC>
<qresource prefix="/icons/reference-item">
<file alias = "copy-from-selection.png">icons/copy-from-selection.png</file>
<file alias = "copy-to-selection.png">icons/copy-to-selection.png</file>
<file alias = "clear.png">icons/times.png</file>
</qresource>
</RCC>
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