1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #ifndef GREYCLUSTERINGITEMDELEGATE_H
- #define GREYCLUSTERINGITEMDELEGATE_H
- #include <QStyledItemDelegate>
- #include <QHBoxLayout>
- #include <QLabel>
- #include <QDoubleSpinBox>
- #include <QPushButton>
- class RangeSpin : public QFrame
- {
- Q_OBJECT
- public:
- RangeSpin(QWidget *parent = nullptr) : QFrame(parent)
- {
- QHBoxLayout *hLayout = new QHBoxLayout;
- setStyleSheet("RangeSpin{background-color:gray} QLabel{color:white}");
- hLayout->setMargin(0);
- hLayout->setSpacing(0);
- QLabel *minLabel = new QLabel("小");
- QLabel *maxLabel = new QLabel("大");
- m_minSpin = new QDoubleSpinBox;
- m_maxSpin = new QDoubleSpinBox;
- m_minSpin->setRange(-1000, 1000);
- m_maxSpin->setRange(-1000, 1000);
- hLayout->addWidget(minLabel);
- hLayout->addWidget(m_minSpin);
- hLayout->addWidget(m_maxSpin);
- hLayout->addWidget(maxLabel);
- setLayout(hLayout);
- }
- virtual ~RangeSpin() { }
- QString result()
- {
- this->onConfirm();
- return m_result;
- }
- bool valid() const
- {
- if (m_minSpin->value() < m_maxSpin->value()) {
- return true;
- }
- return false;
- }
- void setValue(const QString &value)
- {
- if (!value.isEmpty()) {
- QStringList tmp = value.mid(1, value.size() - 2).replace(" ", "").split(",");
- m_minSpin->setValue(tmp[0].toDouble());
- m_maxSpin->setValue(tmp[1].toDouble());
- }
- }
- private slots:
- void onConfirm() { m_result = QString("[%1, %2]").arg(m_minSpin->value()).arg(m_maxSpin->value()); }
- private:
- QDoubleSpinBox *m_minSpin;
- QDoubleSpinBox *m_maxSpin;
- QString m_result;
- };
- class GreyClusteringItemDelegate : public QStyledItemDelegate
- {
- Q_OBJECT
- public:
- GreyClusteringItemDelegate(QObject *parent = 0);
- QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, 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;
- };
- #endif // GREYCLUSTERINGITEMDELEGATE_H
|