2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef VARIANTDELEGATE_H
|
|
|
|
#define VARIANTDELEGATE_H
|
|
|
|
|
2019-09-06 18:27:33 +00:00
|
|
|
#include <QStyledItemDelegate>
|
2017-01-21 21:57:20 +00:00
|
|
|
#include <QRegularExpression>
|
2020-07-10 06:09:56 +00:00
|
|
|
#include <QSharedPointer>
|
|
|
|
|
|
|
|
struct TypeChecker
|
|
|
|
{
|
|
|
|
TypeChecker();
|
|
|
|
|
|
|
|
QRegularExpression boolExp;
|
|
|
|
QRegularExpression byteArrayExp;
|
|
|
|
QRegularExpression charExp;
|
|
|
|
QRegularExpression colorExp;
|
|
|
|
QRegularExpression dateExp;
|
|
|
|
QRegularExpression dateTimeExp;
|
|
|
|
QRegularExpression doubleExp;
|
|
|
|
QRegularExpression pointExp;
|
|
|
|
QRegularExpression rectExp;
|
|
|
|
QRegularExpression signedIntegerExp;
|
|
|
|
QRegularExpression sizeExp;
|
|
|
|
QRegularExpression timeExp;
|
|
|
|
QRegularExpression unsignedIntegerExp;
|
|
|
|
};
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-09-06 18:27:33 +00:00
|
|
|
class VariantDelegate : public QStyledItemDelegate
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-07-10 06:09:56 +00:00
|
|
|
explicit VariantDelegate(const QSharedPointer<TypeChecker> &typeChecker,
|
|
|
|
QObject *parent = nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
2016-06-15 08:12:35 +00:00
|
|
|
const QModelIndex &index) const override;
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
2016-06-15 08:12:35 +00:00
|
|
|
const QModelIndex &index) const override;
|
|
|
|
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
2011-04-27 10:05:43 +00:00
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
2016-06-15 08:12:35 +00:00
|
|
|
const QModelIndex &index) const override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-12-02 16:54:48 +00:00
|
|
|
static bool isSupportedType(int type);
|
2011-04-27 10:05:43 +00:00
|
|
|
static QString displayText(const QVariant &value);
|
|
|
|
|
|
|
|
private:
|
2020-07-10 06:09:56 +00:00
|
|
|
QSharedPointer<TypeChecker> m_typeChecker;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|