Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
KListModel Class Reference

The KListModel class is used to replace DDX_Control edit data exchange. More...

#include <klistmodel.h>

Inheritance diagram for KListModel:
[legend]
Collaboration diagram for KListModel:
[legend]

Classes

struct  ChangedItem
 The ChangedItem struct contains info on the changed item, it's emitted by KListModel::itemChanged signal. More...
 
struct  ColumnInfo
 The ColumnInfo struct contains information about a column in the list view control. More...
 
struct  HitTestInfo
 Contains information about a hit test. More...
 
struct  Item
 Contains attributes of a list view item or subitem. More...
 
struct  Position
 The Position struct is the position of the item in the view. More...
 

Public Types

using CustomPaintFunction = std::function<void(QPainter *, const QStyleOptionViewItem &, const QModelIndex &)>
 
enum class  ExtendedStyle : uint {
  GridLines = 0x00000001 , SubItemImages = 0x00000002 , CheckBoxes = 0x00000004 , TrackSelect = 0x00000008 ,
  HeaderDragDrop = 0x00000010 , FullRowSelect = 0x00000020 , OneClickActivate = 0x00000040 , TwoClickActivate = 0x00000080 ,
  FlatSB = 0x00000100 , Regional = 0x00000200 , InfoTip = 0x00000400 , UnderlineHot = 0x00000800 ,
  UnderlineCold = 0x00001000 , MultiWorkAreas = 0x00002000 , LabelTip = 0x00004000 , BorderSelect = 0x00008000 ,
  DoubleBuffer = 0x00010000 , HideLabels = 0x00020000 , SingleRow = 0x00040000 , SnapToGrid = 0x00080000 ,
  SimpleSelect = 0x00100000 , JustifyColumns = 0x00200000 , TransparentBkgnd = 0x00400000 , TransparentShadowText = 0x00800000 ,
  AutoAutoArrange = 0x01000000 , HeaderInAllViews = 0x02000000 , AutoCheckSelect = 0x08000000 , AutoSizeColumns = 0x10000000 ,
  ColumnSnapPoints = 0x40000000 , ColumnOverflow = 0x80000000
}
 
enum class  ImageList { Normal , Small , State }
 
enum class  Mask : uint {
  Text = 0x00000001 , Image = 0x00000002 , Param = 0x00000004 , State = 0x00000008 ,
  Indent = 0x00000010 , NoRecompute = 0x00000800 , GroupId = 0x00000100 , Columns = 0x00000200 ,
  ColFmt = 0x00010000
}
 
enum class  StateMask : uint {
  Focused = 0x0001 , Selected = 0x0002 , Cut = 0x0004 , DropHilited = 0x0008 ,
  Glow = 0x0010 , Activating = 0x0020 , OverlayMask = 0x0F00 , StateImageMask = 0xF000
}
 
enum class  Style : uint {
  Icon = 0x00000001 , Report = 0x00000002 , SmallIcon = 0x00000004 , List = 0x00000008 ,
  TypeMask = 0x00000008 , SingleSel , ShowSelAlways = 0x00000020 , SortAscending = 0x00000040 ,
  SortDescending = 0x00000080 , ShareImageLists = 0x00000100 , NoLabelWrap = 0x00000200 , AutoArrange = 0x00000400 ,
  EditLabels = 0x00000800 , OwnerData = 0x00001000 , NoScroll = 0x00002000 , TypeStyleMask = 0x00004000 ,
  AlignTop = 0x00000001 , AlignLeft = 0x00008000 , AlignMask = 0x00010000 , OwnerDrawFixed = 0x00020000 ,
  NoColumnHeader = 0x00040000 , NoSortHeader = 0x00080000
}
 

Public Slots

void setFilterFixedString (const KString &pattern)
 
void setFilterRegularExpression (const KString &pattern)
 
void setFilterRegularExpression (const QRegularExpression &regularExpression)
 
void setFilterWildcard (const KString &pattern)
 

Signals

void contextMenuRequested (QObject *obj, const QPoint &)
 Signal emitted when the context menu is requested.
 
void headerClicked (int section)
 Signal emitted when the header is clicked.
 
void infoTipRequested (QHelpEvent *, const QModelIndex &)
 Signal emitted when the tooltip for an item is requested.
 
void itemChanged (const ChangedItem &)
 Signal emitted when the item has been changed.
 

Public Member Functions

int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
bool Create (KListModel::Styles style, const KRect &rect, QWidget *pParentWnd)
 Creates a KListModel with the given styles, rect and parent.
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
bool DeleteAllItems ()
 Deletes all items from the control.
 
