You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
2.9 KiB
C
125 lines
2.9 KiB
C
|
3 weeks ago
|
#ifndef NMWXRESERVOIRPROPERTIES_H
|
||
|
|
#define NMWXRESERVOIRPROPERTIES_H
|
||
|
|
|
||
|
|
#include <QTreeWidget>
|
||
|
|
#include <QMouseEvent>
|
||
|
|
|
||
|
|
class WxCustomTreeWidget : public QTreeWidget {
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
explicit WxCustomTreeWidget(QWidget* parent = nullptr);
|
||
|
|
|
||
|
|
void updateRowStyle(QTreeWidgetItem* item, bool selected, bool hasFocus = false);
|
||
|
|
|
||
|
|
protected:
|
||
|
|
void mousePressEvent(QMouseEvent* event) override;
|
||
|
|
|
||
|
|
private:
|
||
|
|
QTreeWidgetItem* m_lastSelected;
|
||
|
|
};
|
||
|
|
|
||
|
|
#include <QStyledItemDelegate>
|
||
|
|
|
||
|
|
class CustomDelegate : public QStyledItemDelegate {
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
explicit CustomDelegate(QObject* parent = 0);
|
||
|
|
|
||
|
|
// 禁用编辑器创建(因为我们直接使用setItemWidget)
|
||
|
|
//QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
|
||
|
|
// const QModelIndex& index) const { return 0; }
|
||
|
|
|
||
|
|
//void setEditorData(QWidget* editor, const QModelIndex& index) const {}
|
||
|
|
//void setModelData(QWidget* editor, QAbstractItemModel* model,
|
||
|
|
// const QModelIndex& index) const {}
|
||
|
|
|
||
|
|
// 绘制项
|
||
|
|
void paint(QPainter* painter, const QStyleOptionViewItem& option,
|
||
|
|
const QModelIndex& index) const;
|
||
|
|
|
||
|
|
// 获取项大小
|
||
|
|
QSize sizeHint(const QStyleOptionViewItem& option,
|
||
|
|
const QModelIndex& index) const;
|
||
|
|
};
|
||
|
|
|
||
|
|
// 备份管理类,用于处理编辑时的数据备份
|
||
|
|
#include <QObject>
|
||
|
|
#include <QMap>
|
||
|
|
#include "nmDataAttribute.h"
|
||
|
|
|
||
|
|
class QTreeWidgetItem;
|
||
|
|
|
||
|
|
class BackupManager : public QObject {
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
explicit BackupManager(QObject* parent = 0);
|
||
|
|
~BackupManager();
|
||
|
|
|
||
|
|
// 开始编辑时创建备份
|
||
|
|
void startEditing(QTreeWidgetItem* item);
|
||
|
|
|
||
|
|
// 确认修改
|
||
|
|
void applyChanges(QTreeWidgetItem* item);
|
||
|
|
|
||
|
|
// 取消编辑
|
||
|
|
void cancelEditing(QTreeWidgetItem* item);
|
||
|
|
|
||
|
|
// 检查是否在编辑中
|
||
|
|
bool isEditing(QTreeWidgetItem* item) const;
|
||
|
|
|
||
|
|
private:
|
||
|
|
QMap<QTreeWidgetItem*, nmDataAttribute*> m_backupMap;
|
||
|
|
};
|
||
|
|
|
||
|
|
#include "nmSubWxs_global.h"
|
||
|
|
#include <QDialog>
|
||
|
|
#include <QTreeWidget>
|
||
|
|
#include "nmDataAttribute.h"
|
||
|
|
|
||
|
|
class BackupManager;
|
||
|
|
class CustomDelegate;
|
||
|
|
class WxCustomTreeWidget;
|
||
|
|
|
||
|
|
class NM_SUB_WXS_EXPORT nmWxReservoirProperties : public QDialog {
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
explicit nmWxReservoirProperties(QWidget* parent = 0);
|
||
|
|
~nmWxReservoirProperties();
|
||
|
|
|
||
|
|
private slots:
|
||
|
|
// 值变化槽函数
|
||
|
|
void onLengthValueChanged();
|
||
|
|
void onLengthUnitChanged();
|
||
|
|
void onTypeChanged();
|
||
|
|
void onVisibleChanged();
|
||
|
|
|
||
|
|
// 项点击槽函数
|
||
|
|
//void onItemClicked(QTreeWidgetItem* item, int column);
|
||
|
|
|
||
|
|
// 按钮槽函数
|
||
|
|
void onConfirmClicked();
|
||
|
|
void onCancelClicked();
|
||
|
|
|
||
|
|
//void onControlFocused(QTreeWidgetItem* item);
|
||
|
|
void onItemClicked(QTreeWidgetItem* item, int column);
|
||
|
|
|
||
|
|
private:
|
||
|
|
// 初始化UI
|
||
|
|
void setupUI();
|
||
|
|
|
||
|
|
// 填充树数据
|
||
|
|
void populateTree();
|
||
|
|
|
||
|
|
void setupTreeItem(QTreeWidgetItem* item, nmDataAttribute* attr);
|
||
|
|
|
||
|
|
// 成员变量
|
||
|
|
//QTreeWidget* m_pTreeWidget;
|
||
|
|
WxCustomTreeWidget* m_pTreeWidget;
|
||
|
|
CustomDelegate* m_pDelegate;
|
||
|
|
BackupManager* m_BackupManager;
|
||
|
|
|
||
|
|
//QList<TreeItemEventFilter*> m_eventFilters;
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif // NMWXRESERVOIRPROPERTIES_H
|