Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37815640
en ru br
Репозитории ALT
S:4.8.7-alt25
5.1: 4.6.3-alt1.M51.1
4.1: 4.4.3-alt1.M41.1
4.0: 4.3.4-alt5.M40.1
3.0: 4.0.1-alt1
+updates:4.0.1-alt2
+backports:4.2.3-alt7.1.M30
www.altlinux.org/Changes

Группа :: Система/Библиотеки
Пакет: qt4

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: 0226-qtreeview-column_resize_when_needed.diff
Скачать


qt-bugs@ issue : None
Trolltech task ID : None
bugs.kde.org number : None
applied: no
author: Rafael Fernц║ndez LцЁpez <ereslibre@kde.org>
If we have no header, or not visible header on a QTreeView, we can end up with
an unusable widget if we expand lots of child widgets of the kind
a
 b
  c
   d
    ...
This patch assures that if no header is shown, or if we only have one column (so
no other columns become shrinked), the contents will be visible.
Index: src/gui/itemviews/qtreeview.h
===================================================================
--- src/gui/itemviews/qtreeview.h	(revisiцЁn: 803370)
+++ src/gui/itemviews/qtreeview.h	(copia de trabajo)
@@ -229,6 +229,7 @@
     Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeRemoved(const QModelIndex &, int, int))
     Q_PRIVATE_SLOT(d_func(), void _q_columnsRemoved(const QModelIndex &, int, int))
     Q_PRIVATE_SLOT(d_func(), void _q_modelAboutToBeReset())
+    Q_PRIVATE_SLOT(d_func(), void _q_forceColumnResizeToFitContents())
 };
 #endif // QT_NO_TREEVIEW
Index: src/gui/itemviews/qtreeview.cpp
===================================================================
--- src/gui/itemviews/qtreeview.cpp	(revisiцЁn: 803370)
+++ src/gui/itemviews/qtreeview.cpp	(copia de trabajo)
@@ -246,6 +246,19 @@
     connect(d->model, SIGNAL(modelAboutToBeReset()), SLOT(_q_modelAboutToBeReset()));
+    // we connect these signals from the model to a slot that will call
+    // resizeColumnToContents. This is important because if we call it only on
+    // expand() method, when we expand a node, the filling of the model can be
+    // delayed. So, we call it again after the model has finished its job.
+    connect(d->model, SIGNAL(layoutChanged()),
+               this, SLOT(_q_forceColumnResizeToFitContents()));
+    connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
+               this, SLOT(_q_forceColumnResizeToFitContents()));
+    connect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+               this, SLOT(_q_forceColumnResizeToFitContents()));
+
+
+
     if (d->sortingEnabled)
         sortByColumn(header()->sortIndicatorSection());
 }
@@ -2787,6 +2800,8 @@
     }
     if (model->canFetchMore(index))
         model->fetchMore(index);
+
+    _q_forceColumnResizeToFitContents();
 }
 void QTreeViewPrivate::collapse(int item, bool emitSignal)
@@ -2826,6 +2841,8 @@
         else
             emit q->collapsed(modelIndex);
     }
+
+    _q_forceColumnResizeToFitContents();
 }
 void QTreeViewPrivate::prepareAnimatedOperation(int item, AnimatedOperation::Type type)
@@ -2937,6 +2954,25 @@
     viewItems.clear();
 }
+void QTreeViewPrivate::_q_forceColumnResizeToFitContents()
+{
+    Q_Q(QTreeView);
+
+    /**
+      * if:
+      *
+      * a) The tree view has no header (user cannot resize the column) OR
+      * b) The tree view has a header, but hidden (user cannot resize the column) OR
+      * c) The tree view has a visible header, but with _only_ one (or zero) column (that
+      *    means: no other information will be affected).
+      *
+      * We can expand the column to make the contents properly visible.
+      */
+    if (!header || !header->isVisible() || ((header->count() - header->hiddenSectionCount()) <= 1)) {
+        q->resizeColumnToContents(q->currentIndex().column());
+    }
+}
+
 void QTreeViewPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
 {
     Q_UNUSED(parent);
Index: src/gui/itemviews/qtreeview_p.h
===================================================================
--- src/gui/itemviews/qtreeview_p.h	(revision 803534)
+++ src/gui/itemviews/qtreeview_p.h	(working copy)
@@ -101,6 +101,7 @@
         QPixmap after;
     };
 
+    void _q_forceColumnResizeToFitContents();
     void expand(int item, bool emitSignal);
     void collapse(int item, bool emitSignal);
 
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin