Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:09:31

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QABSTRACTITEMVIEW_H
0005 #define QABSTRACTITEMVIEW_H
0006 
0007 #include <QtWidgets/qtwidgetsglobal.h>
0008 #include <QtWidgets/qabstractscrollarea.h>
0009 #include <QtCore/qabstractitemmodel.h>
0010 #include <QtCore/qitemselectionmodel.h>
0011 #include <QtWidgets/qabstractitemdelegate.h>
0012 
0013 class tst_QAbstractItemView;
0014 class tst_QTreeView;
0015 
0016 QT_REQUIRE_CONFIG(itemviews);
0017 
0018 QT_BEGIN_NAMESPACE
0019 
0020 class QMenu;
0021 class QDrag;
0022 class QEvent;
0023 class QAbstractItemViewPrivate;
0024 
0025 class Q_WIDGETS_EXPORT QAbstractItemView : public QAbstractScrollArea
0026 {
0027     Q_OBJECT
0028     Q_PROPERTY(bool autoScroll READ hasAutoScroll WRITE setAutoScroll)
0029     Q_PROPERTY(int autoScrollMargin READ autoScrollMargin WRITE setAutoScrollMargin)
0030     Q_PROPERTY(EditTriggers editTriggers READ editTriggers WRITE setEditTriggers)
0031     Q_PROPERTY(bool tabKeyNavigation READ tabKeyNavigation WRITE setTabKeyNavigation)
0032 #if QT_CONFIG(draganddrop)
0033     Q_PROPERTY(bool showDropIndicator READ showDropIndicator WRITE setDropIndicatorShown)
0034     Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
0035     Q_PROPERTY(bool dragDropOverwriteMode READ dragDropOverwriteMode WRITE setDragDropOverwriteMode)
0036     Q_PROPERTY(DragDropMode dragDropMode READ dragDropMode WRITE setDragDropMode)
0037     Q_PROPERTY(Qt::DropAction defaultDropAction READ defaultDropAction WRITE setDefaultDropAction)
0038 #endif
0039     Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors)
0040     Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
0041     Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior
0042                WRITE setSelectionBehavior)
0043     Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
0044     Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode)
0045     Q_PROPERTY(ScrollMode verticalScrollMode READ verticalScrollMode WRITE setVerticalScrollMode
0046                RESET resetVerticalScrollMode)
0047     Q_PROPERTY(ScrollMode horizontalScrollMode READ horizontalScrollMode
0048                WRITE setHorizontalScrollMode RESET resetHorizontalScrollMode)
0049 
0050 public:
0051     enum SelectionMode {
0052         NoSelection,
0053         SingleSelection,
0054         MultiSelection,
0055         ExtendedSelection,
0056         ContiguousSelection
0057     };
0058     Q_ENUM(SelectionMode)
0059 
0060     enum SelectionBehavior {
0061         SelectItems,
0062         SelectRows,
0063         SelectColumns
0064     };
0065     Q_ENUM(SelectionBehavior)
0066 
0067     enum ScrollHint {
0068         EnsureVisible,
0069         PositionAtTop,
0070         PositionAtBottom,
0071         PositionAtCenter
0072     };
0073     Q_ENUM(ScrollHint)
0074 
0075     enum EditTrigger {
0076         NoEditTriggers = 0,
0077         CurrentChanged = 1,
0078         DoubleClicked = 2,
0079         SelectedClicked = 4,
0080         EditKeyPressed = 8,
0081         AnyKeyPressed = 16,
0082         AllEditTriggers = 31
0083     };
0084 
0085     Q_DECLARE_FLAGS(EditTriggers, EditTrigger)
0086     Q_FLAG(EditTriggers)
0087 
0088     enum ScrollMode {
0089         ScrollPerItem,
0090         ScrollPerPixel
0091     };
0092     Q_ENUM(ScrollMode)
0093 
0094     explicit QAbstractItemView(QWidget *parent = nullptr);
0095     ~QAbstractItemView();
0096 
0097     virtual void setModel(QAbstractItemModel *model);
0098     QAbstractItemModel *model() const;
0099 
0100     virtual void setSelectionModel(QItemSelectionModel *selectionModel);
0101     QItemSelectionModel *selectionModel() const;
0102 
0103     void setItemDelegate(QAbstractItemDelegate *delegate);
0104     QAbstractItemDelegate *itemDelegate() const;
0105 
0106     void setSelectionMode(QAbstractItemView::SelectionMode mode);
0107     QAbstractItemView::SelectionMode selectionMode() const;
0108 
0109     void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior);
0110     QAbstractItemView::SelectionBehavior selectionBehavior() const;
0111 
0112     QModelIndex currentIndex() const;
0113     QModelIndex rootIndex() const;
0114 
0115     void setEditTriggers(EditTriggers triggers);
0116     EditTriggers editTriggers() const;
0117 
0118     void setVerticalScrollMode(ScrollMode mode);
0119     ScrollMode verticalScrollMode() const;
0120     void resetVerticalScrollMode();
0121 
0122     void setHorizontalScrollMode(ScrollMode mode);
0123     ScrollMode horizontalScrollMode() const;
0124     void resetHorizontalScrollMode();
0125 
0126     void setAutoScroll(bool enable);
0127     bool hasAutoScroll() const;
0128 
0129     void setAutoScrollMargin(int margin);
0130     int autoScrollMargin() const;
0131 
0132     void setTabKeyNavigation(bool enable);
0133     bool tabKeyNavigation() const;
0134 
0135 #if QT_CONFIG(draganddrop)
0136     void setDropIndicatorShown(bool enable);
0137     bool showDropIndicator() const;
0138 
0139     void setDragEnabled(bool enable);
0140     bool dragEnabled() const;
0141 
0142     void setDragDropOverwriteMode(bool overwrite);
0143     bool dragDropOverwriteMode() const;
0144 
0145     enum DragDropMode {
0146         NoDragDrop,
0147         DragOnly,
0148         DropOnly,
0149         DragDrop,
0150         InternalMove
0151     };
0152     Q_ENUM(DragDropMode)
0153 
0154     void setDragDropMode(DragDropMode behavior);
0155     DragDropMode dragDropMode() const;
0156 
0157     void setDefaultDropAction(Qt::DropAction dropAction);
0158     Qt::DropAction defaultDropAction() const;
0159 #endif
0160 
0161     void setAlternatingRowColors(bool enable);
0162     bool alternatingRowColors() const;
0163 
0164     void setIconSize(const QSize &size);
0165     QSize iconSize() const;
0166 
0167     void setTextElideMode(Qt::TextElideMode mode);
0168     Qt::TextElideMode textElideMode() const;
0169 
0170     virtual void keyboardSearch(const QString &search);
0171 
0172     virtual QRect visualRect(const QModelIndex &index) const = 0;
0173     virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) = 0;
0174     virtual QModelIndex indexAt(const QPoint &point) const = 0;
0175 
0176     QSize sizeHintForIndex(const QModelIndex &index) const;
0177     virtual int sizeHintForRow(int row) const;
0178     virtual int sizeHintForColumn(int column) const;
0179 
0180     void openPersistentEditor(const QModelIndex &index);
0181     void closePersistentEditor(const QModelIndex &index);
0182     bool isPersistentEditorOpen(const QModelIndex &index) const;
0183 
0184     void setIndexWidget(const QModelIndex &index, QWidget *widget);
0185     QWidget *indexWidget(const QModelIndex &index) const;
0186 
0187     void setItemDelegateForRow(int row, QAbstractItemDelegate *delegate);
0188     QAbstractItemDelegate *itemDelegateForRow(int row) const;
0189 
0190     void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate);
0191     QAbstractItemDelegate *itemDelegateForColumn(int column) const;
0192 
0193 #if QT_DEPRECATED_SINCE(6, 0)
0194     QT_DEPRECATED_VERSION_X_6_0("Use itemDelegateForIndex instead")
0195     QAbstractItemDelegate *itemDelegate(const QModelIndex &index) const
0196     { return itemDelegateForIndex(index); }
0197 #endif
0198     virtual QAbstractItemDelegate *itemDelegateForIndex(const QModelIndex &index) const;
0199 
0200     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
0201 
0202     using QAbstractScrollArea::update;
0203 
0204 public Q_SLOTS:
0205     virtual void reset();
0206     virtual void setRootIndex(const QModelIndex &index);
0207     virtual void doItemsLayout();
0208     virtual void selectAll();
0209     void edit(const QModelIndex &index);
0210     void clearSelection();
0211     void setCurrentIndex(const QModelIndex &index);
0212     void scrollToTop();
0213     void scrollToBottom();
0214     void update(const QModelIndex &index);
0215 
0216 protected Q_SLOTS:
0217     virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
0218                              const QList<int> &roles = QList<int>());
0219     virtual void rowsInserted(const QModelIndex &parent, int start, int end);
0220     virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
0221     virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
0222     virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
0223     virtual void updateEditorData();
0224     virtual void updateEditorGeometries();
0225     virtual void updateGeometries();
0226     virtual void verticalScrollbarAction(int action);
0227     virtual void horizontalScrollbarAction(int action);
0228     virtual void verticalScrollbarValueChanged(int value);
0229     virtual void horizontalScrollbarValueChanged(int value);
0230     virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
0231     virtual void commitData(QWidget *editor);
0232     virtual void editorDestroyed(QObject *editor);
0233 
0234 Q_SIGNALS:
0235     void pressed(const QModelIndex &index);
0236     void clicked(const QModelIndex &index);
0237     void doubleClicked(const QModelIndex &index);
0238 
0239     void activated(const QModelIndex &index);
0240     void entered(const QModelIndex &index);
0241     void viewportEntered();
0242 
0243     void iconSizeChanged(const QSize &size);
0244 
0245 protected:
0246     QAbstractItemView(QAbstractItemViewPrivate &, QWidget *parent = nullptr);
0247 
0248     enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight,
0249                         MoveHome, MoveEnd, MovePageUp, MovePageDown,
0250                         MoveNext, MovePrevious };
0251     virtual QModelIndex moveCursor(CursorAction cursorAction,
0252                                    Qt::KeyboardModifiers modifiers) = 0;
0253 
0254     virtual int horizontalOffset() const = 0;
0255     virtual int verticalOffset() const = 0;
0256 
0257     virtual bool isIndexHidden(const QModelIndex &index) const = 0;
0258 
0259     virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) = 0;
0260     virtual QRegion visualRegionForSelection(const QItemSelection &selection) const = 0;
0261     virtual QModelIndexList selectedIndexes() const;
0262 
0263     virtual bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event);
0264 
0265     virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index,
0266                                                                  const QEvent *event = nullptr) const;
0267 
0268 #if QT_CONFIG(draganddrop)
0269     virtual void startDrag(Qt::DropActions supportedActions);
0270 #endif
0271 
0272     virtual void initViewItemOption(QStyleOptionViewItem *option) const;
0273 
0274     enum State {
0275         NoState,
0276         DraggingState,
0277         DragSelectingState,
0278         EditingState,
0279         ExpandingState,
0280         CollapsingState,
0281         AnimatingState
0282     };
0283 
0284     State state() const;
0285     void setState(State state);
0286 
0287     void scheduleDelayedItemsLayout();
0288     void executeDelayedItemsLayout();
0289 
0290     void setDirtyRegion(const QRegion &region);
0291     void scrollDirtyRegion(int dx, int dy);
0292     QPoint dirtyRegionOffset() const;
0293 
0294     void startAutoScroll();
0295     void stopAutoScroll();
0296     void doAutoScroll();
0297 
0298     bool focusNextPrevChild(bool next) override;
0299     bool event(QEvent *event) override;
0300     bool viewportEvent(QEvent *event) override;
0301     void mousePressEvent(QMouseEvent *event) override;
0302     void mouseMoveEvent(QMouseEvent *event) override;
0303     void mouseReleaseEvent(QMouseEvent *event) override;
0304     void mouseDoubleClickEvent(QMouseEvent *event) override;
0305 #if QT_CONFIG(draganddrop)
0306     void dragEnterEvent(QDragEnterEvent *event) override;
0307     void dragMoveEvent(QDragMoveEvent *event) override;
0308     void dragLeaveEvent(QDragLeaveEvent *event) override;
0309     void dropEvent(QDropEvent *event) override;
0310 #endif
0311     void focusInEvent(QFocusEvent *event) override;
0312     void focusOutEvent(QFocusEvent *event) override;
0313     void keyPressEvent(QKeyEvent *event) override;
0314     void resizeEvent(QResizeEvent *event) override;
0315     void timerEvent(QTimerEvent *event) override;
0316     void inputMethodEvent(QInputMethodEvent *event) override;
0317     bool eventFilter(QObject *object, QEvent *event) override;
0318 
0319 #if QT_CONFIG(draganddrop)
0320     enum DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport };
0321     DropIndicatorPosition dropIndicatorPosition() const;
0322 #endif
0323 
0324     QSize viewportSizeHint() const override;
0325 
0326 private:
0327     Q_DECLARE_PRIVATE(QAbstractItemView)
0328     Q_DISABLE_COPY(QAbstractItemView)
0329 
0330     friend class ::tst_QAbstractItemView;
0331     friend class ::tst_QTreeView;
0332     friend class QTreeViewPrivate; // needed to compile with MSVC
0333     friend class QListModeViewBase;
0334     friend class QListViewPrivate;
0335     friend class QAbstractSlider;
0336 };
0337 
0338 Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractItemView::EditTriggers)
0339 
0340 QT_END_NAMESPACE
0341 
0342 #endif // QABSTRACTITEMVIEW_H