KTextEditor

expandingwidgetmodel.h
1 /*
2  SPDX-FileCopyrightText: 2007 David Nolden <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef EXPANDING_WIDGET_MODEL_H
8 #define EXPANDING_WIDGET_MODEL_H
9 
10 #include <QAbstractTableModel>
11 #include <QIcon>
12 #include <QPointer>
13 
14 class QTreeView;
15 
16 /**
17  * Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate
18  */
20 {
21  Q_OBJECT
22 public:
24  ~ExpandingWidgetModel() override;
25 
26  enum ExpandingType { NotExpandable = 0, Expandable, Expanded };
27 
28  /// Unexpand all rows and clear all cached information about them(this includes deleting the expanding-widgets)
29  void clearExpanding();
30 
31  ///@return whether the row given through index is expandable
32  bool isExpandable(const QModelIndex &index) const;
33 
34  ///@return whether row is currently expanded
35  bool isExpanded(const QModelIndex &row) const;
36  /// Change the expand-state of the row given through index. The display will be updated.
37  void setExpanded(QModelIndex index, bool expanded);
38 
39  ///@return the expanding-widget for the given row, if available. Expanding-widgets are in best case available for all expanded rows.
40  /// This does not return the partially-expand widget.
41  QWidget *expandingWidget(const QModelIndex &row) const;
42 
43  /// Places and shows the expanding-widget for the given row, if it should be visible and is valid.
44  /// Also shows the partial-expanding-widget when it should be visible.
45  void placeExpandingWidget(const QModelIndex &row);
46 
47  virtual QTreeView *treeView() const = 0;
48 
49  /// Should return true if the given row should be painted like a contained item(as opposed to label-rows etc.)
50  virtual bool indexIsItem(const QModelIndex &index) const = 0;
51 
52  /// Does not request data from index, this only returns local data like highlighting for expanded rows and similar
53  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
54 
55  /// Returns the match-color for the given index, or zero if match-quality could not be computed.
56  uint matchColor(const QModelIndex &index) const;
57 
58 public Q_SLOTS:
59  /// Place or hides all expanding-widgets to the correct positions. Should be called after the view was scrolled.
60  void placeExpandingWidgets();
61 
62 protected:
63  /**
64  * @return the context-match quality from 0 to 10 if it could be determined, else -1
65  * */
66  virtual int contextMatchQuality(const QModelIndex &index) const = 0;
67 
68  // Makes sure m_expandedIcon and m_collapsedIcon are loaded
69  void cacheIcons() const;
70 
71  mutable QIcon m_expandedIcon;
72  mutable QIcon m_collapsedIcon;
73 
74  // Finds out the basic height of the row represented by the given index. Basic means without respecting any expansion.
75  int basicRowHeight(const QModelIndex &index) const;
76 
77 private:
78  // QMap<QModelIndex, ExpansionType> m_partiallyExpanded;
79  // Store expanding-widgets and cache whether items can be expanded
80  mutable QMap<QModelIndex, ExpandingType> m_expandState;
81  QMap<QModelIndex, QPointer<QWidget>> m_expandingWidgets; // Map rows to their expanding-widgets
82 };
83 
84 /**
85  * Helper-function to merge custom-highlighting variant-lists.
86  *
87  * @param strings A list of strings that should be merged
88  * @param highlights One variant-list for highlighting, as described in the kde header ktextedtor/codecompletionmodel.h
89  * @param gapBetweenStrings How many signs are inserted between 2 strings?
90  * */
91 QList<QVariant> mergeCustomHighlighting(QStringList strings, QList<QVariantList> highlights, int gapBetweenStrings = 0);
92 #endif
Q_OBJECTQ_OBJECT
void placeExpandingWidget(const QModelIndex &row)
Places and shows the expanding-widget for the given row, if it should be visible and is valid.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Does not request data from index, this only returns local data like highlighting for expanded rows an...
DisplayRole
Q_SLOTSQ_SLOTS
uint matchColor(const QModelIndex &index) const
Returns the match-color for the given index, or zero if match-quality could not be computed.
virtual bool indexIsItem(const QModelIndex &index) const =0
Should return true if the given row should be painted like a contained item(as opposed to label-rows ...
void clearExpanding()
Unexpand all rows and clear all cached information about them(this includes deleting the expanding-wi...
void setExpanded(QModelIndex index, bool expanded)
Change the expand-state of the row given through index. The display will be updated.
bool isExpanded(const QModelIndex &row) const
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
virtual int contextMatchQuality(const QModelIndex &index) const =0
QWidget * expandingWidget(const QModelIndex &row) const
bool isExpandable(const QModelIndex &index) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
QObject * parent() const const
void placeExpandingWidgets()
Place or hides all expanding-widgets to the correct positions. Should be called after the view was sc...
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 9 2022 03:52:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.