bool DeleteColumn (int nCol)
 Deletes a column from the list view control.
 
bool EnsureVisible (int nItem, bool bPartialOK)
 Ensures that an item is visible.
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
bool GetCheck (int nItem) const
 Returns true if the item is checked.
 
bool GetCheckState (int nItem) const
 Returns true if the item is checked.
 
void GetClientRect (KRect *rect) const
 Gets the dimensions of the widget.
 
bool GetColumn (int nCol, ColumnInfo *pColumn) const
 Retrieves the attributes of a control's column.
 
Qt::Alignment getColumnAlignment (int col) const
 
ExtendedStyles GetExtendedStyle () const
 Retrieves the current extended styles of a list view control.
 
Position GetFirstSelectedItemPosition () const
 Retrieves the position of the first selected list view item in a list view control.
 
KHeaderCtrlGetHeaderCtrl () const
 Retrieves the header control of a list view control.
 
int GetItemCount () const
 Retrieves the number of items in a list view control.
 
void * GetItemData (int nItem) const
 Retrieves the application-specific value associated with an item.
 
KString GetItemText (int nItem, int nSubItem) const
 Retrieves the text of a list view item or subitem.
 
int GetNextSelectedItem (Position &pos) const
 Retrieves the index of a list view item position, and the position of the next selected list view item for iterating.
 
int GetScrollPos (Qt::Orientation orientation) const
 Retrieves the current position of a scroll box.
 
int GetSelectedCount () const
 Retrieves the number of selected items in the list view control.
 
Styles GetStyle () const
 Returns the current style used.
 
bool GetWindowRect (KRect *r) const
 Gets the screen coordinates of widget.
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
 
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.
 
int InsertItem (const Item *pItem)
 Inserts a new item in a list view control.
 
int InsertItem (int nItem, const KString &lpszItem)
 Inserts a new item in a list view control, with the text given in parameter.
 
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) override
 
 KListModel (QObject *parent=nullptr)
 
QModelIndex mapFromSource (const QModelIndex &sourceIndex) const
 
QModelIndex mapToSource (const QModelIndex &proxyIndex) const
 
QModelIndex parent (const QModelIndex &child) const override
 
 Q_DECLARE_FLAGS (ExtendedStyles, ExtendedStyle)
 
 Q_DECLARE_FLAGS (Masks, Mask)
 
 Q_DECLARE_FLAGS (StateMasks, StateMask)
 
 Q_DECLARE_FLAGS (Styles, Style)
 
 Q_ENUM (ImageList)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
void SetCheckState (int nItem, bool checked)
 Set the check status of the item.
 
bool SetColumnWidth (int nCol, int cx)
 Changes the width of a column in report view or list view.
 
template<typename Class >
void setCustomPaintFunction (Class *object, void(Class::*method)(QPainter *painter, const QStyleOptionViewItem &styleOption, const QModelIndex &index))
 Sets the custom paint function individual items in the list.
 
void setCustomPaintFunction (const CustomPaintFunction &function)
 Sets the custom paint function individual items in the list.
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
void SetExtendedStyle (ExtendedStyles styles)
 Sets the current extended styles of a list view control.
 
KImageListSetImageList (KImageList *pImageList, KListModel::ImageList imageListType)
 Assigns an image list to a list view control.
 
bool SetItem (const Item *pItem)
 Sets some or all of a list view item's attributes.
 
bool SetItemData (int nItem, void *dwData)
 Sets the item's application-specific value.
 
bool SetItemState (int nItem, StateMasks nState, StateMasks nMask)
 Changes the state of an item in a list view control.
 
bool SetItemText (int nItem, int nSubItem, const KString &lpszText)
 Changes the text of a list view item or subitem.
 
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 new position.
 
void SetStyle (Styles styles)
 Sets the current style used.
 
void setWidget (QTreeView *widget)
 
bool SortItems (KSortFilterProxyModel::SortFunction lessThan)
 Sorts list view items using an application-defined comparison function.
 
bool SortItems (PFNLVCOMPARE fn, std::uintptr_t param)
 Sorts list view items using an application-defined comparison function.
 
int SubItemHitTest (HitTestInfo *pInfo)
 Determines which list view item, if any, is at a given position.
 
QTreeView * widget () const
 
 ~KListModel ()
 

Static Public Member Functions

static Qt::AlignmentFlag toQtAlignmentFlag (int nFormat)
 

Friends

class KHeaderCtrl
 
class StyledItemDelegate
 

Detailed Description

