libyui-mga  1.0.7
YMGA_CBTable.cc
1 /*
2  Copyright 2013 by Angelo Naselli <anaselli at linux dot it>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as
6  published by the Free Software Foundation; either version 2.1 of the
7  License, or (at your option) version 3.0 of the License. This library
8  is distributed in the hope that it will be useful, but WITHOUT ANY
9  WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11  License for more details. You should have received a copy of the GNU
12  Lesser General Public License along with this library; if not, write
13  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14  Floor, Boston, MA 02110-1301 USA
15 */
16 
17 
18 /*-/
19 
20  File: YMGA_CBTable.cc
21 
22  Author: Angelo Naselli <anaselli@linux.it>
23 
24 /-*/
25 
26 
27 #define YUILogComponent "mga-ui"
28 #include "YUILog.h"
29 
30 #include "YUISymbols.h"
31 #include "YMGA_CBTable.h"
32 
34 {
35  YMGA_CBTablePrivate ( YTableHeader * header )
36  : header ( header )
37  , keepSorting ( false )
38  , immediateMode ( false )
39  , mode ( YCBTableCheckBoxOnFirstColumn )
40  , item ( 0 )
41  {
42  }
43 
44  YTableHeader* header;
45  bool keepSorting;
46  bool immediateMode;
47  YCBTableMode mode;
48  YCBTableItem* item;
49 };
50 
51 
52 
53 
54 
55 YMGA_CBTable::YMGA_CBTable ( YWidget* parent, YTableHeader * header, YCBTableMode mode )
56  :YSelectionWidget ( parent,
57  "", // label
58  true ) // enforceSingleSelection
59  , priv ( new YMGA_CBTablePrivate ( header ) )
60 {
61  YUI_CHECK_PTR ( header );
62  YUI_CHECK_NEW ( priv );
63 
64  priv->mode = mode;
65 
66  setDefaultStretchable ( YD_HORIZ, true );
67  setDefaultStretchable ( YD_VERT, true );
68 }
69 
70 
72 {
73 }
74 
76 {
77  return priv->item;
78 }
79 
81 {
82  priv->item = pItem;
83 }
84 
85 
87 {
88  return priv->mode;
89 }
90 
91 
92 void YMGA_CBTable::addItem ( YItem* item )
93 {
94  YUI_CHECK_PTR ( item );
95 
96  YSelectionWidget::addItem ( item );
97 }
98 
99 void YMGA_CBTable::setTableHeader ( YTableHeader * newHeader )
100 {
101  YUI_CHECK_PTR ( newHeader );
102 
103  if ( priv->header->columns() != newHeader->columns() )
104  deleteAllItems();
105 
106  delete priv->header;
107  priv->header = newHeader;
108 }
109 
110 
112 {
113  return priv->header->columns();
114 }
115 
116 
117 bool YMGA_CBTable::hasColumn ( int column ) const
118 {
119  return priv->header->hasColumn ( column );
120 }
121 
122 
123 std::string YMGA_CBTable::header ( int column ) const
124 {
125  return priv->header->header ( column );
126 }
127 
128 
129 YAlignmentType YMGA_CBTable::alignment ( int column ) const
130 {
131  return priv->header->alignment ( column );
132 }
133 
134 
136 {
137  return priv->immediateMode;
138 }
139 
140 
142 {
143  priv->immediateMode = immediateMode;
144 
145  if ( immediateMode )
146  setNotify ( true );
147 }
148 
149 
151 {
152  return priv->keepSorting;
153 }
154 
155 
157 {
158  priv->keepSorting = keepSorting;
159 }
160 
161 
163 {
164  return ! YSelectionWidget::enforceSingleSelection();
165 }
166 
167 
168 YItem * YMGA_CBTable::item ( int index ) const
169 {
170  return YSelectionWidget::itemAt ( index );
171 }
172 
173 YItemIterator YMGA_CBTable::nextItem( YItemIterator currentIterator)
174 {
175  return ++currentIterator;
176 }
177 
179 {
180  priv->item = NULL;
181  YSelectionWidget::deleteAllItems();
182 }
183 
184 
185 YItem* YMGA_CBTable::YItemIteratorToYItem ( YItemIterator it )
186 {
187  return *it;
188 }
189 
191 {
192  return dynamic_cast<YCBTableItem*>(item);
193 }
194 
195 const YPropertySet &YMGA_CBTable::propertySet()
196 {
197  static YPropertySet propSet;
198 
199  if ( propSet.isEmpty() )
200  {
201  /*
202  * @property itemID Value The currently selected item
203  * @property itemID CurrentItem The currently selected item
204  * @property itemList Items All items
205  * @property itemList SelectedItems All currently selected items
206  * @property std::string Cell One cell (one column of one item)
207  * @property integer Cell (ChangeWidget only) One cell as integer
208  * @property `icon(...) Cell Icon for one one cell
209  * @property std::string Item Alias for Cell
210  * @property std::string Item QueryWidget only: Return one complete item
211  * @property std::string IconPath Base path for icons
212  * @property bool MultiSelection Flag: User can select multiple items (read-only)
213  */
214  propSet.add ( YProperty ( YUIProperty_Value, YOtherProperty ) );
215  propSet.add ( YProperty ( YUIProperty_CurrentItem, YOtherProperty ) );
216  propSet.add ( YProperty ( YUIProperty_SelectedItems, YOtherProperty ) );
217  propSet.add ( YProperty ( YUIProperty_Items, YOtherProperty ) );
218  propSet.add ( YProperty ( YUIProperty_Cell, YOtherProperty ) );
219  propSet.add ( YProperty ( YUIProperty_Item, YOtherProperty ) );
220  propSet.add ( YProperty ( YUIProperty_IconPath, YStringProperty ) );
221  propSet.add ( YProperty ( YUIProperty_MultiSelection, YBoolProperty, true ) ); // read-only
222  propSet.add ( YWidget::propertySet() );
223  }
224 
225  return propSet;
226 }
227 
228 
229 bool YMGA_CBTable::setProperty ( const std::string & propertyName, const YPropertyValue & val )
230 {
231  propertySet().check ( propertyName, val.type() ); // throws exceptions if not found or type mismatch
232 
233  if ( propertyName == YUIProperty_Value )
234  return false; // Needs special handling
235  else if ( propertyName == YUIProperty_CurrentItem )
236  return false; // Needs special handling
237  else if ( propertyName == YUIProperty_SelectedItems )
238  return false; // Needs special handling
239  else if ( propertyName == YUIProperty_Items )
240  return false; // Needs special handling
241  else if ( propertyName == YUIProperty_Cell )
242  return false; // Needs special handling
243  else if ( propertyName == YUIProperty_Item )
244  return false; // Needs special handling
245  else if ( propertyName == YUIProperty_IconPath )
246  setIconBasePath ( val.stringVal() );
247  else
248  {
249  return YWidget::setProperty ( propertyName, val );
250  }
251 
252  return true; // success -- no special processing necessary
253 }
254 
255 
256 YPropertyValue YMGA_CBTable::getProperty ( const std::string & propertyName )
257 {
258  propertySet().check ( propertyName ); // throws exceptions if not found
259 
260  if ( propertyName == YUIProperty_Value )
261  return YPropertyValue ( YOtherProperty );
262  else if ( propertyName == YUIProperty_CurrentItem )
263  return YPropertyValue ( YOtherProperty );
264  else if ( propertyName == YUIProperty_SelectedItems )
265  return YPropertyValue ( YOtherProperty );
266  else if ( propertyName == YUIProperty_Items )
267  return YPropertyValue ( YOtherProperty );
268  else if ( propertyName == YUIProperty_Cell )
269  return YPropertyValue ( YOtherProperty );
270  else if ( propertyName == YUIProperty_Item )
271  return YPropertyValue ( YOtherProperty );
272  else if ( propertyName == YUIProperty_IconPath )
273  return YPropertyValue ( iconBasePath() );
274 
275  return YWidget::getProperty ( propertyName );
276 }
277 
virtual void setKeepSorting(bool keepSorting)
Switch between sorting by item insertion order (keepSorting: true) or allowing the user to sort by an...
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
YCBTableItem * toCBYTableItem(YItem *item)
useful cast for bindings.
YMGA_CBTable(YWidget *parent, YTableHeader *header, YCBTableMode mode)
Constructor.
Definition: YMGA_CBTable.cc:55
YCBTableMode tableMode()
returns the YCBTable checkbox position mode
Definition: YMGA_CBTable.cc:86
virtual void setChangedItem(YCBTableItem *pItem)
When derived classes emit YWidgetEvent with reason ValueChanged they have to set which item is change...
Definition: YMGA_CBTable.cc:80
int columns() const
Return the number of columns of this table.
YAlignmentType alignment(int column) const
Return the alignment for the specified column.
std::string header(int column) const
Return the header text for the specified column.
virtual void addItem(YItem *item_disown)
Add one item.
Definition: YMGA_CBTable.cc:92
bool immediateMode() const
Deliver even more events than with notify() set.
YItem * YItemIteratorToYItem(YItemIterator iter)
useful cast for bindings.
virtual YItem * item(int index) const
From YSelectionWidget returns the item at index &#39;index&#39; (from 0) or 0 if there is no such item...
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
virtual void deleteAllItems()
Delete all items.
void setImmediateMode(bool immediateMode=true)
Set immediateMode() on or off.
bool hasMultiSelection() const
Return &#39;true&#39; if the user can select multiple items at the same time (e.g., with shift-click or ctrl-...
void setTableHeader(YTableHeader *newHeader)
Exchange the previous table header with a new one.
Definition: YMGA_CBTable.cc:99
bool hasColumn(int column) const
Return &#39;true&#39; if this table has a column no.
bool keepSorting() const
Return &#39;true&#39; if the sort order is to be kept in item insertion order, i.e.
virtual ~YMGA_CBTable()
Destructor.
Definition: YMGA_CBTable.cc:71
YItemIterator nextItem(YItemIterator currentIterator)
YSelectionWidget does not implement the increment of iterator and bindings seem not to work with iter...
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
virtual YCBTableItem * changedItem()
Return the item which value is changed (e.g.
Definition: YMGA_CBTable.cc:75