libyui  3.3.1
YTable.cc
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: YTable.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YUISymbols.h"
30 #include "YTable.h"
31 
32 
34 {
35  YTablePrivate( YTableHeader * header )
36  : header( header )
37  , keepSorting( false )
38  , immediateMode( false )
39  {
40  }
41 
42  YTableHeader * header;
43  bool keepSorting;
44  bool immediateMode;
45 };
46 
47 
48 
49 
50 YTable::YTable( YWidget * parent, YTableHeader * header, bool multiSelection )
51  : YSelectionWidget( parent,
52  "", // label
53  ! multiSelection ) // enforceSingleSelection
54  , priv( new YTablePrivate( header ) )
55 {
56  YUI_CHECK_PTR( header );
57  YUI_CHECK_NEW( priv );
58 
59  setDefaultStretchable( YD_HORIZ, true );
60  setDefaultStretchable( YD_VERT, true );
61 }
62 
63 
65 {
66  if ( priv->header )
67  delete priv->header;
68 }
69 
70 
71 void
73 {
74  YUI_CHECK_PTR( newHeader );
75 
76  if ( priv->header->columns() != newHeader->columns() )
78 
79  delete priv->header;
80  priv->header = newHeader;
81 }
82 
83 
84 int
86 {
87  return priv->header->columns();
88 }
89 
90 
91 bool
92 YTable::hasColumn( int column ) const
93 {
94  return priv->header->hasColumn( column );
95 }
96 
97 
98 std::string
99 YTable::header( int column ) const
100 {
101  return priv->header->header( column );
102 }
103 
104 
105 YAlignmentType
106 YTable::alignment( int column ) const
107 {
108  return priv->header->alignment( column );
109 }
110 
111 
112 bool
114 {
115  return priv->immediateMode;
116 }
117 
118 
119 void
121 {
122  priv->immediateMode = immediateMode;
123 
124  if ( immediateMode )
125  setNotify( true );
126 }
127 
128 
129 bool
131 {
132  return priv->keepSorting;
133 }
134 
135 
136 void
138 {
139  priv->keepSorting = keepSorting;
140 }
141 
142 
143 bool
145 {
147 }
148 
149 
150 const YPropertySet &
152 {
153  static YPropertySet propSet;
154 
155  if ( propSet.isEmpty() )
156  {
157  /*
158  * @property itemID Value The currently selected item
159  * @property itemID CurrentItem The currently selected item
160  * @property itemList Items All items
161  * @property itemList SelectedItems All currently selected items
162  * @property std::string Cell One cell (one column of one item)
163  * @property integer Cell (ChangeWidget only) One cell as integer
164  * @property `icon(...) Cell Icon for one one cell
165  * @property std::string Item Alias for Cell
166  * @property std::string Item QueryWidget only: Return one complete item
167  * @property std::string IconPath Base path for icons
168  * @property bool MultiSelection Flag: User can select multiple items (read-only)
169  */
170  propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) );
171  propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) );
172  propSet.add( YProperty( YUIProperty_SelectedItems, YOtherProperty ) );
173  propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
174  propSet.add( YProperty( YUIProperty_Cell, YOtherProperty ) );
175  propSet.add( YProperty( YUIProperty_Item, YOtherProperty ) );
176  propSet.add( YProperty( YUIProperty_IconPath, YStringProperty ) );
177  propSet.add( YProperty( YUIProperty_MultiSelection, YBoolProperty, true ) ); // read-only
178  propSet.add( YWidget::propertySet() );
179  }
180 
181  return propSet;
182 }
183 
184 
185 bool
186 YTable::setProperty( const std::string & propertyName, const YPropertyValue & val )
187 {
188  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
189 
190  if ( propertyName == YUIProperty_Value ) return false; // Needs special handling
191  else if ( propertyName == YUIProperty_CurrentItem ) return false; // Needs special handling
192  else if ( propertyName == YUIProperty_SelectedItems ) return false; // Needs special handling
193  else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
194  else if ( propertyName == YUIProperty_Cell ) return false; // Needs special handling
195  else if ( propertyName == YUIProperty_Item ) return false; // Needs special handling
196  else if ( propertyName == YUIProperty_IconPath ) setIconBasePath( val.stringVal() );
197  else
198  {
199  return YWidget::setProperty( propertyName, val );
200  }
201 
202  return true; // success -- no special processing necessary
203 }
204 
205 
207 YTable::getProperty( const std::string & propertyName )
208 {
209  propertySet().check( propertyName ); // throws exceptions if not found
210 
211  if ( propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty );
212  else if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( YOtherProperty );
213  else if ( propertyName == YUIProperty_SelectedItems ) return YPropertyValue( YOtherProperty );
214  else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
215  else if ( propertyName == YUIProperty_Cell ) return YPropertyValue( YOtherProperty );
216  else if ( propertyName == YUIProperty_Item ) return YPropertyValue( YOtherProperty );
217  else if ( propertyName == YUIProperty_IconPath ) return YPropertyValue( iconBasePath() );
218  else
219  {
220  return YWidget::getProperty( propertyName );
221  }
222 }
int columns() const
Return the number of columns of this table.
Definition: YTable.cc:85
YAlignmentType alignment(int column) const
Return the alignment for the specified column.
Definition: YTable.cc:106
bool isEmpty() const
Returns &#39;true&#39; if this property set does not contain anything.
Definition: YProperty.h:263
YTable(YWidget *parent, YTableHeader *header, bool multiSelection)
Constructor.
Definition: YTable.cc:50
Transport class for the value of simple properties.
Definition: YProperty.h:104
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-...
Definition: YTable.cc:144
Base class for various kinds of multi-value widgets.
Helper class for YTable for table column properties:
Definition: YTableHeader.h:43
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:145
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:428
A set of properties to check names and types against.
Definition: YProperty.h:197
void setImmediateMode(bool immediateMode=true)
Set immediateMode() on or off.
Definition: YTable.cc:120
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YTable.cc:207
bool hasColumn(int column) const
Return &#39;true&#39; if this table header has a column no.
Definition: YTableHeader.cc:77
int columns() const
Return the number of columns.
Definition: YTableHeader.cc:70
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YTable.cc:151
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YWidget.cc:393
virtual ~YTable()
Destructor.
Definition: YTable.cc:64
virtual void deleteAllItems()
Delete all items.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YTable.cc:186
std::string header(int column) const
Return the header text for the specified column.
Definition: YTable.cc:99
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:453
bool immediateMode() const
Deliver even more events than with notify() set.
Definition: YTable.cc:113
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:561
Class for widget properties.
Definition: YProperty.h:51
void setTableHeader(YTableHeader *newHeader)
Exchange the previous table header with a new one.
Definition: YTable.cc:72
void setNotify(bool notify=true)
Sets the Notify property.
Definition: YWidget.cc:517
void setIconBasePath(const std::string &basePath)
Set this widget&#39;s base path where to look up icons.
virtual void setKeepSorting(bool keepSorting)
Switch between sorting by item insertion order (keepSorting: true) or allowing the user to sort by an...
Definition: YTable.cc:137
YAlignmentType alignment(int column) const
Return the alignment for the specified column.
Definition: YTableHeader.cc:94
bool keepSorting() const
Return &#39;true&#39; if the sort order is to be kept in item insertion order, i.e.
Definition: YTable.cc:130
bool hasColumn(int column) const
Return &#39;true&#39; if this table has a column no.
Definition: YTable.cc:92
std::string header(int column) const
Return the header text for the specified column.
Definition: YTableHeader.cc:84
void check(const std::string &propertyName) const
Check if a property &#39;propertyName&#39; exists in this property set.
Definition: YProperty.cc:87
Abstract base class of all UI widgets.
Definition: YWidget.h:54
bool enforceSingleSelection() const
Return &#39;true&#39; if this base class should enforce single selection.
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
std::string iconBasePath() const
Return this widget&#39;s base path where to look up icons as set with setIconBasePath().