File indexing completed on 2024-05-05 04:38:44
0001 /* 0002 SPDX-FileCopyrightText: 2009 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_FOCUSEDTREEVIEW_H 0008 #define KDEVPLATFORM_FOCUSEDTREEVIEW_H 0009 0010 #include <QTreeView> 0011 #include "utilexport.h" 0012 0013 namespace KDevelop { 0014 class FocusedTreeViewPrivate; 0015 0016 /** 0017 * Specialized version of QTreeView, that allows efficiently managing an extremely 0018 * long list of items, by focusing the size of the horizontal scroll-bars only on the currently 0019 * visible items. 0020 * 0021 * In addition, this class provides optional automatic scrolling when rows are inserted at the end. 0022 * 0023 * @warning Either the scroll-mode ScrollPerItem must be enabled, or the uniformRowHeight flag, for this to work efficiently. 0024 * @warning This currently only works with flat list models(todo). 0025 */ 0026 class KDEVPLATFORMUTIL_EXPORT FocusedTreeView : public QTreeView 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 explicit FocusedTreeView(QWidget* parent); 0032 ~FocusedTreeView() override; 0033 0034 /** 0035 * When enabled, automatically scroll to bottom when new rows are inserted at the end 0036 * and the end was previously visible. (Default: false) 0037 */ 0038 void setAutoScrollAtEnd(bool enable); 0039 0040 void setModel(QAbstractItemModel* model) override; 0041 int sizeHintForColumn(int column) const override; 0042 0043 /** 0044 * Resize columns to contents. 0045 * 0046 * Call this function after modifying the @a wordWrap property to rewrap lines 0047 * immediately rather than only after subsequent vertical scrolling. 0048 */ 0049 void fitColumns(); 0050 0051 protected: 0052 void resizeEvent(QResizeEvent* event) override; 0053 0054 private Q_SLOTS: 0055 void rowsAboutToBeInserted(const QModelIndex& parent, int first, int last); 0056 void rowsRemoved(const QModelIndex& parent, int first, int last); 0057 void delayedAutoScrollAndResize(); 0058 0059 private: 0060 const QScopedPointer<class FocusedTreeViewPrivate> d_ptr; 0061 Q_DECLARE_PRIVATE(FocusedTreeView) 0062 }; 0063 0064 } 0065 0066 #endif // KDEVPLATFORM_FOCUSEDLISTVIEW_H