libyui-qt  2.46.13
YQTable.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQTable.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YQTable_h
26 #define YQTable_h
27 
28 #include <QFrame>
29 #include "QY2ListView.h"
30 #include <yui/YTable.h>
31 
32 
33 class QY2ListView;
34 class QTreeWidgetItem;
35 class YQListViewItem;
36 
37 class YQTable : public QFrame, public YTable
38 {
39  Q_OBJECT
40 
41 public:
42 
43  /**
44  * Constructor.
45  **/
46  YQTable( YWidget * parent, YTableHeader * header, bool multiSelection );
47 
48  /**
49  * Destructor.
50  **/
51  virtual ~YQTable();
52 
53  /**
54  * Switch between sorting by item insertion order (keepSorting: true) or
55  * allowing the user to sort by an arbitrary column (by clicking on the
56  * column header).
57  *
58  * Reimplemented from YTable.
59  **/
60  virtual void setKeepSorting( bool keepSorting );
61 
62  /**
63  * Add an item.
64  *
65  * Reimplemented from YSelectionWidget.
66  **/
67  virtual void addItem( YItem * item );
68 
69  /**
70  * Add multiple items.
71  *
72  * Reimplemented for efficiency from YSelectionWidget.
73  **/
74  virtual void addItems( const YItemCollection & itemCollection );
75 
76  /**
77  * Select or deselect an item.
78  *
79  * Reimplemented from YSelectionWidget.
80  **/
81  virtual void selectItem( YItem * item, bool selected = true );
82 
83  /**
84  * Deselect all items.
85  *
86  * Reimplemented from YSelectionWidget.
87  **/
88  virtual void deselectAllItems();
89 
90  /**
91  * Delete all items.
92  *
93  * Reimplemented from YSelectionWidget.
94  **/
95  virtual void deleteAllItems();
96 
97  /**
98  * Notification that a cell (its text and/or its icon) was changed from the
99  * outside. Applications are required to call this whenever a table cell is
100  * changed after adding the corresponding table item (the row) to the table
101  * widget.
102  *
103  * Reimplemented from YTable.
104  **/
105  virtual void cellChanged( const YTableCell * cell );
106 
107  /**
108  * Set enabled/disabled state.
109  *
110  * Reimplemented from YWidget.
111  **/
112  virtual void setEnabled( bool enabled );
113 
114  /**
115  * Preferred width of the widget.
116  *
117  * Reimplemented from YWidget.
118  **/
119  virtual int preferredWidth();
120 
121  /**
122  * Preferred height of the widget.
123  *
124  * Reimplemented from YWidget.
125  **/
126  virtual int preferredHeight();
127 
128  /**
129  * Set the new size of the widget.
130  *
131  * Reimplemented from YWidget.
132  **/
133  virtual void setSize( int newWidth, int newHeight );
134 
135  /**
136  * Accept the keyboard focus.
137  *
138  * Reimplemented from YWidget.
139  **/
140  virtual bool setKeyboardFocus();
141 
142 
143 protected slots:
144 
145  /**
146  * Notification that an item is selected (single click or keyboard).
147  **/
148  void slotSelected( QTreeWidgetItem * );
149 
150  /**
151  * Notification that the item selection changed
152  * (relevant for multiSelection mode).
153  **/
154  void slotSelectionChanged();
155 
156  /**
157  * Notification that an item is activated (double click or keyboard).
158  **/
159  void slotActivated( QTreeWidgetItem * );
160 
161  /**
162  * Propagate a context menu selection
163  *
164  * This will trigger an 'ContextMenuActivated' event if 'notifyContextMenu' is set.
165  **/
166  void slotContextMenu ( const QPoint & pos );
167 
168 
169 
170 protected:
171 
172  /**
173  * Select the original item (the YTableItem) that corresponds to the
174  * specified listViewItem.
175  **/
176  void selectOrigItem( QTreeWidgetItem * listViewItem );
177 
178  /**
179  * Internal addItem() method that will not do expensive operations in batch
180  * mode.
181  **/
182  void addItem( YItem * item, bool batchMode, bool resizeColumnsToContent );
183 
184  //
185  // Data members
186  //
187 
188  QY2ListView * _qt_listView;
189 };
190 
191 
192 
193 /**
194  * Visual representation of a YTableItem.
195  **/
197 {
198 public:
199 
200  /**
201  * Constructor.
202  **/
204  QY2ListView * parent,
205  YTableItem * origItem );
206 
207  /**
208  * Return the parent table widget.
209  **/
210  YQTable * table() const { return _table; }
211 
212  /**
213  * Return the corresponding YTableItem.
214  **/
215  YTableItem * origItem() const { return _origItem; }
216 
217  /**
218  * Update this item's display with the content of 'cell'.
219  **/
220  void updateCell( const YTableCell * cell );
221 
222 protected:
223 
224  YQTable * _table;
225  YTableItem * _origItem;
226 };
227 
228 
229 
230 #endif // YQLabel_h
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
Definition: YQTable.cc:208
YTableItem * origItem() const
Return the corresponding YTableItem.
Definition: YQTable.h:215
virtual void addItem(YItem *item)
Add an item.
Definition: YQTable.cc:124
void slotContextMenu(const QPoint &pos)
Propagate a context menu selection.
Definition: YQTable.cc:399
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQTable.cc:390
YQTableListViewItem(YQTable *table, QY2ListView *parent, YTableItem *origItem)
Constructor.
Definition: YQTable.cc:413
void slotSelected(QTreeWidgetItem *)
Notification that an item is selected (single click or keyboard).
Definition: YQTable.cc:279
virtual void setKeepSorting(bool keepSorting)
Switch between sorting by item insertion order (keepSorting: true) or allowing the user to sort by an...
Definition: YQTable.cc:115
virtual void deleteAllItems()
Delete all items.
Definition: YQTable.cc:245
void selectOrigItem(QTreeWidgetItem *listViewItem)
Select the original item (the YTableItem) that corresponds to the specified listViewItem.
Definition: YQTable.cc:266
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQTable.cc:353
YQTable * table() const
Return the parent table widget.
Definition: YQTable.h:210
Visual representation of a YTableItem.
Definition: YQTable.h:196
virtual void deselectAllItems()
Deselect all items.
Definition: YQTable.cc:235
virtual void cellChanged(const YTableCell *cell)
Notification that a cell (its text and/or its icon) was changed from the outside. ...
Definition: YQTable.cc:253
YQTable(YWidget *parent, YTableHeader *header, bool multiSelection)
Constructor.
Definition: YQTable.cc:43
virtual ~YQTable()
Destructor.
Definition: YQTable.cc:108
void updateCell(const YTableCell *cell)
Update this item's display with the content of 'cell'.
Definition: YQTable.cc:435
Enhanced QTreeWidget.
Definition: QY2ListView.h:47
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQTable.cc:383
void slotActivated(QTreeWidgetItem *)
Notification that an item is activated (double click or keyboard).
Definition: YQTable.cc:340
virtual void addItems(const YItemCollection &itemCollection)
Add multiple items.
Definition: YQTable.cc:181
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQTable.cc:363
Enhanced QTreeWidgetItem.
Definition: QY2ListView.h:233
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQTable.cc:373
void slotSelectionChanged()
Notification that the item selection changed (relevant for multiSelection mode).
Definition: YQTable.cc:305