The KListModel class is used to replace DDX_Control edit data exchange.

This class is the equivalent of CListCtrl in MFC, in report mode (LVS_REPORT style). The KListModel is a model (QABStractItemModel) and can be used as is with any views). Some methods requires you to set a QTreeView as the view.

Internally, the model also contains a QProxyModel to handle sorting and filtering:

  • KListModel model
  • QSortFilterProxyModel model
  • QTreeView view

This should be completely transparent when using the class.

See also
https://learn.microsoft.com/en-us/cpp/mfc/reference/clistctrl-class
https://doc.qt.io/qt-6/qabstractitemmodel.html

Member Typedef Documentation

◆ CustomPaintFunction

using KListModel::CustomPaintFunction = std::function<void(QPainter *, const QStyleOptionViewItem &, const QModelIndex &)>

Member Enumeration Documentation

◆ ExtendedStyle

enum class KListModel::ExtendedStyle : uint
strong
Enumerator
GridLines 
SubItemImages 

Not handled yet.

CheckBoxes 

Enables check boes for items in a listview.

TrackSelect 

Not handled yet.

HeaderDragDrop 

Not handled yet.

FullRowSelect 
OneClickActivate 

Not handled yet.

TwoClickActivate 

Not handled yet.

FlatSB 

Not handled yet.

Regional 

Not handled yet.

InfoTip 
UnderlineHot 

Not handled yet.

UnderlineCold 

Not handled yet.

MultiWorkAreas 

Not handled yet.

LabelTip 

Not handled yet.

BorderSelect 

Not handled yet.

DoubleBuffer 

Not handled yet.

HideLabels 

Not handled yet.

SingleRow 

Not handled yet.

SnapToGrid 

Not handled yet.

SimpleSelect 

Not handled yet.

JustifyColumns 

Not handled yet.

TransparentBkgnd 

Not handled yet.

TransparentShadowText 

Not handled yet.

AutoAutoArrange 

Not handled yet.

HeaderInAllViews 

Not handled yet.

AutoCheckSelect 

Not handled yet.

AutoSizeColumns 

Not handled yet.

ColumnSnapPoints 

Not handled yet.

ColumnOverflow 

Not handled yet.

◆ ImageList

enum class KListModel::ImageList
strong
Enumerator
Normal 
Small 
State 

◆ Mask

enum class KListModel::Mask : uint
strong
Enumerator
Text 

The pszText member is valid or must be set.

Image 

Not handled yet.

Param 

Not handled yet.

State 

Not handled yet.

Indent 

Not handled yet.

NoRecompute 

Not handled yet.

GroupId 

Not handled yet.

Columns 

Not handled yet.

ColFmt 

Not handled yet.

◆ StateMask

enum class KListModel::StateMask : uint
strong
Enumerator
Focused 
Selected 
Cut 
DropHilited 
Glow 
Activating 
OverlayMask 
StateImageMask 

◆ Style

enum class KListModel::Style : uint
strong
Enumerator
Icon 

Not handled yet. This style specifies icon view.

Report 

Default. This style specifies report view.

SmallIcon 

Not handled yet. This style specifies small icon view.

List 

Not handled yet. This style specifies list view.

TypeMask 

Not handled yet.

SingleSel 

Only one item at a time can be selected. By default, multiple items may be selected.

ShowSelAlways 

Not handled yet.

SortAscending 

Not handled yet.

SortDescending 

Not handled yet.

ShareImageLists 

Not handled yet.

NoLabelWrap 

Not handled yet.

AutoArrange 

Not handled yet.

EditLabels 

Not handled yet.

OwnerData 

Not handled yet.

NoScroll 

Not handled yet.

TypeStyleMask 

Not handled yet.

AlignTop 

Not handled yet.

AlignLeft 

Not handled yet.

AlignMask 

Not handled yet.

OwnerDrawFixed 

Not handled yet.

NoColumnHeader 

Column headers are not displayed in report view.

NoSortHeader 

Column headers are not clickable.

Constructor & Destructor Documentation

◆ KListModel()

KListModel::KListModel ( QObject * parent = nullptr)
explicit

◆ ~KListModel()

KListModel::~KListModel ( )

Member Function Documentation

◆ columnCount()

int KListModel::columnCount ( const QModelIndex & parent = QModelIndex()) const
override

◆ contextMenuRequested

void KListModel::contextMenuRequested ( QObject * obj,
const QPoint &  )
signal

Signal emitted when the context menu is requested.

The object is the item that was clicked on (either the KHeaderCtrl or treeview widget), and the point is the position of the click.

◆ Create()

