30#include <QAbstractItemModel>
35class QAbstractItemDelegate;
38class QStyleOptionViewItem;
43class StyledItemDelegate;
79 QModelIndex
index(
int row,
int column,
const QModelIndex &parent = QModelIndex())
const override;
80 QModelIndex
parent(
const QModelIndex &child)
const override;
81 int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
82 int columnCount(
const QModelIndex &parent = QModelIndex())
const override;
83 QVariant
data(
const QModelIndex &index,
int role = Qt::DisplayRole)
const override;
84 bool setData(
const QModelIndex &index,
const QVariant &value,
int role)
override;
85 bool insertRows(
int row,
int count,
const QModelIndex &parent = QModelIndex())
override;
86 QVariant
headerData(
int section, Qt::Orientation orientation,
int role = Qt::DisplayRole)
const override;
87 Qt::ItemFlags
flags(
const QModelIndex &index)
const override;
97#ifdef KDWINUTILS_WITHMFC
102 using CustomPaintFunction = std::function<void(QPainter *,
const QStyleOptionViewItem &,
const QModelIndex &)>;
108 template <
typename Class>
110 void setCustomPaintFunction(Class *
object,
111 void (Class::*method)(QPainter *painter,
const QStyleOptionViewItem &styleOption,
112 const QModelIndex &index));
127 explicit operator bool() const noexcept {
return pos >= 0; }
134 return !
static_cast<bool>(p);
138 return static_cast<bool>(p);
150 SmallIcon = 0x00000004,
152 TypeMask = 0x00000008,
155 ShowSelAlways = 0x00000020,
156 SortAscending = 0x00000040,
157 SortDescending = 0x00000080,
158 ShareImageLists = 0x00000100,
159 NoLabelWrap = 0x00000200,
160 AutoArrange = 0x00000400,
161 EditLabels = 0x00000800,
162 OwnerData = 0x00001000,
163 NoScroll = 0x00002000,
164 TypeStyleMask = 0x00004000,
165 AlignTop = 0x00000001,
166 AlignLeft = 0x00008000,
167 AlignMask = 0x00010000,
168 OwnerDrawFixed = 0x00020000,
169 NoColumnHeader = 0x00040000,
170 NoSortHeader = 0x00080000,
175 GridLines = 0x00000001,
176 SubItemImages = 0x00000002,
177 CheckBoxes = 0x00000004,
178 TrackSelect = 0x00000008,
179 HeaderDragDrop = 0x00000010,
180 FullRowSelect = 0x00000020,
181 OneClickActivate = 0x00000040,
182 TwoClickActivate = 0x00000080,
184 Regional = 0x00000200,
185 InfoTip = 0x00000400,
186 UnderlineHot = 0x00000800,
187 UnderlineCold = 0x00001000,
188 MultiWorkAreas = 0x00002000,
189 LabelTip = 0x00004000,
190 BorderSelect = 0x00008000,
191 DoubleBuffer = 0x00010000,
192 HideLabels = 0x00020000,
193 SingleRow = 0x00040000,
194 SnapToGrid = 0x00080000,
195 SimpleSelect = 0x00100000,
196 JustifyColumns = 0x00200000,
197 TransparentBkgnd = 0x00400000,
198 TransparentShadowText = 0x00800000,
199 AutoAutoArrange = 0x01000000,
200 HeaderInAllViews = 0x02000000,
201 AutoCheckSelect = 0x08000000,
202 AutoSizeColumns = 0x10000000,
203 ColumnSnapPoints = 0x40000000,
204 ColumnOverflow = 0x80000000,
212 DropHilited = 0x0008,
215 OverlayMask = 0x0F00,
216 StateImageMask = 0xF000,
226 NoRecompute = 0x00000800,
227 GroupId = 0x00000100,
228 Columns = 0x00000200,
291 bool Create(KListModel::Styles style,
const KRect &rect, QWidget *pParentWnd);
305 int nWidth = -1,
int nSubItem = -1);
355 int SetScrollPos(Qt::Orientation orientation,
int pos,
bool bRedraw =
true);
371#ifdef KDWINUTILS_WITHMFC
412 friend class StyledItemDelegate;
421 using ListItem = std::vector<CellData>;
426 Qt::AlignmentFlag alignment;
428 using HeaderItem = std::vector<HeaderData>;
430 QTreeView *m_widget =
nullptr;
431 std::unique_ptr<KItemViewToolTipHandler> m_toolTipHandler;
432 HeaderItem m_headerItem;
434 QList<ListItem> m_data;
436 ExtendedStyles m_extendedStyles {};
442 StyledItemDelegate *m_delegate;
446 CustomPaintFunction m_customPaintFunction;
456template <
typename Class>
458 void (Class::*method)(QPainter *painter,
459 const QStyleOptionViewItem &styleOption,
460 const QModelIndex &index))
463 object, [
object, method](QPainter *painter,
const QStyleOptionViewItem &styleOption,
const QModelIndex &
index) {
464 return (object->*method)(painter, styleOption,
index);
The KDialog class is used to replace MFC KDialog.
Definition kdialog.h:40
The KImageList class defines a list of images, each of the same size.
Definition kimagelist.h:38
The KListModel class is used to replace DDX_Control edit data exchange.
Definition klistmodel.h:66
Position GetFirstSelectedItemPosition() const
Retrieves the position of the first selected list view item in a list view control.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setFilterRegularExpression(const QRegularExpression ®ularExpression)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
int GetSelectedCount() const
Retrieves the number of selected items in the list view control.
bool Create(KListModel::Styles style, const KRect &rect, QWidget *pParentWnd)
Creates a KListModel with the given styles, rect and parent.
void setFilterWildcard(const KString &pattern)
bool GetCheck(int nItem) const
Returns true if the item is checked.
void * GetItemData(int nItem) const
Retrieves the application-specific value associated with an item.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
int InsertItem(int nItem, const KString &lpszItem)
Inserts a new item in a list view control, with the text given in parameter.
Qt::Alignment getColumnAlignment(int col) const
void SetCheckState(int nItem, bool checked)
Set the check status of the item.
KListModel(QObject *parent=nullptr)
int GetItemCount() const
Retrieves the number of items in a list view control.
Q_DECLARE_FLAGS(ExtendedStyles, ExtendedStyle)
int GetScrollPos(Qt::Orientation orientation) const
Retrieves the current position of a scroll box.
StateMask
Definition klistmodel.h:208
KHeaderCtrl * GetHeaderCtrl() const
Retrieves the header control of a list view control.
Qt::ItemFlags flags(const QModelIndex &index) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
bool DeleteAllItems()
Deletes all items from the control.
bool GetColumn(int nCol, ColumnInfo *pColumn) const
Retrieves the attributes of a control's column.
ImageList
Definition klistmodel.h:281
bool DeleteColumn(int nCol)
Deletes a column from the list view control.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
int SubItemHitTest(HitTestInfo *pInfo)
Determines which list view item, if any, is at a given position.
void SetStyle(Styles styles)
Sets the current style used.
bool SortItems(PFNLVCOMPARE fn, std::uintptr_t param)
Sorts list view items using an application-defined comparison function.
bool SetItemState(int nItem, StateMasks nState, StateMasks nMask)
Changes the state of an item in a list view control.
int InsertColumn(int nCol, const KString &lpszColumnHeading, Qt::AlignmentFlag nFormat=Qt::AlignLeft, int nWidth=-1, int nSubItem=-1)
Inserts a new column in a list view control.
ExtendedStyles GetExtendedStyle() const
Retrieves the current extended styles of a list view control.
void SetExtendedStyle(ExtendedStyles styles)
Sets the current extended styles of a list view control.
bool SortItems(KSortFilterProxyModel::SortFunction lessThan)
Sorts list view items using an application-defined comparison function.
void setWidget(QTreeView *widget)
static Qt::AlignmentFlag toQtAlignmentFlag(int nFormat)
KString GetItemText(int nItem, int nSubItem) const
Retrieves the text of a list view item or subitem.
Styles GetStyle() const
Returns the current style used.
void headerClicked(int section)
Signal emitted when the header is clicked.
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
bool SetItemText(int nItem, int nSubItem, const KString &lpszText)
Changes the text of a list view item or subitem.
Style
Definition klistmodel.h:147
ExtendedStyle
Definition klistmodel.h:174
int GetNextSelectedItem(Position &pos) const
Retrieves the index of a list view item position, and the position of the next selected list view ite...
Q_DECLARE_FLAGS(Masks, Mask)
void itemChanged(const ChangedItem &)
Signal emitted when the item has been changed.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
void GetClientRect(KRect *rect) const
Gets the dimensions of the widget.
void setCustomPaintFunction(const CustomPaintFunction &function)
Sets the custom paint function individual items in the list.
bool SetColumnWidth(int nCol, int cx)
Changes the width of a column in report view or list view.
void infoTipRequested(QHelpEvent *, const QModelIndex &)
Signal emitted when the tooltip for an item is requested.
Q_DECLARE_FLAGS(StateMasks, StateMask)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
bool EnsureVisible(int nItem, bool bPartialOK)
Ensures that an item is visible.
Mask
Definition klistmodel.h:220
int InsertItem(const Item *pItem)
Inserts a new item in a list view control.
QTreeView * widget() const
void setFilterRegularExpression(const KString &pattern)
bool SetItemData(int nItem, void *dwData)
Sets the item's application-specific value.
bool GetWindowRect(KRect *r) const
Gets the screen coordinates of widget.
int SetScrollPos(Qt::Orientation orientation, int pos, bool bRedraw=true)
Sets the current position of a scroll box and, if specified, redraws the scroll bar to reflect the ne...
bool SetItem(const Item *pItem)
Sets some or all of a list view item's attributes.
bool GetCheckState(int nItem) const
Returns true if the item is checked.
void contextMenuRequested(QObject *obj, const QPoint &)
Signal emitted when the context menu is requested.
std::function< void(QPainter *, const QStyleOptionViewItem &, const QModelIndex &)> CustomPaintFunction
Definition klistmodel.h:102
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void setFilterFixedString(const KString &pattern)
KImageList * SetImageList(KImageList *pImageList, KListModel::ImageList imageListType)
Assigns an image list to a list view control.
Q_DECLARE_FLAGS(Styles, Style)
QModelIndex parent(const QModelIndex &child) const override
The KRect class defines a rectangle in the plane using integer precision.
Definition krect.h:40
The KSortFilterProxyModel is a QSortFilterProxyModel that allows custom sorting.
Definition ksortfilterproxymodel.h:39
std::function< bool(const QModelIndex &, const QModelIndex &)> SortFunction
Definition ksortfilterproxymodel.h:45
The KString class provides a Unicode character string.
Definition kstring.h:45
#define KDWINUTILS_EXPORT
Definition kdwinutils_export.h:31
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28
The ChangedItem struct contains info on the changed item, it's emitted by KListModel::itemChanged sig...
Definition klistmodel.h:256
int iItem
Definition klistmodel.h:257
int iSubItem
Definition klistmodel.h:258
void * lParam
Definition klistmodel.h:259
The ColumnInfo struct contains information about a column in the list view control.
Definition klistmodel.h:277
KString pszText
Definition klistmodel.h:278
Contains information about a hit test.
Definition klistmodel.h:264
int iItem
Definition klistmodel.h:266
QPoint pt
Definition klistmodel.h:265
int iSubItem
Definition klistmodel.h:267
Contains attributes of a list view item or subitem.
Definition klistmodel.h:240
StateMask stateMask
Specifies which bits of the state member will be retrieved or modified.
Definition klistmodel.h:245
int iIndent
Not handled yet.
Definition klistmodel.h:250
int iImage
The zero-based index of an image within the image list.
Definition klistmodel.h:248
Masks mask
Specifies which members of the structure are valid input.
Definition klistmodel.h:241
KString pszText
The item's text.
Definition klistmodel.h:246
int iSubItem
The column of the item (1 is the first subItem).
Definition klistmodel.h:243
int iItem
The row of the item.
Definition klistmodel.h:242
StateMask state
Specifies the item's state.
Definition klistmodel.h:244
void * lParam
Application-defined item data.
Definition klistmodel.h:249
int cchTextMax
The length of the item string.
Definition klistmodel.h:247
The Position struct is the position of the item in the view.
Definition klistmodel.h:121
friend bool operator==(Position p, std::nullptr_t) noexcept
Definition klistmodel.h:141
friend bool operator!=(Position p, Private::CompareAgainstLiteralZero) noexcept
Definition klistmodel.h:136
friend bool operator!=(Position p, std::nullptr_t) noexcept
Definition klistmodel.h:142
friend bool operator==(Position lhs, Position rhs) noexcept
Definition klistmodel.h:129
Position(int p) noexcept
Definition klistmodel.h:123
friend bool operator==(Position p, Private::CompareAgainstLiteralZero) noexcept
Definition klistmodel.h:132
friend bool operator!=(Position lhs, Position rhs) noexcept
Definition klistmodel.h:130