libyui-qt  2.52.4
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,
47  YTableHeader * header,
48  bool multiSelection );
49 
50  /**
51  * Destructor.
52  **/
53  virtual ~YQTable();
54 
55  /**
56  * Switch between sorting by item insertion order (keepSorting: true) or
57  * allowing the user to sort by an arbitrary column (by clicking on the
58  * column header).
59  *
60  * Reimplemented from YTable.
61  **/
62  virtual void setKeepSorting( bool keepSorting );
63 
64  /**
65  * Add an item.
66  *
67  * Reimplemented from YSelectionWidget.
68  **/
69  virtual void addItem( YItem * item );
70 
71  /**
72  * Add multiple items.
73  *
74  * Reimplemented for efficiency from YSelectionWidget.
75  **/
76  virtual void addItems( const YItemCollection & itemCollection );
77 
78  /**
79  * Select or deselect an item.
80  *
81  * Reimplemented from YSelectionWidget.
82  **/
83  virtual void selectItem( YItem * item, bool selected = true );
84 
85  /**
86  * Deselect all items.
87  *
88  * Reimplemented from YSelectionWidget.
89  **/
90  virtual void deselectAllItems();
91 
92  /**
93  * Delete all items.
94  *
95  * Reimplemented from YSelectionWidget.
96  **/
97  virtual void deleteAllItems();
98 
99  /**
100  * Notification that a cell (its text and/or its icon) was changed from the
101  * outside. Applications are required to call this whenever a table cell is
102  * changed after adding the corresponding table item (the row) to the table
103  * widget.
104  *
105  * Reimplemented from YTable.
106  **/
107  virtual void cellChanged( const YTableCell * cell );
108 
109  /**
110  * Set enabled/disabled state.
111  *
112  * Reimplemented from YWidget.
113  **/
114  virtual void setEnabled( bool enabled );
115 
116  /**
117  * Preferred width of the widget.
118  *
119  * Reimplemented from YWidget.
120  **/
121  virtual int preferredWidth();
122 
123  /**
124  * Preferred height of the widget.
125  *
126  * Reimplemented from YWidget.
127  **/
128  virtual int preferredHeight();
129 
130  /**
131  * Set the new size of the widget.
132  *
133  * Reimplemented from YWidget.
134  **/
135  virtual void setSize( int newWidth, int newHeight );
136 
137  /**
138  * Accept the keyboard focus.
139  *
140  * Reimplemented from YWidget.
141  **/
142  virtual bool setKeyboardFocus();
143 
144 
145 protected slots:
146 
147  /**
148  * Notification that an item is selected (single click or keyboard).
149  **/
150  void slotSelected( QTreeWidgetItem * );
151 
152  /**
153  * Notification that the item selection changed
154  * (relevant for multiSelection mode).
155  **/
156  void slotSelectionChanged();
157 
158  /**
159  * Notification that an item is activated (double click or keyboard).
160  **/
161  void slotActivated( QTreeWidgetItem * );
162 
163  /**
164  * Propagate a context menu selection
165  *
166  * This will trigger an 'ContextMenuActivated' event if 'notifyContextMenu' is set.
167  **/
168  void slotContextMenu ( const QPoint & pos );
169 
170 
171 
172 protected:
173 
174  /**
175  * Select the original item (the YTableItem) that corresponds to the
176  * specified listViewItem.
177  **/
178  void selectOrigItem( QTreeWidgetItem * listViewItem );
179 
180  /**
181  * Internal addItem() method that will not do expensive operations in batch
182  * mode.
183  **/
184  void addItem( YItem * item, bool batchMode, bool resizeColumnsToContent );
185 
186  //
187  // Data members
188  //
189 
190  QY2ListView * _qt_listView;
191 };
192 
193 
194 
195 /**
196  * Visual representation of a YTableItem.
197  **/
199 {
200 public:
201 
202  /**
203  * Constructor.
204  **/
206  QY2ListView * parent,
207  YTableItem * origItem );
208 
209  /**
210  * Return the parent table widget.
211  **/
212  YQTable * table() const { return _table; }
213 
214  /**
215  * Return the corresponding YTableItem.
216  **/
217  YTableItem * origItem() const { return _origItem; }
218 
219  /**
220  * Update this item's display with the content of 'cell'.
221  **/
222  void updateCell( const YTableCell * cell );
223 
224  /**
225  * The text of the table cell or the sort-key if available.
226  **/
227  virtual QString smartSortKey(int column) const override;
228 
229 protected:
230 
231  YQTable * _table;
232  YTableItem * _origItem;
233 };
234 
235 
236 
237 #endif // YQLabel_h
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
Definition: YQTable.cc:213
virtual void addItem(YItem *item)
Add an item.
Definition: YQTable.cc:129
void slotContextMenu(const QPoint &pos)
Propagate a context menu selection.
Definition: YQTable.cc:404
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQTable.cc:395
YQTableListViewItem(YQTable *table, QY2ListView *parent, YTableItem *origItem)
Constructor.
Definition: YQTable.cc:418
void slotSelected(QTreeWidgetItem *)
Notification that an item is selected (single click or keyboard).
Definition: YQTable.cc:284
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:120
virtual void deleteAllItems()
Delete all items.
Definition: YQTable.cc:250
void selectOrigItem(QTreeWidgetItem *listViewItem)
Select the original item (the YTableItem) that corresponds to the specified listViewItem.
Definition: YQTable.cc:271
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQTable.cc:358
Visual representation of a YTableItem.
Definition: YQTable.h:198
YTableItem * origItem() const
Return the corresponding YTableItem.
Definition: YQTable.h:217
virtual void deselectAllItems()
Deselect all items.
Definition: YQTable.cc:240
virtual void cellChanged(const YTableCell *cell)
Notification that a cell (its text and/or its icon) was changed from the outside. ...
Definition: YQTable.cc:258
YQTable(YWidget *parent, YTableHeader *header, bool multiSelection)
Constructor.
Definition: YQTable.cc:46
virtual ~YQTable()
Destructor.
Definition: YQTable.cc:113
void updateCell(const YTableCell *cell)
Update this item&#39;s display with the content of &#39;cell&#39;.
Definition: YQTable.cc:440
YQTable * table() const
Return the parent table widget.
Definition: YQTable.h:212
Enhanced QTreeWidget.
Definition: QY2ListView.h:47
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQTable.cc:388
void slotActivated(QTreeWidgetItem *)
Notification that an item is activated (double click or keyboard).
Definition: YQTable.cc:345
virtual void addItems(const YItemCollection &itemCollection)
Add multiple items.
Definition: YQTable.cc:186
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQTable.cc:368
Enhanced QTreeWidgetItem.
Definition: QY2ListView.h:233
virtual QString smartSortKey(int column) const override
The text of the table cell or the sort-key if available.
Definition: YQTable.cc:477
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQTable.cc:378
void slotSelectionChanged()
Notification that the item selection changed (relevant for multiSelection mode).
Definition: YQTable.cc:310