summaryrefslogtreecommitdiff
path: root/debian/patches/0226-qtreeview-column_resize_when_needed.diff
blob: e755a1985513308ce2158c4f704d3bde37ad3dfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
qt-bugs@ issue : N209927
Trolltech task ID : 210390
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
===================================================================
--- a/src/gui/itemviews/qtreeview.h	(revisión: 803370)
+++ b/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
===================================================================
--- a/src/gui/itemviews/qtreeview.cpp	(revisión: 803370)
+++ b/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());
 }
@@ -2797,6 +2810,8 @@
     }
     if (model->canFetchMore(index))
         model->fetchMore(index);
+
+    _q_forceColumnResizeToFitContents();
 }

 void QTreeViewPrivate::collapse(int item, bool emitSignal)
@@ -2836,6 +2851,8 @@
         else
             emit q->collapsed(modelIndex);
     }
+
+    _q_forceColumnResizeToFitContents();
 }

 void QTreeViewPrivate::prepareAnimatedOperation(int item, AnimatedOperation::Type type)
@@ -2947,6 +2964,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
===================================================================
--- a/src/gui/itemviews/qtreeview_p.h	(revision 803534)
+++ b/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);