DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dlistview.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DLISTVIEW_H
6#define DLISTVIEW_H
7
8#include <dtkwidget_global.h>
9
10#include <dobject.h>
11#include <DStyledItemDelegate>
12
13#include <QListView>
14
15DWIDGET_BEGIN_NAMESPACE
16
17class DVariantListModel : public QAbstractListModel
18{
19public:
20 explicit DVariantListModel(QObject *parent = 0);
21
22 int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
23 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
24 bool setData(const QModelIndex &index, const QVariant &value, int role) Q_DECL_OVERRIDE;
25
26 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
27 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
28
29private:
30 QList<QVariant> dataList;
31};
32
34class LIBDTKWIDGETSHARED_EXPORT DListView : public QListView, public DTK_CORE_NAMESPACE::DObject
35{
36 Q_OBJECT
37
39 Q_PROPERTY(int count READ count NOTIFY rowCountChanged)
41 Q_PROPERTY(Qt::Orientation orientation READ orientation NOTIFY orientationChanged)
42 Q_PROPERTY(DStyledItemDelegate::BackgroundType backgroundType READ backgroundType WRITE setBackgroundType)
43 Q_PROPERTY(QMargins itemMargins READ itemMargins WRITE setItemMargins)
44 Q_PROPERTY(QSize itemSize READ itemSize WRITE setItemSize)
45
46public:
47 explicit DListView(QWidget *parent = 0);
48
49 State state() const;
50
51 QWidget *getHeaderWidget(int index) const;
52 QWidget *getFooterWidget(int index) const;
53
55 bool isActiveRect(const QRect &rect) const;
56 bool isVisualRect(const QRect &rect) const;
57
58 int count() const;
59
60 Qt::Orientation orientation() const;
61
62 void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE;
63 QSize minimumSizeHint() const Q_DECL_OVERRIDE;
64
65 DStyledItemDelegate::BackgroundType backgroundType() const;
66 QMargins itemMargins() const;
67 QSize itemSize() const;
68
69 using QListView::contentsSize;
70 using QListView::setViewportMargins;
71
72public Q_SLOTS:
73 bool addItem(const QVariant &data);
74 bool addItems(const QVariantList &datas);
75 bool insertItem(int index, const QVariant &data);
76 bool insertItems(int index, const QVariantList &datas);
77 bool removeItem(int index);
78 bool removeItems(int index, int count);
79
80 int addHeaderWidget(QWidget *widget);
81 void removeHeaderWidget(int index);
82 QWidget *takeHeaderWidget(int index);
83 int addFooterWidget(QWidget *widget);
84 void removeFooterWidget(int index);
85 QWidget *takeFooterWidget(int index);
86
87 void setOrientation(QListView::Flow flow, bool wrapping);
88 void edit(const QModelIndex &index);
89
90 void setBackgroundType(DStyledItemDelegate::BackgroundType backgroundType);
91 void setItemMargins(const QMargins &itemMargins);
92 void setItemSize(QSize itemSize);
93 void setItemSpacing(int spacing);
94 void setItemRadius(int radius);
95
96Q_SIGNALS:
97 void rowCountChanged();
98 void orientationChanged(Qt::Orientation orientation);
99 void currentChanged(const QModelIndex &previous);
100 void triggerEdit(const QModelIndex &index);
101
102protected:
103#if(QT_VERSION < 0x050500)
104 void setViewportMargins(int left, int top, int right, int bottom);
105 void setViewportMargins(const QMargins &margins);
106 QMargins viewportMargins() const;
107#endif
108
109 void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
110 void currentChanged(const QModelIndex &current, const QModelIndex &previous) Q_DECL_OVERRIDE;
111 bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) Q_DECL_OVERRIDE;
112
113#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
114 QStyleOptionViewItem viewOptions() const override;
115#else
116 void initViewItemOption(QStyleOptionViewItem *option) const override;
117#endif
118 virtual QModelIndex moveCursor(CursorAction cursorAction,
119 Qt::KeyboardModifiers modifiers) override;
120 QSize viewportSizeHint() const override;
121 int horizontalOffset() const override;
122
123private:
124 void setFlow(QListView::Flow flow);
125 void setWrapping(bool enable);
126
127 D_DECLARE_PRIVATE(DListView)
128};
129
130DWIDGET_END_NAMESPACE
131
132#endif // DLISTVIEW_H
Definition dlistview_p.h:16
DListView 一个用于展示一列数据的控件.
Definition dlistview.h:35
Definition dstyleditemdelegate.h:65
Definition dlistview.h:18