/
htable2.h
180 lines (149 loc) · 5.08 KB
/
htable2.h
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <QTreeView>
#include <QMouseEvent>
#include <QStandardItemModel>
#include <QHeaderView>
#include <QTreeWidget>
class HeadedTable2;
class CellAttribute2
{
public:
QString text;
bool selected;
bool sorted;
QColor backColor; //table share
QColor foreColor; //rows share
int xpos; // cols share
int ypos; // rows share
int w; // cols share
int depth; // rows share
int folded; //
};
class HtableModel : public QAbstractItemModel
//class HtableModel : public QAbstractTableModel
{
Q_OBJECT
public:
HtableModel(QObject *parent = 0);
~HtableModel(){};
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex())const; //pure
virtual QModelIndex parent(const QModelIndex &child) const; //pure virtual
virtual int rowCount(const QModelIndex &parent) const;
virtual QVariant data(const QModelIndex &index, int role) const;
int columnCount(const QModelIndex &parent) const;
QVariant headerData ( int section, Qt::Orientation o, int role ) const;
virtual Qt::ItemFlags flags ( const QModelIndex & index ) const;
// Qt::ItemFlags flags(const QModelIndex &index) const;
// QMap<int, QVariant> itemData ( const QModelIndex & index ) const ;
// void update(){ reset();}
void update(){ emit layoutChanged();}
// void update(const QModelIndex &idx);
// void update(int row);
// void update(); //TEMP
HeadedTable2 *htable;
};
class HtableHeader : public QHeaderView
// QHeaderView ( Qt::Orientation orientation, QWidget * parent = 0 )
{
Q_OBJECT
public:
HtableHeader(QWidget *parent = 0);
~HtableHeader(){};
protected:
virtual void mousePressEvent(QMouseEvent *e);
signals:
void rightClicked(QPoint where, int col);
void toolTip(QPoint where, int col);
private:
HeadedTable2 *htable;
};
class HeadedTable2 : public QTreeView
//class HeadedTable2 : public QTreeWidget
{
Q_OBJECT
public:
HeadedTable2(QWidget *parent, int opts=0);
~HeadedTable2(){};
friend class HtableModel;
HtableModel *model;
enum NodeState { Leaf, Open, Closed };
void repaint_changed();
int clickedColumn(){return 0;}; // need imp
int sortedCol() { return sorted_col; } //ok
/*
void deleteCol(int col, bool update = TRUE);
void topAndRepaint();
int lastRowVisible() { return body->lastRowVisible(); };
void updateCell(int row, int col, bool erase=false);
void updateHeading(int col) { };
void selectionNotify();
void repaintColumns(int col0, int col1 = -1);
bool treeMode() { return treemode; };
int tableWidth() const { return body->totalWidth()+ body->verticalScrollBar()->width(); }
bool isCellContentsChanged(int row,int col,bool head);
void selectOnly(int row);
void clearAllSelections();
*/
int numRows() { return nrows; }
int numCols() { return ncols; }
int numSelected() { return 0; }
void setTreeMode(bool mode);
void setSortedCol(int col);
void setNumRows(int rows);
void setNumCols(int cols);
virtual bool isSelected(int row) { return false; }
virtual void setSelected(int row, bool sel){};
void modelIterate(const QModelIndex &idx);
signals:
void titleClicked(int col);
void doubleClicked(int row);
void rightClicked(QPoint where);
void foldSubTree(int row);
void colMoved(int col, int place);
public slots:
void selectAll();
void repaintAll();
protected:
virtual void mousePressEvent(QMouseEvent *e);
virtual int rowDepth(int row){ return 0;} ;
virtual NodeState folded(int row){ return Leaf;};
virtual bool folded(QModelIndex &idx){ return false;};
virtual int parentRow(int row){return 0;};
virtual bool lastChild(int row){return false;};
virtual bool columnMovable(int col){return true;};
virtual int colWidth(int col) = 0; //head_width
virtual void moveCol(int col, int place){};
virtual QString title(int col) = 0;
virtual QString text(int row, int col) = 0;
virtual QString tipText(int col){ return "";};
virtual int alignment(int col){ return 0;};
/*
virtual char *total_selectedRow(int col);
virtual int sizeHintForColumn(int col) const;
virtual void hideEvent ( QHideEvent * event );
virtual void showEvent ( QShowEvent * event );
virtual void resizeEvent(QResizeEvent *);
*/
// colWidth returns width in digit units; negative means variable width.
// virtual void drawCellContents(int row, int col, int w, int h, QPainter *painter);
//virtual bool modified(int row){return true;};
bool treemode;
private:
// to make signals originate from the right object
/* void emit_click_signal(int col);
void emit_double_click_signal(int row);
void emit_right_click_signal(QPoint where);
void emit_fold(int row);
inline int computedWidth(int col);
int colOffset(int col);
inline int colXPos(int col);
void updateCols(int deltacols, int place, bool update);
*/
int sorted_col; // column to emphasize
int reversed_sort; // true if sorting backwards
int options;
int nrows;
int ncols;
// text cache is in logical columns (reorder causes no flush)
QHash<int,CellAttribute2 *> cached_attr; // indexed by (row << 16) + log_col
QHash<int,CellAttribute2 * > cached_attr_h; // indexed by (row << 16) + log_col
};