libyui-mga  1.0.4
 All Classes Functions Enumerations Enumerator
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 
141 void YMGA_CBTable::setImmediateMode ( bool immediateMode )
142 {
143  priv->immediateMode = immediateMode;
144 
145  if ( immediateMode )
146  setNotify ( true );
147 }
148 
149 
151 {
152  return priv->keepSorting;
153 }
154 
155 
156 void YMGA_CBTable::setKeepSorting ( bool keepSorting )
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 
178 YItem* YMGA_CBTable::YItemIteratorToYItem ( YItemIterator it )
179 {
180  return *it;
181 }
182 
184 {
185  return dynamic_cast<YCBTableItem*>(item);
186 }
187 
188 const YPropertySet &YMGA_CBTable::propertySet()
189 {
190  static YPropertySet propSet;
191 
192  if ( propSet.isEmpty() )
193  {
194  /*
195  * @property itemID Value The currently selected item
196  * @property itemID CurrentItem The currently selected item
197  * @property itemList Items All items
198  * @property itemList SelectedItems All currently selected items
199  * @property std::string Cell One cell (one column of one item)
200  * @property integer Cell (ChangeWidget only) One cell as integer
201  * @property `icon(...) Cell Icon for one one cell
202  * @property std::string Item Alias for Cell
203  * @property std::string Item QueryWidget only: Return one complete item
204  * @property std::string IconPath Base path for icons
205  * @property bool MultiSelection Flag: User can select multiple items (read-only)
206  */
207  propSet.add ( YProperty ( YUIProperty_Value, YOtherProperty ) );
208  propSet.add ( YProperty ( YUIProperty_CurrentItem, YOtherProperty ) );
209  propSet.add ( YProperty ( YUIProperty_SelectedItems, YOtherProperty ) );
210  propSet.add ( YProperty ( YUIProperty_Items, YOtherProperty ) );
211  propSet.add ( YProperty ( YUIProperty_Cell, YOtherProperty ) );
212  propSet.add ( YProperty ( YUIProperty_Item, YOtherProperty ) );
213  propSet.add ( YProperty ( YUIProperty_IconPath, YStringProperty ) );
214  propSet.add ( YProperty ( YUIProperty_MultiSelection, YBoolProperty, true ) ); // read-only
215  propSet.add ( YWidget::propertySet() );
216  }
217 
218  return propSet;
219 }
220 
221 
222 bool YMGA_CBTable::setProperty ( const std::string & propertyName, const YPropertyValue & val )
223 {
224  propertySet().check ( propertyName, val.type() ); // throws exceptions if not found or type mismatch
225 
226  if ( propertyName == YUIProperty_Value )
227  return false; // Needs special handling
228  else if ( propertyName == YUIProperty_CurrentItem )
229  return false; // Needs special handling
230  else if ( propertyName == YUIProperty_SelectedItems )
231  return false; // Needs special handling
232  else if ( propertyName == YUIProperty_Items )
233  return false; // Needs special handling
234  else if ( propertyName == YUIProperty_Cell )
235  return false; // Needs special handling
236  else if ( propertyName == YUIProperty_Item )
237  return false; // Needs special handling
238  else if ( propertyName == YUIProperty_IconPath )
239  setIconBasePath ( val.stringVal() );
240  else
241  {
242  return YWidget::setProperty ( propertyName, val );
243  }
244 
245  return true; // success -- no special processing necessary
246 }
247 
248 
249 YPropertyValue YMGA_CBTable::getProperty ( const std::string & propertyName )
250 {
251  propertySet().check ( propertyName ); // throws exceptions if not found
252 
253  if ( propertyName == YUIProperty_Value )
254  return YPropertyValue ( YOtherProperty );
255  else if ( propertyName == YUIProperty_CurrentItem )
256  return YPropertyValue ( YOtherProperty );
257  else if ( propertyName == YUIProperty_SelectedItems )
258  return YPropertyValue ( YOtherProperty );
259  else if ( propertyName == YUIProperty_Items )
260  return YPropertyValue ( YOtherProperty );
261  else if ( propertyName == YUIProperty_Cell )
262  return YPropertyValue ( YOtherProperty );
263  else if ( propertyName == YUIProperty_Item )
264  return YPropertyValue ( YOtherProperty );
265  else if ( propertyName == YUIProperty_IconPath )
266  return YPropertyValue ( iconBasePath() );
267 
268  return YWidget::getProperty ( propertyName );
269 }
270 
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'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
virtual void addItem(YItem *item_disown)
Add one item.
Definition: YMGA_CBTable.cc:92
YItem * YItemIteratorToYItem(YItemIterator iter)
useful cast for bindings.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
int columns() const
Return the number of columns of this table.
virtual YItem * item(int index) const
From YSelectionWidget returns the item at index 'index' (from 0) or 0 if there is no such item...
void setImmediateMode(bool immediateMode=true)
Set immediateMode() on or off.
bool hasColumn(int column) const
Return 'true' if this table has a column no.
bool immediateMode() const
Deliver even more events than with notify() set.
std::string header(int column) const
Return the header text for the specified column.
bool keepSorting() const
Return 'true' if the sort order is to be kept in item insertion order, i.e.
void setTableHeader(YTableHeader *newHeader)
Exchange the previous table header with a new one.
Definition: YMGA_CBTable.cc:99
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...
YAlignmentType alignment(int column) const
Return the alignment for the specified column.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
bool hasMultiSelection() const
Return 'true' if the user can select multiple items at the same time (e.g., with shift-click or ctrl-...
virtual YCBTableItem * changedItem()
Return the item which value is changed (e.g.
Definition: YMGA_CBTable.cc:75