69 lines
1.9 KiB
C++
69 lines
1.9 KiB
C++
#ifndef ATTRIBUTETABLEDELEGATE_H
|
|
#define ATTRIBUTETABLEDELEGATE_H
|
|
|
|
#include <QStyledItemDelegate>
|
|
#include <QTableView>
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
namespace Ui {
|
|
class TextEditWidget;
|
|
}
|
|
QT_END_NAMESPACE
|
|
|
|
class TextEditWidget : public QWidget {
|
|
Q_OBJECT
|
|
public:
|
|
explicit TextEditWidget(QWidget* parent = nullptr);
|
|
~TextEditWidget();
|
|
|
|
QString editText();
|
|
void setEditText(const QString&);
|
|
void setPrompt(const QString&);
|
|
void setRegularExpression(const QString&);
|
|
void setErrorInfo(const QString&);
|
|
|
|
signals:
|
|
void confirm();
|
|
void cancle();
|
|
|
|
protected:
|
|
//bool eventFilter(QObject*, QEvent*) override;
|
|
|
|
private slots:
|
|
void onTextChanged();
|
|
void onBtnClicked_confirm();
|
|
void onBtnClicked_cancle();
|
|
|
|
private:
|
|
Ui::TextEditWidget* ui;
|
|
|
|
QString m_promptString; //提示字符
|
|
QString m_patternString; //正则表达式的模式字符
|
|
QRegularExpression m_regExp;
|
|
};
|
|
|
|
class AttributeTableDelegate : public QStyledItemDelegate
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit AttributeTableDelegate(QTableView* view, const QString& connection = "", QObject* parent = nullptr);
|
|
~AttributeTableDelegate();
|
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,const QModelIndex &index) const override;
|
|
//void destroyEditor(QWidget* editor, const QModelIndex& index) const override;
|
|
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
|
|
|
private:
|
|
bool isEnumType(const QModelIndex&) const;
|
|
|
|
QString m_connection;
|
|
QTableView* m_tableView;
|
|
};
|
|
|
|
#endif //ATTRIBUTETABLEDELEGATE_H
|