Commit d585148e authored by Artur Grunau's avatar Artur Grunau
Browse files

PipelineTreeWidget: provide a sensible height hint

The sizeHint method has been overridden in PipelineTreeWidget to return
a sensible height for the wigdet, while still reusing QTreeView's
hardcoded width.

The main window makes use of that to limit PipelineTreeWidget's maximum
height and give any vertical space reclaimed in this way over to the
widget displaying pipeline properties.
parent 163acaae
......@@ -82,6 +82,7 @@ namespace campvis {
setCentralWidget(_mdiArea);
_pipelineWidget = new PipelineTreeWidget();
_pipelineWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
ui.pipelineTreeDock->setWidget(_pipelineWidget);
_pipelinePropertiesScrollArea = new QScrollArea();
......
......@@ -31,6 +31,7 @@
#include "tgt/assert.h"
#include <QHeaderView>
#include <QScrollBar>
#include <QStringList>
namespace campvis {
......@@ -282,6 +283,27 @@ namespace campvis {
}
QSize PipelineTreeWidget::sizeHint() const {
int height = 0;
// First of all, sum up the heights of top-level items and their children
for (int i = 0; i < model()->rowCount(); i++) {
QModelIndex index = model()->index(i, 0);
height += sizeHintForRow(i);
if (model()->hasChildren(index)) {
height += model()->rowCount(index) * sizeHintForIndex(index.child(0, 0)).height();
}
}
// Next, add the heights of the horizontal scrollbar, header, and frame
height += horizontalScrollBar()->sizeHint().height();
height += header()->sizeHint().height();
height += 2 * frameWidth();
return QSize(QTreeView::sizeHint().width(), height);
}
void PipelineTreeWidget::update(const std::vector<AbstractPipeline*>& pipelines) {
// clear selection before setting the new data or we will encounter random crashes...
selectionModel()->clear();
......@@ -290,6 +312,9 @@ namespace campvis {
expandAll();
resizeColumnToContents(0);
resizeColumnToContents(1);
// The widget's size hint might have changed, notify the layout
updateGeometry();
}
void PipelineTreeWidget::setupWidget() {
......@@ -299,4 +324,4 @@ namespace campvis {
setModel(_treeModel);
}
}
\ No newline at end of file
}
......@@ -148,6 +148,14 @@ namespace campvis {
*/
virtual ~PipelineTreeWidget();
/**
* Return the recommended size for the widget.
*
* This method tries to calculate a sensible height for the wigdet, while still reusing QTreeView's hardcoded
* width.
*/
virtual QSize sizeHint() const;
public slots:
/**
......
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