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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/* This file is part of the KDE libraries and the Kate part.
*
* Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KDEVPLATFORM_PLUGIN_EXPANDING_WIDGET_MODEL_H
#define KDEVPLATFORM_PLUGIN_EXPANDING_WIDGET_MODEL_H
#include <QAbstractTableModel>
#include <QPointer>
class ExpandingDelegate;
class ExpandingTree;
class QTreeView;
/**
* Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate
*/
class ExpandingWidgetModel
: public QAbstractTableModel
{
Q_OBJECT
public:
explicit ExpandingWidgetModel(QWidget* parent);
~ExpandingWidgetModel() override;
enum ExpandingType {
NotExpandable = 0,
Expandable,
Expanded
};
///The following three are convenience-functions for the current item that could be replaced by the later ones
///@return whether the current item can be expanded
bool canExpandCurrentItem() const;
///@return whether the current item can be collapsed
bool canCollapseCurrentItem() const;
///Expand/collapse the current item
void setCurrentItemExpanded(bool);
void clearMatchQualities();
///Unexpand all rows and clear all cached information about them(this includes deleting the expanding-widgets)
void clearExpanding();
///@return whether the row given through index is expandable
bool isExpandable(const QModelIndex& index) const;
enum ExpansionType {
NotExpanded = 0,
ExpandDownwards, //The additional(expanded) information is shown UNDER the original information
ExpandUpwards //The additional(expanded) information is shown ABOVE the original information
};
///Returns whether the given index is currently partially expanded. Does not do any other checks like calling models for data.
ExpansionType isPartiallyExpanded(const QModelIndex& index) const;
///@return whether row is currently expanded
bool isExpanded(const QModelIndex& row) const;
///Change the expand-state of the row given through index. The display will be updated.
void setExpanded(const QModelIndex& index, bool expanded);
///Returns the total height added through all open expanding-widgets
int expandingWidgetsHeight() const;
///@return the expanding-widget for the given row, if available. Expanding-widgets are in best case available for all expanded rows.
///This does not return the partially-expand widget.
QWidget* expandingWidget(const QModelIndex& row) const;
///Amount by which the height of a row increases when it is partially expanded
int partiallyExpandWidgetHeight() const;
/**
* Notifies underlying models that the item was selected, collapses any previous partially expanded line,
* checks whether this line should be partially expanded, and eventually does it.
* Does nothing when nothing needs to be done.
* Does NOT show the expanding-widget. That is done immediately when painting by ExpandingDelegate,
* to reduce flickering. @see showPartialExpandWidget()
* @param row The row
* */
///
virtual void rowSelected(const QModelIndex& row);
/// Returns the rectangle for the partially expanded part of the given row
/// TODO: Do this via QAIM roles?
QRect partialExpandRect(const QModelIndex& row) const;
/// TODO: Do this via QAIM roles?
QString partialExpandText(const QModelIndex& row) const;
///Places and shows the expanding-widget for the given row, if it should be visible and is valid.
///Also shows the partial-expanding-widget when it should be visible.
void placeExpandingWidget(const QModelIndex& row);
virtual QTreeView* treeView() const = 0;
///Should return true if the given row should be painted like a contained item(as opposed to label-rows etc.)
virtual bool indexIsItem(const QModelIndex& index) const = 0;
///Does not request data from index, this only returns local data like highlighting for expanded rows and similar
QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const override;
///Returns the first row that is currently partially expanded.
QModelIndex partiallyExpandedRow() const;
///Returns the match-color for the given index, or zero if match-quality could not be computed.
uint matchColor(const QModelIndex& index) const;
public Q_SLOTS:
///Place or hides all expanding-widgets to the correct positions. Should be called after the view was scrolled.
void placeExpandingWidgets();
protected:
/**
* @return the context-match quality from 0 to 10 if it could be determined, else -1
* */
virtual int contextMatchQuality(const QModelIndex& index) const = 0;
QModelIndex mapFromSource(const QModelIndex& index) const;
QModelIndex mapToSource(const QModelIndex& index) const;
//Does not update the view
void partiallyUnExpand(const QModelIndex& index);
//Finds out the basic height of the row represented by the given index. Basic means without respecting any expansion.
int basicRowHeight(const QModelIndex& index) const;
private:
friend ExpandingDelegate;
friend ExpandingTree;
QMap<QModelIndex, ExpansionType> m_partiallyExpanded;
// Store expanding-widgets and cache whether items can be expanded
mutable QMap<QModelIndex, ExpandingType> m_expandState;
QMap<QModelIndex, QPointer<QWidget> > m_expandingWidgets; //Map rows to their expanding-widgets
QMap<QModelIndex, int> m_contextMatchQualities; //Map rows to their context-match qualities(undefined if unknown, else 0 to 10). Not used yet, eventually remove.
};
/**
* Helper-function to merge custom-highlighting variant-lists.
*
* @param strings A list of strings that should be merged
* @param highlights One variant-list for highlighting, as described in the kde header ktextedtor/codecompletionmodel.h
* @param gapBetweenStrings How many signs are inserted between 2 strings?
* */
QList<QVariant> mergeCustomHighlighting(const QStringList& strings, const QList<QVariantList>& highlights, int gapBetweenStrings = 0);
#endif
|