#887 Category Legend: Limit legend height when having few categories

This commit is contained in:
Magne Sjaastad 2016-09-22 15:31:21 +02:00
parent 993a67edb6
commit 120cc8b6dc
3 changed files with 28 additions and 2 deletions

View File

@ -493,20 +493,31 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend)
{
updateLegendTextAndTickMarkColor(legend);
legend->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT);
firstRendering->addOverlayItem(legend);
m_visibleLegends.push_back(legend);
}
// Category count used to switch between standard height and full height of legend
const size_t categoryThreshold = 13;
std::vector<caf::CategoryLegend*> categoryLegends;
std::vector<cvf::OverlayItem*> overlayItems;
for (auto legend : m_visibleLegends)
{
legend->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT);
caf::CategoryLegend* catLegend = dynamic_cast<caf::CategoryLegend*>(legend.p());
if (catLegend)
{
categoryLegends.push_back(catLegend);
if (catLegend->categoryCount() > categoryThreshold)
{
categoryLegends.push_back(catLegend);
}
else
{
catLegend->setSizeHint(cvf::Vec2ui(200, 200));
}
}
else
{

View File

@ -127,6 +127,19 @@ String CategoryLegend::title() const
return title;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t CategoryLegend::categoryCount() const
{
if (m_categoryMapper.notNull())
{
return m_categoryMapper->categoryCount();
}
return 0;
}
//--------------------------------------------------------------------------------------------------
/// Hardware rendering using shader programs
//--------------------------------------------------------------------------------------------------

View File

@ -49,6 +49,8 @@ public:
void setTitle(const cvf::String& title);
cvf::String title() const;
size_t categoryCount() const;
protected:
//==================================================================================================