Commit b55a22d6 authored by Haocheng LIU's avatar Haocheng LIU
Browse files

BUG: Fix logic error in qtCheckItemComboBox and qtModelEntityItem

In order to be able to pick multiple items in comboBox, CMB uses
a QStandardItemModel in comboBox. But CMB does not update the model
when comboBox inits. Now CMB would initialize the model every time
and disable the pickability of the entity summary.

When entities have been expunged, qtModelEntityItem should also expunge
the corresponding items. A logic is added to address this issue.
parent 52cdf734
Pipeline #60528 running with stage
......@@ -87,7 +87,7 @@ Attribute::~Attribute()
void Attribute::removeAllItems()
{
// we need to detatch all items owned bu this attribute
// we need to detatch all items owned by this attribute
std::size_t i, n = this->m_items.size();
for (i = 0; i < n; i++)
{
......
......@@ -63,6 +63,7 @@ void qtCheckItemComboBox::init()
{
this->m_displayItem = new QStandardItem;
this->m_displayItem->setFlags(Qt::ItemIsEnabled);
this->m_displayItem->setCheckable(false);
this->m_displayItem->setText("0 " + m_displayTextExt);
QStandardItemModel* itemModel = qobject_cast<QStandardItemModel*>(this->model());
if (itemModel)
......@@ -201,6 +202,7 @@ void qtModelEntityItemCombo::init()
void qtModelEntityItemCombo::showPopup()
{
this->setModel(new QStandardItemModel());
this->init();
this->qtCheckItemComboBox::showPopup();
}
......
......@@ -435,6 +435,21 @@ void qtModelEntityItem::onRequestEntityAssociation()
emit this->modified();
}
void qtModelEntityItem::onExpungeEntities(const smtk::model::EntityRefs& expungedEnts)
{
smtk::attribute::ModelEntityItemPtr modEntityItem =
dynamic_pointer_cast<ModelEntityItem>(this->getObject());
for (smtk::model::EntityRefs::const_iterator bit = expungedEnts.begin();
bit != expungedEnts.end(); ++bit)
{
std::ptrdiff_t idx = modEntityItem->find(*bit);
if (idx >= 0)
{
modEntityItem->removeValue(static_cast<std::size_t>(idx));
}
}
}
void qtModelEntityItem::popupViewItemSelected()
{
QStandardItemModel* itemModel =
......
......@@ -48,6 +48,7 @@ public:
public slots:
void setOutputOptional(int);
virtual void onRequestEntityAssociation();
void onExpungeEntities(const smtk::model::EntityRefs& expungedEnts);
signals:
void requestEntityAssociation();
......
......@@ -337,6 +337,8 @@ bool qtModelOperationWidget::initOperatorUI(const smtk::model::OperatorPtr& brOp
SIGNAL(fileItemCreated(smtk::extension::qtFileItem*)));
QObject::connect(uiManager, SIGNAL(modelEntityItemCreated(smtk::extension::qtModelEntityItem*)),
this, SIGNAL(modelEntityItemCreated(smtk::extension::qtModelEntityItem*)));
QObject::connect(uiManager, SIGNAL(modelEntityItemCreated(smtk::extension::qtModelEntityItem*)),
this, SLOT(onModelEntityItemCreated(smtk::extension::qtModelEntityItem*)));
QObject::connect(uiManager,
SIGNAL(meshSelectionItemCreated(smtk::extension::qtMeshSelectionItem*)), this,
SLOT(onMeshSelectionItemCreated(smtk::extension::qtMeshSelectionItem*)));
......@@ -427,16 +429,46 @@ void qtModelOperationWidget::expungeEntities(const smtk::model::EntityRefs& expu
it.next();
bool associationChanged = false;
if (it.value().opPtr && it.value().opPtr->specification())
{
for (EntityRefs::const_iterator bit = expungedEnts.begin(); bit != expungedEnts.end(); ++bit)
{ // FIXME it should recursively update all modelEntityItems in the attribute
for (auto i = 0; i < it.value().opPtr->specification()->numberOfItems(); ++i)
{
smtk::attribute::ItemPtr currentItem = it.value().opPtr->specification()->item(i);
if (currentItem->isValid())
{
smtk::attribute::ModelEntityItemPtr currentMEItem =
smtk::dynamic_pointer_cast<smtk::attribute::ModelEntityItem>(currentItem);
if (currentMEItem && currentMEItem->isValid())
{
for (smtk::model::EntityRefs::const_iterator bit = expungedEnts.begin();
bit != expungedEnts.end(); ++bit)
{
std::ptrdiff_t idx = currentMEItem->find(*bit);
if (idx >= 0)
{
currentMEItem->removeValue(static_cast<std::size_t>(idx));
}
}
}
}
}
if (it.value().opPtr->specification()->associations())
{
if (it.value().opPtr->specification()->isEntityAssociated(*bit))
for (EntityRefs::const_iterator bit = expungedEnts.begin(); bit != expungedEnts.end();
++bit)
{
//std::cout << "expunge from op " << bit->flagSummary(0) << " " << bit->entity() << "\n";
it.value().opPtr->specification()->disassociateEntity(*bit);
associationChanged = true;
if (it.value().opPtr->specification()->isEntityAssociated(*bit))
{
//std::cout << "expunge from op " << bit->flagSummary(0) << " " << bit->entity() << "\n";
it.value().opPtr->specification()->disassociateEntity(*bit);
associationChanged = true;
}
}
}
else // operator's modelEntityItem has been expunged update in qtModelEntityItem
{
emit broadcastExpungeEntities(expungedEnts);
}
}
if (associationChanged)
it.value().opUiView->updateUI();
......@@ -492,6 +524,15 @@ void qtModelOperationWidget::resetUI()
}
}
void qtModelOperationWidget::onModelEntityItemCreated(smtk::extension::qtModelEntityItem* entItem)
{
if (entItem)
{
QObject::connect(this, SIGNAL(broadcastExpungeEntities(const smtk::model::EntityRefs&)),
entItem, SLOT(onExpungeEntities(const smtk::model::EntityRefs&)));
}
}
void qtModelOperationWidget::onMeshSelectionItemCreated(
smtk::extension::qtMeshSelectionItem* meshItem)
{
......
......@@ -60,6 +60,7 @@ public slots:
}
virtual void displayResult(const smtk::io::Logger& html);
virtual void resetUI();
virtual void onModelEntityItemCreated(smtk::extension::qtModelEntityItem* entItem);
signals:
void operationRequested(const smtk::model::OperatorPtr& brOp);
......@@ -69,6 +70,7 @@ signals:
void meshSelectionItemCreated(smtk::extension::qtMeshSelectionItem* meshItem,
const std::string& opName, const smtk::common::UUID& uuid);
void activateOperationTarget(const smtk::common::UUID&);
void broadcastExpungeEntities(const smtk::model::EntityRefs& expungedEnts);
friend class qtModelView;
......
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