libyui-qt  2.56.2
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 <shundhammer@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;
36 
37 
38 class YQTable : public QFrame, public YTable
39 {
40  Q_OBJECT
41 
42 public:
43 
44  /**
45  * Constructor.
46  **/
47  YQTable( YWidget * parent,
48  YTableHeader * header,
49  bool multiSelection );
50 
51  /**
52  * Destructor.
53  **/
54  virtual ~YQTable();
55 
56  /**
57  * Switch between sorting by item insertion order (keepSorting: true) or
58  * allowing the user to sort by an arbitrary column (by clicking on the
59  * column header).
60  *
61  * Reimplemented from YTable.
62  **/
63  virtual void setKeepSorting( bool keepSorting );
64 
65  /**
66  * Add an item.
67  *
68  * Reimplemented from YSelectionWidget.
69  **/
70  virtual void addItem( YItem * item );
71 
72  /**
73  * Add multiple items.
74  *
75  * Reimplemented for efficiency from YSelectionWidget.
76  **/
77  virtual void addItems( const YItemCollection & itemCollection );
78 
79  /**
80  * Select or deselect an item.
81  *
82  * Reimplemented from YSelectionWidget.
83  **/
84  virtual void selectItem( YItem * item, bool selected = true );
85 
86  /**
87  * Deselect all items.
88  *
89  * Reimplemented from YSelectionWidget.
90  **/
91  virtual void deselectAllItems();
92 
93  /**
94  * Delete all items.
95  *
96  * Reimplemented from YSelectionWidget.
97  **/
98  virtual void deleteAllItems();
99 
100  /**
101  * Notification that a cell (its text and/or its icon) was changed from the
102  * outside. Applications are required to call this whenever a table cell is
103  * changed after adding the corresponding table item (the row) to the table
104  * widget.
105  *
106  * Reimplemented from YTable.
107  **/
108  virtual void cellChanged( const YTableCell * cell );
109 
110  /**
111  * Set enabled/disabled state.
112  *
113  * Reimplemented from YWidget.
114  **/
115  virtual void setEnabled( bool enabled );
116 
117  /**
118  * Preferred width of the widget.
119  *
120  * Reimplemented from YWidget.
121  **/
122  virtual int preferredWidth();
123 
124  /**
125  * Preferred height of the widget.
126  *
127  * Reimplemented from YWidget.
128  **/
129  virtual int preferredHeight();
130 
131  /**
132  * Set the new size of the widget.
133  *
134  * Reimplemented from YWidget.
135  **/
136  virtual void setSize( int newWidth, int newHeight );
137 
138  /**
139  * Accept the keyboard focus.
140  *
141  * Reimplemented from YWidget.
142  **/
143  virtual bool setKeyboardFocus();
144 
145 
146 protected slots:
147 
148  /**
149  * Notification that an item is selected (single click or keyboard).
150  **/
151  void slotSelected( QTreeWidgetItem * );
152 
153  /**
154  * Notification that the item selection changed
155  * (relevant for multiSelection mode).
156  **/
157  void slotSelectionChanged();
158 
159  /**
160  * Notification that an item is activated (double click or keyboard).
161  **/
162  void slotActivated( QTreeWidgetItem * );
163 
164  /**
165  * Propagate an "item expanded" event to the underlying YTableItem.
166  **/
167  void slotItemExpanded( QTreeWidgetItem * item );
168 
169  /**
170  * Propagate an "item collapsed" event to the underlying YTableItem.
171  **/
172  void slotItemCollapsed( QTreeWidgetItem * item );
173 
174 
175  /**
176  * Propagate a context menu selection.
177  *
178  * This will trigger a 'ContextMenuActivated' event if 'notifyContextMenu' is set.
179  **/
180  void slotContextMenu ( const QPoint & pos );
181 
182 
183 
184 protected:
185 
186  /**
187  * Select the original item (the YTableItem) that corresponds to the
188  * specified listViewItem.
189  **/
190  void selectOrigItem( QTreeWidgetItem * listViewItem );
191 
192  /**
193  * Internal addItem() method that will not do expensive operations in batch
194  * mode.
195  **/
196  void addItem( YItem * item, bool batchMode, bool resizeColumnsToContent );
197 
198  /**
199  * Clone (create Qt item counterparts) for all child items of 'parentItem'.
200  * Set their Qt item parent to 'parentItemClone'.
201  **/
202  void cloneChildItems( YTableItem * parentItem,
203  YQTableListViewItem * parentItemClone );
204 
205  //
206  // Data members
207  //
208 
209  QY2ListView * _qt_listView;
210 };
211 
212 
213 
214 /**
215  * Visual representation of a YTableItem.
216  **/
218 {
219 public:
220 
221  /**
222  * Constructor for toplevel items.
223  **/
225  QY2ListView * parent,
226  YTableItem * origItem );
227 
228  /**
229  * Constructor for nested items.
230  **/
232  YQTableListViewItem * parentItemClone,
233  YTableItem * origItem );
234 
235  /**
236  * Return the parent table widget.
237  **/
238  YQTable * table() const { return _table; }
239 
240  /**
241  * Return the corresponding YTableItem.
242  **/
243  YTableItem * origItem() const { return _origItem; }
244 
245  /**
246  * Update this item's display with the content of 'cell'.
247  **/
248  void updateCell( const YTableCell * cell );
249 
250  /**
251  * Update all columns of this item with the content of the original item.
252  **/
253  void updateCells();
254 
255  /**
256  * The text of the table cell or the sort-key if available.
257  **/
258  virtual QString smartSortKey(int column) const override;
259 
260 protected:
261 
262  /**
263  * Common initializations for all constructors
264  **/
265  void init();
266 
267  /**
268  * Set the alignment for each column according to the YTable parent's
269  * alignment.
270  **/
271  void setColAlignment();
272 
273 
274  YQTable * _table;
275  YTableItem * _origItem;
276 };
277 
278 
279 
280 #endif // YQLabel_h
YQTable::setSize
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQTable.cc:430
YQTableListViewItem::setColAlignment
void setColAlignment()
Set the alignment for each column according to the YTable parent's alignment.
Definition: YQTable.cc:547
YQTable::deleteAllItems
virtual void deleteAllItems()
Delete all items.
Definition: YQTable.cc:292
YQTable::slotContextMenu
void slotContextMenu(const QPoint &pos)
Propagate a context menu selection.
Definition: YQTable.cc:446
YQTableListViewItem::init
void init()
Common initializations for all constructors.
Definition: YQTable.cc:483
YQTable::setEnabled
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQTable.cc:400
YQTableListViewItem::YQTableListViewItem
YQTableListViewItem(YQTable *table, QY2ListView *parent, YTableItem *origItem)
Constructor for toplevel items.
Definition: YQTable.cc:460
YQTable::slotSelectionChanged
void slotSelectionChanged()
Notification that the item selection changed (relevant for multiSelection mode).
Definition: YQTable.cc:352
YQTable::preferredWidth
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQTable.cc:410
YQTable::~YQTable
virtual ~YQTable()
Destructor.
Definition: YQTable.cc:124
YQTable::cellChanged
virtual void cellChanged(const YTableCell *cell)
Notification that a cell (its text and/or its icon) was changed from the outside.
Definition: YQTable.cc:300
YQTableListViewItem::smartSortKey
virtual QString smartSortKey(int column) const override
The text of the table cell or the sort-key if available.
Definition: YQTable.cc:566
YQTable::slotItemExpanded
void slotItemExpanded(QTreeWidgetItem *item)
Propagate an "item expanded" event to the underlying YTableItem.
Definition: YQTable.cc:259
YQTableListViewItem::updateCell
void updateCell(const YTableCell *cell)
Update this item's display with the content of 'cell'.
Definition: YQTable.cc:510
YQTable::deselectAllItems
virtual void deselectAllItems()
Deselect all items.
Definition: YQTable.cc:282
YQTableListViewItem::origItem
YTableItem * origItem() const
Return the corresponding YTableItem.
Definition: YQTable.h:243
YQTable::slotActivated
void slotActivated(QTreeWidgetItem *)
Notification that an item is activated (double click or keyboard).
Definition: YQTable.cc:387
YQTable::setKeyboardFocus
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQTable.cc:437
YQTableListViewItem::table
YQTable * table() const
Return the parent table widget.
Definition: YQTable.h:238
YQTable::selectItem
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
Definition: YQTable.cc:232
YQTable::addItems
virtual void addItems(const YItemCollection &itemCollection)
Add multiple items.
Definition: YQTable.cc:206
YQTable::YQTable
YQTable(YWidget *parent, YTableHeader *header, bool multiSelection)
Constructor.
Definition: YQTable.cc:50
YQTable::cloneChildItems
void cloneChildItems(YTableItem *parentItem, YQTableListViewItem *parentItemClone)
Clone (create Qt item counterparts) for all child items of 'parentItem'.
Definition: YQTable.cc:186
YQTable::slotItemCollapsed
void slotItemCollapsed(QTreeWidgetItem *item)
Propagate an "item collapsed" event to the underlying YTableItem.
Definition: YQTable.cc:270
YQTable
Definition: YQTable.h:39
YQTable::selectOrigItem
void selectOrigItem(QTreeWidgetItem *listViewItem)
Select the original item (the YTableItem) that corresponds to the specified listViewItem.
Definition: YQTable.cc:313
YQTable::slotSelected
void slotSelected(QTreeWidgetItem *)
Notification that an item is selected (single click or keyboard).
Definition: YQTable.cc:326
YQTable::preferredHeight
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQTable.cc:420
QY2ListView
Enhanced QTreeWidget.
Definition: QY2ListView.h:48
YQTable::setKeepSorting
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:131
YQTable::addItem
virtual void addItem(YItem *item)
Add an item.
Definition: YQTable.cc:140
YQTableListViewItem::updateCells
void updateCells()
Update all columns of this item with the content of the original item.
Definition: YQTable.cc:498
QY2ListViewItem
Enhanced QTreeWidgetItem.
Definition: QY2ListView.h:234
YQTableListViewItem
Visual representation of a YTableItem.
Definition: YQTable.h:218