-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoEditTreeView.h
More file actions
119 lines (99 loc) · 2.73 KB
/
AutoEditTreeView.h
File metadata and controls
119 lines (99 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef AutoEditTreeView_H
#define AutoEditTreeView_H
#include <QTreeView>
#include <QStandardItemModel>
#include <QItemDelegate>
#include <QTimer>
class AutoEditTreeViewDelegate :public QItemDelegate
{
Q_OBJECT
public:
AutoEditTreeViewDelegate(QObject* parent);
QWidget* AutoEditTreeViewDelegate::createEditor(QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index) const;
void setEditorData(QWidget* editor, const QModelIndex& index) const;
void setModelData(QWidget* editor,
QAbstractItemModel* model,
const QModelIndex& index
) const;
void updateEditorGeometry(QWidget* editor,
const QStyleOptionViewItem& option,
const QModelIndex& index
) const;
public slots:
void MycloseEditor(QWidget * editor, QAbstractItemDelegate::EndEditHint hint = NoHint);
protected:
bool editorEvent(QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index);
signals:
void EditorClosed();
void editMoveLeft();
void editMoveRight();
void editMoveUp();
void editMoveDown();
private:
QString m_lastedittext;
};
class ANameEdit;
class AutoEditTreeView : public QTreeView
{
Q_OBJECT
public:
explicit AutoEditTreeView(QWidget *parent = 0);
virtual ~AutoEditTreeView();
void setModel(QAbstractItemModel * model);
void ClearAndNew();
void AppenEmptyRow();
QStandardItemModel *model(){ return mmodel; }
protected:
void focusInEvent(QFocusEvent * event);
void focusOutEvent(QFocusEvent * event);
void keyPressEvent(QKeyEvent *keyevent);
void editorDestroyed(QObject * editor);
//bool edit(const QModelIndex & index, EditTrigger trigger, QEvent * event);
void closeEditor(QWidget * editor, QAbstractItemDelegate::EndEditHint hint);
private slots:
void EditorClosed();
void editMoveLeft()
{
auto ind = currentIndex();
if (ind.column() - 1 >= 0)
{
nexteditind = ind.sibling(ind.row(), ind.column() - 1);
mtm->start(200);
}
}
void editMoveRight(){
auto ind = currentIndex();
if (ind.column() + 1 < model()->columnCount())
{
nexteditind = ind.sibling(ind.row(), ind.column() + 1);
mtm->start(200);
}
}
void editMoveUp(){
auto ind = currentIndex();
if (ind.row() - 1 >=0)
{
nexteditind = ind.sibling(ind.row() - 1, ind.column());
mtm->start(200);
}
}
void editMoveDown(){
auto ind = currentIndex();
if (ind.row() + 1 < model()->rowCount())
{
nexteditind = ind.sibling(ind.row() + 1, ind.column());
mtm->start(200);
}
}
void DeleteSelectedRow();
public slots:
void mtmtimeout();
signals:
private:
QStandardItemModel *mmodel;
QTimer *mtm;
QModelIndex nexteditind;
};
#endif