From b4c8696d6aa3428432d8d3f3026d76df94517cc2 Mon Sep 17 00:00:00 2001 From: mzn Date: Thu, 5 Jun 2008 13:01:54 +0000 Subject: [PATCH] Fix for bug IPAL19655(Qt4 porting:Object Browser - Name field width changes to default after any operation). --- src/ObjBrowser/OB_Browser.cxx | 6 +++--- src/Qtx/QtxTreeView.cxx | 20 ++++++++++++++++++++ src/Qtx/QtxTreeView.h | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 1e7528c74..63ea37b3f 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -457,7 +457,7 @@ void OB_Browser::setOpen( const QModelIndex& index, const bool open ) */ void OB_Browser::adjustWidth() { - myView->resizeColumnToContents( 0 ); + myView->resizeColumnToEncloseContents( 0 ); } /*! @@ -465,7 +465,7 @@ void OB_Browser::adjustWidth() */ void OB_Browser::adjustFirstColumnWidth() { - myView->resizeColumnToContents( 0 ); + myView->resizeColumnToEncloseContents( 0 ); } /*! @@ -475,7 +475,7 @@ void OB_Browser::adjustColumnsWidth() { for ( int aCol = 1; aCol < myView->header()->count(); aCol++ ) { if ( myView->columnWidth( aCol ) > 0 ) - myView->resizeColumnToContents( aCol ); + myView->resizeColumnToEncloseContents( aCol ); } } diff --git a/src/Qtx/QtxTreeView.cxx b/src/Qtx/QtxTreeView.cxx index c1dfc56b9..ea2289616 100644 --- a/src/Qtx/QtxTreeView.cxx +++ b/src/Qtx/QtxTreeView.cxx @@ -271,6 +271,26 @@ bool QtxTreeView::sortMenuEnabled() const return h ? h->sortMenuEnabled() : false; } +/*! + \brief Resizes the given column in order to enclose its contents. + The size will be changed only if it is smaller than the size of + contents. + \param column number of column +*/ +void QtxTreeView::resizeColumnToEncloseContents( int column ) +{ + if (column < 0 || column >= header()->count()) + return; + + int contentsSizeHint = sizeHintForColumn(column); + int headerSizeHint = header()->isHidden() ? 0 : header()->sectionSizeHint(column); + int sizeHint = qMax(contentsSizeHint, headerSizeHint); + + int currentSize = columnWidth( column ); + if (currentSize < sizeHint) + setColumnWidth( column, sizeHint ); +} + /* \brief Called when the header section is clicked. \param column header column index diff --git a/src/Qtx/QtxTreeView.h b/src/Qtx/QtxTreeView.h index be10077a4..f02eaf65c 100644 --- a/src/Qtx/QtxTreeView.h +++ b/src/Qtx/QtxTreeView.h @@ -51,6 +51,8 @@ public: void setSortMenuEnabled( const bool ); bool sortMenuEnabled() const; + void resizeColumnToEncloseContents( int ); + protected slots: void onHeaderClicked( int ); void rowsAboutToBeRemoved( const QModelIndex&, int, int ); -- 2.39.2