File indexing completed on 2025-01-18 10:09:35
0001
0002
0003
0004 #ifndef QITEMEDITORFACTORY_H
0005 #define QITEMEDITORFACTORY_H
0006
0007 #include <QtWidgets/qtwidgetsglobal.h>
0008 #include <QtCore/qmetaobject.h>
0009 #include <QtCore/qbytearray.h>
0010 #include <QtCore/qhash.h>
0011 #include <QtCore/qvariant.h>
0012
0013 QT_REQUIRE_CONFIG(itemviews);
0014
0015 QT_BEGIN_NAMESPACE
0016
0017 class QWidget;
0018
0019 class Q_WIDGETS_EXPORT QItemEditorCreatorBase
0020 {
0021 public:
0022 virtual ~QItemEditorCreatorBase();
0023
0024 virtual QWidget *createWidget(QWidget *parent) const = 0;
0025 virtual QByteArray valuePropertyName() const = 0;
0026 };
0027
0028 template <class T>
0029 class QItemEditorCreator : public QItemEditorCreatorBase
0030 {
0031 public:
0032 inline explicit QItemEditorCreator(const QByteArray &valuePropertyName);
0033 inline QWidget *createWidget(QWidget *parent) const override { return new T(parent); }
0034 inline QByteArray valuePropertyName() const override { return propertyName; }
0035
0036 private:
0037 QByteArray propertyName;
0038 };
0039
0040 template <class T>
0041 class QStandardItemEditorCreator: public QItemEditorCreatorBase
0042 {
0043 public:
0044 inline QStandardItemEditorCreator()
0045 : propertyName(T::staticMetaObject.userProperty().name())
0046 {}
0047 inline QWidget *createWidget(QWidget *parent) const override { return new T(parent); }
0048 inline QByteArray valuePropertyName() const override { return propertyName; }
0049
0050 private:
0051 QByteArray propertyName;
0052 };
0053
0054
0055 template <class T>
0056 Q_INLINE_TEMPLATE QItemEditorCreator<T>::QItemEditorCreator(const QByteArray &avaluePropertyName)
0057 : propertyName(avaluePropertyName) {}
0058
0059 class Q_WIDGETS_EXPORT QItemEditorFactory
0060 {
0061 public:
0062 inline QItemEditorFactory() {}
0063 virtual ~QItemEditorFactory();
0064
0065 virtual QWidget *createEditor(int userType, QWidget *parent) const;
0066 virtual QByteArray valuePropertyName(int userType) const;
0067
0068 void registerEditor(int userType, QItemEditorCreatorBase *creator);
0069
0070 static const QItemEditorFactory *defaultFactory();
0071 static void setDefaultFactory(QItemEditorFactory *factory);
0072
0073 private:
0074 QHash<int, QItemEditorCreatorBase *> creatorMap;
0075 };
0076
0077 QT_END_NAMESPACE
0078
0079 #endif