KDWinUtils
Helper library for MFC to Qt migration
|
The KListModel class is used to replace DDX_Control edit data exchange. More...
#include <klistmodel.h>
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 ®ularExpression) |
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. | |
KHeaderCtrl * | GetHeaderCtrl () 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. | |
KImageList * | SetImageList (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 |
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:
This should be completely transparent when using the class.
using KListModel::CustomPaintFunction = std::function<void(QPainter *, const QStyleOptionViewItem &, const QModelIndex &)> |
|
strong |
|
strong |
|
strong |
|
strong |
|
strong |
|
explicit |
KListModel::~KListModel | ( | ) |
|
override |
|
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.
bool KListModel::Create | ( | KListModel::Styles | style, |
const KRect & | rect, | ||
QWidget * | pParentWnd ) |
Creates a KListModel with the given styles, rect and parent.
|
override |
bool KListModel::DeleteAllItems | ( | ) |
Deletes all items from the control.
bool KListModel::DeleteColumn | ( | int | nCol | ) |
Deletes a column from the list view control.
bool KListModel::EnsureVisible | ( | int | nItem, |
bool | bPartialOK ) |
Ensures that an item is visible.
|
override |
bool KListModel::GetCheck | ( | int | nItem | ) | const |
Returns true if the item is checked.
bool KListModel::GetCheckState | ( | int | nItem | ) | const |
Returns true if the item is checked.
void KListModel::GetClientRect | ( | KRect * | rect | ) | const |
Gets the dimensions of the widget.
bool KListModel::GetColumn | ( | int | nCol, |
ColumnInfo * | pColumn ) const |
Retrieves the attributes of a control's column.
Qt::Alignment KListModel::getColumnAlignment | ( | int | col | ) | const |
Gets the column alignment for the given column.
ExtendedStyles KListModel::GetExtendedStyle | ( | ) | const |
Retrieves the current extended styles of a list view control.
Position KListModel::GetFirstSelectedItemPosition | ( | ) | const |
Retrieves the position of the first selected list view item in a list view control.
KHeaderCtrl * KListModel::GetHeaderCtrl | ( | ) | const |
Retrieves the header control of a list view control.
int KListModel::GetItemCount | ( | ) | const |
Retrieves the number of items in a list view control.
void * KListModel::GetItemData | ( | int | nItem | ) | const |
Retrieves the application-specific value associated with an item.
KString KListModel::GetItemText | ( | int | nItem, |
int | nSubItem ) const |
Retrieves the text of a list view item or subitem.
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.
int KListModel::GetScrollPos | ( | Qt::Orientation | orientation | ) | const |
Retrieves the current position of a scroll box.
int KListModel::GetSelectedCount | ( | ) | const |
Retrieves the number of selected items in the list view control.
Styles KListModel::GetStyle | ( | ) | const |
Returns the current style used.
bool KListModel::GetWindowRect | ( | KRect * | r | ) | const |
Gets the screen coordinates of widget.
|
signal |
Signal emitted when the header is clicked.
|
override |
|
override |
|
signal |
Signal emitted when the tooltip for an item is requested.
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.
int KListModel::InsertItem | ( | const Item * | pItem | ) |
Inserts a new item in a list view control.
int KListModel::InsertItem | ( | int | nItem, |
const KString & | lpszItem ) |
Inserts a new item in a list view control, with the text given in parameter.
|
override |
|
signal |
Signal emitted when the item has been changed.
QModelIndex KListModel::mapFromSource | ( | const QModelIndex & | sourceIndex | ) | const |
Maps the model index to the proxy index.
QModelIndex KListModel::mapToSource | ( | const QModelIndex & | proxyIndex | ) | const |
Maps the proxy index to the model index.
|
override |
KListModel::Q_DECLARE_FLAGS | ( | ExtendedStyles | , |
ExtendedStyle | ) |
KListModel::Q_DECLARE_FLAGS | ( | Masks | , |
Mask | ) |
KListModel::Q_DECLARE_FLAGS | ( | StateMasks | , |
StateMask | ) |
KListModel::Q_DECLARE_FLAGS | ( | Styles | , |
Style | ) |
KListModel::Q_ENUM | ( | ImageList | ) |
|
override |
void KListModel::SetCheckState | ( | int | nItem, |
bool | checked ) |
Set the check status of the item.
bool KListModel::SetColumnWidth | ( | int | nCol, |
int | cx ) |
Changes the width of a column in report view or list view.
|
inline |
Sets the custom paint function individual items in the list.
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.
|
override |
void KListModel::SetExtendedStyle | ( | ExtendedStyles | styles | ) |
Sets the current extended styles of a list view control.
|
slot |
Sets the fixed string used to filter the contents of the source model to the given pattern.
|
slot |
Sets the regular expression used to filter the contents of the source model to pattern.
|
slot |
Sets the regular expression used to filter the contents of the source model to pattern.
|
slot |
Sets the wildcard expression used to filter the contents of the source model to the given pattern.
KImageList * KListModel::SetImageList | ( | KImageList * | pImageList, |
KListModel::ImageList | imageListType ) |
Assigns an image list to a list view control.
bool KListModel::SetItem | ( | const Item * | pItem | ) |
Sets some or all of a list view item's attributes.
bool KListModel::SetItemData | ( | int | nItem, |
void * | dwData ) |
Sets the item's application-specific value.
bool KListModel::SetItemState | ( | int | nItem, |
StateMasks | nState, | ||
StateMasks | nMask ) |
Changes the state of an item in a list view control.
bool KListModel::SetItemText | ( | int | nItem, |
int | nSubItem, | ||
const KString & | lpszText ) |
Changes the text of a list view item or subitem.
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.
void KListModel::SetStyle | ( | Styles | styles | ) |
Sets the current style used.
void KListModel::setWidget | ( | QTreeView * | widget | ) |
Sets the view of the class.
bool KListModel::SortItems | ( | KSortFilterProxyModel::SortFunction | lessThan | ) |
Sorts list view items using an application-defined comparison function.
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.
int KListModel::SubItemHitTest | ( | HitTestInfo * | pInfo | ) |
Determines which list view item, if any, is at a given position.
|
static |
Transforms MFC alignment format into Qt format.
QTreeView * KListModel::widget | ( | ) | const |
Returns the view of the class.
|
friend |
|
friend |