bool KListModel::Create ( KListModel::Styles style,
const KRect & rect,
QWidget * pParentWnd )

Creates a KListModel with the given styles, rect and parent.

◆ data()

QVariant KListModel::data ( const QModelIndex & index,
int role = Qt::DisplayRole ) const
override

◆ DeleteAllItems()

bool KListModel::DeleteAllItems ( )

Deletes all items from the control.

◆ DeleteColumn()

bool KListModel::DeleteColumn ( int nCol)

Deletes a column from the list view control.

◆ EnsureVisible()

bool KListModel::EnsureVisible ( int nItem,
bool bPartialOK )

Ensures that an item is visible.

◆ flags()

Qt::ItemFlags KListModel::flags ( const QModelIndex & index) const
override

◆ GetCheck()

bool KListModel::GetCheck ( int nItem) const

Returns true if the item is checked.

◆ GetCheckState()

bool KListModel::GetCheckState ( int nItem) const

Returns true if the item is checked.

◆ GetClientRect()

void KListModel::GetClientRect ( KRect * rect) const

Gets the dimensions of the widget.

◆ GetColumn()

bool KListModel::GetColumn ( int nCol,
ColumnInfo * pColumn ) const

Retrieves the attributes of a control's column.

◆ getColumnAlignment()

Qt::Alignment KListModel::getColumnAlignment ( int col) const

Gets the column alignment for the given column.

◆ GetExtendedStyle()

ExtendedStyles KListModel::GetExtendedStyle ( ) const

Retrieves the current extended styles of a list view control.

◆ GetFirstSelectedItemPosition()

Position KListModel::GetFirstSelectedItemPosition ( ) const

Retrieves the position of the first selected list view item in a list view control.

◆ GetHeaderCtrl()

KHeaderCtrl * KListModel::GetHeaderCtrl ( ) const

Retrieves the header control of a list view control.

◆ GetItemCount()

int KListModel::GetItemCount ( ) const

Retrieves the number of items in a list view control.

◆ GetItemData()

void * KListModel::GetItemData ( int nItem) const

Retrieves the application-specific value associated with an item.

◆ GetItemText()

KString KListModel::GetItemText ( int nItem,
int nSubItem ) const

Retrieves the text of a list view item or subitem.

◆ GetNextSelectedItem()

int KListModel::GetNextSelectedItem ( Position & pos) const

Retrieves the index of a list view item position, and the position of the next selected list view item for iterating.

◆ GetScrollPos()

int KListModel::GetScrollPos ( Qt::Orientation orientation) const

Retrieves the current position of a scroll box.

◆ GetSelectedCount()

int KListModel::GetSelectedCount ( ) const

Retrieves the number of selected items in the list view control.

◆ GetStyle()

Styles KListModel::GetStyle ( ) const

Returns the current style used.

◆ GetWindowRect()

bool KListModel::GetWindowRect ( KRect * r) const

Gets the screen coordinates of widget.

◆ headerClicked

void KListModel::headerClicked ( int section)
signal

Signal emitted when the header is clicked.

◆ headerData()

QVariant KListModel::headerData ( int section,
Qt::Orientation orientation,
int role = Qt::DisplayRole ) const
override

◆ index()

QModelIndex KListModel::index ( int row,
int column,
const QModelIndex & parent = QModelIndex() ) const
override

◆ infoTipRequested

void KListModel::infoTipRequested ( QHelpEvent * ,
const QModelIndex &  )
signal

Signal emitted when the tooltip for an item is requested.

◆ InsertColumn()

int KListModel::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.

◆ InsertItem() [1/2]

int KListModel::InsertItem ( const Item * pItem)

Inserts a new item in a list view control.

◆ InsertItem() [2/2]

int KListModel::InsertItem ( int nItem,
const KString & lpszItem )

Inserts a new item in a list view control, with the text given in parameter.

◆ insertRows()

bool KListModel::insertRows ( int row,
int count,
const QModelIndex & parent = QModelIndex() )
override

◆ itemChanged

void KListModel::itemChanged ( const ChangedItem & )
signal

Signal emitted when the item has been changed.

◆ mapFromSource()

QModelIndex KListModel::mapFromSource ( const QModelIndex & sourceIndex) const

Maps the model index to the proxy index.

◆ mapToSource()

QModelIndex KListModel::mapToSource ( const QModelIndex & proxyIndex) const

Maps the proxy index to the model index.

◆ parent()

QModelIndex KListModel::parent ( const QModelIndex & child) const
override

◆ Q_DECLARE_FLAGS() [1/4]

