Commit cf8b1861 authored by Bob Obara's avatar Bob Obara

ENH: Adding support to clean up empty views

Views could be made empty by category or advance filtering options.  This commit will prevent empty view labels from showing up in tiled group views
parent 6bf5db63
......@@ -61,6 +61,7 @@ qtAttribute::qtAttribute(smtk::attribute::AttributePtr myAttribute, QWidget* p,
m_widget = NULL;
m_useSelectionManager = false;
this->createWidget();
m_isEmpty = true;
}
qtAttribute::~qtAttribute()
......@@ -82,6 +83,8 @@ qtAttribute::~qtAttribute()
void qtAttribute::createWidget()
{
// Initially there are no items being displayed
m_isEmpty = true;
if (!this->attribute() ||
(!this->attribute()->numberOfItems() && !this->attribute()->associations()))
{
......@@ -119,7 +122,7 @@ void qtAttribute::createWidget()
{
return;
}
m_isEmpty = false;
QFrame* attFrame = new QFrame(this->parentWidget());
attFrame->setFrameShape(QFrame::Box);
m_widget = attFrame;
......@@ -154,6 +157,8 @@ void qtAttribute::showAdvanceLevelOverlay(bool show)
void qtAttribute::createBasicLayout(bool includeAssociations)
{
// Initially we have not displayed any items
m_isEmpty = true;
//If there is no main widget there is nothing to show
if (!m_widget)
{
......@@ -169,6 +174,7 @@ void qtAttribute::createBasicLayout(bool includeAssociations)
qItem = this->createItem(att->associations(), m_widget, m_internals->m_view);
if (qItem && qItem->widget())
{
m_isEmpty = false;
layout->addWidget(qItem->widget());
this->addItem(qItem);
}
......@@ -180,6 +186,7 @@ void qtAttribute::createBasicLayout(bool includeAssociations)
qItem = this->createItem(att->item(static_cast<int>(i)), m_widget, m_internals->m_view);
if (qItem && qItem->widget())
{
m_isEmpty = false;
layout->addWidget(qItem->widget());
this->addItem(qItem);
}
......@@ -303,3 +310,7 @@ qtAttributeItemWidgetFactory* qtAttribute::itemWidgetFactory()
{
return qtAttribute::s_factory;
}
bool qtAttribute::isEmpty() const
{
return m_isEmpty;
}
......@@ -51,6 +51,9 @@ public:
// A basic layout for an attribute
void createBasicLayout(bool includeAssociations);
//Returns true if it does not display any of its items
bool isEmpty() const;
// create all the items
static qtItem* createItem(smtk::attribute::ItemPtr item, QWidget* p, qtBaseView* view,
Qt::Orientation enVectorItemOrient = Qt::Horizontal);
......@@ -75,6 +78,7 @@ protected slots:
private:
qtAttributeInternals* m_internals;
bool m_useSelectionManager;
bool m_isEmpty;
};
} // namespace attribute
......
......@@ -1433,3 +1433,10 @@ void qtAttributeView::showAdvanceLevelOverlay(bool show)
}
this->qtBaseView::showAdvanceLevelOverlay(show);
}
bool qtAttributeView::isEmpty() const
{
QList<smtk::attribute::DefinitionPtr> currentDefs =
this->Internals->getCurrentDefs(this->uiManager()->currentCategory().c_str());
return currentDefs.isEmpty();
}
......@@ -44,6 +44,7 @@ public:
QTableWidgetItem* getSelectedItem();
int currentViewBy();
virtual void createNewAttribute(smtk::attribute::DefinitionPtr attDef);
bool isEmpty() const override;
enum enumViewBy
{
......
......@@ -451,3 +451,8 @@ void qtBaseView::setInfoToBeDisplayed()
{
m_infoDialog->displayInfo(this->getObject());
}
bool qtBaseView::isEmpty() const
{
return false;
}
......@@ -97,6 +97,10 @@ public:
bool isTopLevel() const { return m_isTopLevel; }
//Returns true if the view does not contain any information to display - the default
// behavior is to return false
virtual bool isEmpty() const;
signals:
void modified(smtk::attribute::ItemPtr);
......
......@@ -48,6 +48,7 @@ public:
{
}
QList<smtk::extension::qtBaseView*> ChildViews;
QList<QLabel*> Labels;
qtGroupViewInternals::Style m_style;
std::vector<smtk::view::ViewPtr> m_views;
int m_currentTabSelected;
......@@ -257,21 +258,70 @@ void qtGroupView::clearChildViews()
delete childView;
}
this->Internals->ChildViews.clear();
this->Internals->Labels.clear();
}
void qtGroupView::updateUI()
{
foreach (qtBaseView* childView, this->Internals->ChildViews)
// In the case of tiling we don't want to show the
// label for empty views
if (this->Internals->m_style == qtGroupViewInternals::TILED)
{
childView->updateUI();
int i, size = this->Internals->ChildViews.size();
for (i = 0; i < size; i++)
{
auto child = this->Internals->ChildViews.at(i);
child->updateUI();
if (child->isEmpty())
{
child->widget()->hide();
this->Internals->Labels.at(i)->hide();
}
else
{
child->widget()->show();
this->Internals->Labels.at(i)->show();
}
}
}
else
{
foreach (qtBaseView* childView, this->Internals->ChildViews)
{
childView->updateUI();
}
}
}
void qtGroupView::onShowCategory()
{
foreach (qtBaseView* childView, this->Internals->ChildViews)
// In the case of tiling we don't want to show the
// label for empty views
if (this->Internals->m_style == qtGroupViewInternals::TILED)
{
childView->onShowCategory();
int i, size = this->Internals->ChildViews.size();
for (i = 0; i < size; i++)
{
auto child = this->Internals->ChildViews.at(i);
child->onShowCategory();
if (child->isEmpty())
{
child->widget()->hide();
this->Internals->Labels.at(i)->hide();
}
else
{
child->widget()->show();
this->Internals->Labels.at(i)->show();
}
}
}
else
{
foreach (qtBaseView* childView, this->Internals->ChildViews)
{
childView->onShowCategory();
}
}
this->qtBaseView::onShowCategory();
}
......@@ -365,6 +415,7 @@ void qtGroupView::addTileEntry(qtBaseView* child)
return;
}
QLabel* label = new QLabel(child->getObject()->label().c_str(), this->Widget);
this->Internals->Labels.append(label);
QFont titleFont;
titleFont.setBold(true);
titleFont.setItalic(true);
......@@ -375,6 +426,11 @@ void qtGroupView::addTileEntry(qtBaseView* child)
vLayout->addWidget(label);
vLayout->addWidget(child->widget());
vLayout->setAlignment(Qt::AlignTop);
if (child->isEmpty())
{
label->hide();
child->widget()->hide();
}
}
void qtGroupView::updateModelAssociation()
......
......@@ -30,9 +30,10 @@ using namespace smtk::extension;
class qtInstancedViewInternals
{
public:
qtInstancedViewInternals() {}
qtInstancedViewInternals() { m_isEmpty = true; }
//QScrollArea *ScrollArea;
QList<QPointer<qtAttribute> > AttInstances;
bool m_isEmpty;
};
qtBaseView* qtInstancedView::createViewWidget(const ViewInfo& info)
......@@ -153,6 +154,8 @@ void qtInstancedView::updateAttributeData()
this->setFixedLabelWidth(longLabelWidth);
n = atts.size();
// Assume by default the view is empty
this->Internals->m_isEmpty = true;
for (i = 0; i < n; i++)
{
if (atts[i]->numberOfItems() > 0)
......@@ -164,9 +167,10 @@ void qtInstancedView::updateAttributeData()
// if any exists
attInstance->createBasicLayout(true);
this->Internals->AttInstances.push_back(attInstance);
if (attInstance->widget())
if (attInstance->widget() && !attInstance->isEmpty())
{
this->Widget->layout()->addWidget(attInstance->widget());
this->Internals->m_isEmpty = false;
}
QObject::connect(attInstance, SIGNAL(modified()), this, SIGNAL(modified()));
}
......@@ -197,3 +201,8 @@ bool qtInstancedView::isValid() const
}
return true;
}
bool qtInstancedView::isEmpty() const
{
return this->Internals->m_isEmpty;
}
......@@ -37,6 +37,8 @@ public:
// Returns true if all attributes in the view are valid
bool isValid() const;
bool isEmpty() const override;
public slots:
void showAdvanceLevelOverlay(bool show) override;
void onShowCategory() override { this->updateAttributeData(); }
......
......@@ -665,3 +665,10 @@ void qtModelEntityAttributeView::selectionMade()
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier));
}
}
bool qtModelEntityAttributeView::isEmpty() const
{
QList<smtk::attribute::DefinitionPtr> currentDefs =
this->Internals->getCurrentDefs(this->uiManager()->currentCategory().c_str());
return currentDefs.isEmpty();
}
......@@ -69,6 +69,8 @@ public:
/**\brief method used when model entities are selected via the Selection System */
void updateSelectedModelEntity(const std::string& selSource, smtk::view::SelectionPtr p);
bool isEmpty() const override;
public slots:
void onShowCategory() override;
void showAdvanceLevelOverlay(bool show) override;
......
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