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 
20 {
21  Q_OBJECT
22 public:
24  ~ExpandingWidgetModel() override;
25 
26  enum ExpandingType { NotExpandable = 0, Expandable, Expanded };
27 
30  bool canExpandCurrentItem() const;
32  bool canCollapseCurrentItem() const;
34  void setCurrentItemExpanded(bool);
35 
36  void clearMatchQualities();
37 
39  void clearExpanding();
40 
42  bool isExpandable(const QModelIndex &index) const;
43 
44  enum ExpansionType {
45  NotExpanded = 0,
46  ExpandDownwards, // The additional(expanded) information is shown UNDER the original information
47  ExpandUpwards // The additional(expanded) information is shown ABOVE the original information
48  };
49 
51  ExpansionType isPartiallyExpanded(const QModelIndex &index) const;
52 
54  bool isExpanded(const QModelIndex &row) const;
56  void setExpanded(QModelIndex index, bool expanded);
57 
59  int expandingWidgetsHeight() const;
60 
63  QWidget *expandingWidget(const QModelIndex &row) const;
64 
66  int partiallyExpandWidgetHeight() const;
75  virtual void rowSelected(const QModelIndex &row);
77 
79  QRect partialExpandRect(const QModelIndex &row) const;
80 
81  QString partialExpandText(const QModelIndex &row) const;
82 
85  void placeExpandingWidget(const QModelIndex &row);
86 
87  virtual QTreeView *treeView() const = 0;
88 
90  virtual bool indexIsItem(const QModelIndex &index) const = 0;
91 
93  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
94 
97 
99  uint matchColor(const QModelIndex &index) const;
100 
101 public Q_SLOTS:
103  void placeExpandingWidgets();
104 
105 protected:
109  virtual int contextMatchQuality(const QModelIndex &index) const = 0;
110 
111  // Makes sure m_expandedIcon and m_collapsedIcon are loaded
112  void cacheIcons() const;
113 
114  mutable QIcon m_expandedIcon;
115  mutable QIcon m_collapsedIcon;
116 
117  // Does not update the view
118  void partiallyUnExpand(const QModelIndex &index);
119  // Finds out the basic height of the row represented by the given index. Basic means without respecting any expansion.
120  int basicRowHeight(const QModelIndex &index) const;
121 
122 private:
123  QMap<QModelIndex, ExpansionType> m_partiallyExpanded;
124  // Store expanding-widgets and cache whether items can be expanded
125  mutable QMap<QModelIndex, ExpandingType> m_expandState;
126  QMap<QModelIndex, QPointer<QWidget>> m_expandingWidgets; // Map rows to their expanding-widgets
127  QMap<QModelIndex, int> m_contextMatchQualities; // Map rows to their context-match qualities(undefined if unknown, else 0 to 10). Not used yet, eventually remove.
128 };
129 
137 QList<QVariant> mergeCustomHighlighting(QStringList strings, QList<QVariantList> highlights, int gapBetweenStrings = 0);
138 #endif
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const =0
void setCurrentItemExpanded(bool)
Expand/collapse the current item.
virtual void rowSelected(const QModelIndex &row)
Notifies underlying models that the item was selected, collapses any previous partially expanded line...
QModelIndex partiallyExpandedRow() const
Returns the first row that is currently partially expanded.
void clearExpanding()
Unexpand all rows and clear all cached information about them(this includes deleting the expanding-wi...
void placeExpandingWidgets()
Place or hides all expanding-widgets to the correct positions. Should be called after the view was sc...
ExpansionType isPartiallyExpanded(const QModelIndex &index) const
Returns whether the given index is currently partially expanded. Does not do any other checks like ca...
bool isExpandable(const QModelIndex &index) const
void placeExpandingWidget(const QModelIndex &row)
Places and shows the expanding-widget for the given row, if it should be visible and is valid...
Q_OBJECTQ_OBJECT
virtual int contextMatchQuality(const QModelIndex &index) const =0
QWidget * expandingWidget(const QModelIndex &row) const
DisplayRole
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 ...
bool isExpanded(const QModelIndex &row) const
int partiallyExpandWidgetHeight() const
Amount by which the height of a row increases when it is partially expanded.
bool canCollapseCurrentItem() const
void setExpanded(QModelIndex index, bool expanded)
Change the expand-state of the row given through index. The display will be updated.
Q_SLOTSQ_SLOTS
QObject * parent() const const
bool canExpandCurrentItem() const
The following three are convenience-functions for the current item that could be replaced by the late...
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...
int expandingWidgetsHeight() const
Returns the total height added through all open expanding-widgets.
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
QRect partialExpandRect(const QModelIndex &row) const
Returns the rectangle for the partially expanded part of the given row.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 22:57:32 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.