KListModel::Q_DECLARE_FLAGS ( ExtendedStyles ,
ExtendedStyle  )

◆ Q_DECLARE_FLAGS() [2/4]

KListModel::Q_DECLARE_FLAGS ( Masks ,
Mask  )

◆ Q_DECLARE_FLAGS() [3/4]

KListModel::Q_DECLARE_FLAGS ( StateMasks ,
StateMask  )

◆ Q_DECLARE_FLAGS() [4/4]

KListModel::Q_DECLARE_FLAGS ( Styles ,
Style  )

◆ Q_ENUM()

KListModel::Q_ENUM ( ImageList )

◆ rowCount()

int KListModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
override

◆ SetCheckState()

void KListModel::SetCheckState ( int nItem,
bool checked )

Set the check status of the item.

◆ SetColumnWidth()

bool KListModel::SetColumnWidth ( int nCol,
int cx )

Changes the width of a column in report view or list view.

◆ setCustomPaintFunction() [1/2]

template<typename Class >
void KListModel::setCustomPaintFunction ( Class * object,
void(Class::* method )(QPainter *painter, const QStyleOptionViewItem &styleOption, const QModelIndex &index) )
inline

Sets the custom paint function individual items in the list.

◆ setCustomPaintFunction() [2/2]

void KListModel::setCustomPaintFunction ( const CustomPaintFunction & function)

Sets the custom paint function individual items in the list.

The function is called for each item in the list. It overrides the default painting code.

◆ setData()

bool KListModel::setData ( const QModelIndex & index,
const QVariant & value,
int role )
override

◆ SetExtendedStyle()

void KListModel::SetExtendedStyle ( ExtendedStyles styles)

Sets the current extended styles of a list view control.

◆ setFilterFixedString

void KListModel::setFilterFixedString ( const KString & pattern)
slot

Sets the fixed string used to filter the contents of the source model to the given pattern.

◆ setFilterRegularExpression [1/2]

void KListModel::setFilterRegularExpression ( const KString & pattern)
slot

Sets the regular expression used to filter the contents of the source model to pattern.

◆ setFilterRegularExpression [2/2]

void KListModel::setFilterRegularExpression ( const QRegularExpression & regularExpression)
slot

Sets the regular expression used to filter the contents of the source model to pattern.

◆ setFilterWildcard

void KListModel::setFilterWildcard ( const KString & pattern)
slot

Sets the wildcard expression used to filter the contents of the source model to the given pattern.

◆ SetImageList()

KImageList * KListModel::SetImageList ( KImageList * pImageList,
KListModel::ImageList imageListType )

Assigns an image list to a list view control.

◆ SetItem()

bool KListModel::SetItem ( const Item * pItem)

Sets some or all of a list view item's attributes.

◆ SetItemData()

bool KListModel::SetItemData ( int nItem,
void * dwData )

Sets the item's application-specific value.

◆ SetItemState()

bool KListModel::SetItemState ( int nItem,
StateMasks nState,
StateMasks nMask )

Changes the state of an item in a list view control.

◆ SetItemText()

bool KListModel::SetItemText ( int nItem,
int nSubItem,
const KString & lpszText )

Changes the text of a list view item or subitem.

◆ SetScrollPos()

int KListModel::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 new position.

◆ SetStyle()

void KListModel::SetStyle ( Styles styles)

Sets the current style used.

◆ setWidget()

void KListModel::setWidget ( QTreeView * widget)

Sets the view of the class.

◆ SortItems() [1/2]

bool KListModel::SortItems ( KSortFilterProxyModel::SortFunction lessThan)

Sorts list view items using an application-defined comparison function.

◆ SortItems() [2/2]

bool KListModel::SortItems ( PFNLVCOMPARE fn,
std::uintptr_t param )

Sorts list view items using an application-defined comparison function.

This method is used to replace SortItems from MFC. Should be replaced in a non-MFC project.

◆ SubItemHitTest()

int KListModel::SubItemHitTest ( HitTestInfo * pInfo)

Determines which list view item, if any, is at a given position.

◆ toQtAlignmentFlag()

static Qt::AlignmentFlag KListModel::toQtAlignmentFlag ( int nFormat)
static

Transforms MFC alignment format into Qt format.

◆ widget()

QTreeView * KListModel::widget ( ) const

Returns the view of the class.

Friends And Related Symbol Documentation

◆ KHeaderCtrl

friend class KHeaderCtrl
friend

◆ StyledItemDelegate

friend class StyledItemDelegate
friend

The documentation for this class was generated from the following file: