1 // File : SALOME_ProductsView.cxx
2 // Created : Thu Dec 18 12:01:00 2002
3 // Author : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
5 // Module : Installation Wizard
6 // Copyright : 2002-2007 CEA
8 #include "SALOME_ProductsView.hxx"
9 #include <qstringlist.h>
12 // ================================================================
14 * ProductsViewItem::ProductsViewItem
17 // ================================================================
18 ProductsViewItem::ProductsViewItem( ProductsView* parent, const QString& text, Type tt )
19 : QCheckListItem( parent, text, tt )
22 // ================================================================
24 * ProductsViewItem::ProductsViewItem
27 // ================================================================
28 ProductsViewItem::ProductsViewItem( QCheckListItem* parent, const QString& text, Type tt )
29 : QCheckListItem( parent, text, tt )
32 // ================================================================
34 * ProductsViewItem::stateChange
35 * Called when users switches item on/off
37 // ================================================================
38 void ProductsViewItem::stateChange( bool on ) {
39 QCheckListItem::stateChange( on );
40 ((ProductsView*)listView())->itemActivated( (QCheckListItem*)this );
44 // ================================================================
46 * ProductsView::ProductsView
49 // ================================================================
50 ProductsView::ProductsView( QWidget* parent ) : QListView( parent )
52 setRootIsDecorated( false );
53 addColumn( tr( "Product" ) );
54 addColumn( tr( "Version" ) );
55 setResizeMode( LastColumn );
56 setSorting( -1, false );
58 // ================================================================
60 * ProductsView::addItem
61 * Adds product item(s) into the list
63 // ================================================================
64 QCheckListItem* ProductsView::addItem( const QString& name,
65 const QString& version,
66 const QString& install,
67 const QStringList& supported,
68 const QString& script )
70 QCheckListItem* item = 0;
71 QListViewItem* lItem = this->firstChild();
72 while( lItem && lItem->nextSibling() )
73 lItem = lItem->nextSibling();
75 if ( install.isNull() || install.isEmpty() ) {
76 item = new ProductsViewItem( this, name, QCheckListItem::CheckBox );
77 item->setText( 1, version );
78 item->setText( 2, script );
79 item->moveItem( lItem );
82 item = new ProductsViewItem( this, name, QCheckListItem::Controller );
83 item->setText( 1, version );
84 item->setText( 2, script );
86 QCheckListItem* subitem = 0;
87 subitem = new ProductsViewItem( item, tr( "not install" ), QCheckListItem::RadioButton );
88 subitem->setOn( true );
89 QCheckListItem* previtem = subitem;
90 subitem->moveItem( previtem );
91 for ( int i = 0; i < (int)supported.count(); i++ ) {
92 subitem = new ProductsViewItem( item, supported[ i ], QCheckListItem::RadioButton );
93 if ( supported[i] == install )
94 subitem->setOn( true );
95 subitem->moveItem( previtem );
98 item->moveItem( lItem );
99 item->setOpen( true );
103 // ================================================================
105 * ProductsView::eventFilter
106 * Event filter - prevents collapsing/expanding of items
108 // ================================================================
109 bool ProductsView::eventFilter( QObject* o, QEvent* e )
111 if ( o == viewport() && e->type() == QEvent::MouseButtonDblClick )
113 return QListView::eventFilter( o, e );
115 // ================================================================
117 * ProductsView::itemActivated
118 * Emits signal when checkbox or radiobutton is switched
120 // ================================================================
121 void ProductsView::itemActivated( QCheckListItem* item ) {
122 emit itemToggled( item );
124 // ================================================================
126 * ProductsView::isBinaries
127 * Returns true if "install binaries" is on for the item
129 // ================================================================
130 bool ProductsView::isBinaries( QCheckListItem* item ) const
132 if ( item->childCount() > 0 && item->isEnabled() ) {
133 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
135 if ( subItem->isOn() )
136 return subItem->text() == tr( "install binaries" );
137 subItem = (QCheckListItem*)( subItem->nextSibling() );
142 // ================================================================
144 * ProductsView::isSources
145 * Returns true if "install sources" is on for the item
147 // ================================================================
148 bool ProductsView::isSources( QCheckListItem* item ) const
150 if ( item->childCount() > 0 && item->isEnabled() ) {
151 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
153 if ( subItem->isOn() )
154 return subItem->text() == tr( "install sources" );
155 subItem = (QCheckListItem*)( subItem->nextSibling() );
163 // ================================================================
165 * ProductsView::isNative
166 * Returns true if "use native" is on for the item
168 // ================================================================
169 bool ProductsView::isNative( QCheckListItem* item ) const
171 if ( item->childCount() > 0 && item->isEnabled() ) {
172 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
174 if ( subItem->isOn() )
175 return subItem->text() == tr( "use native" );
176 subItem = (QCheckListItem*)( subItem->nextSibling() );
181 // ================================================================
183 * ProductsView::isNone
184 * Returns true if "not install" is on for the item
186 // ================================================================
187 bool ProductsView::isNone( QCheckListItem* item ) const
189 return !isBinaries( item ) && !isSources( item ) && !isNative( item );
191 // ================================================================
193 * ProductsView::setBinaries
194 * Sets "install binaries" on for the item; if "binaries" item
195 * is absent, set "install sources" on if it is present
197 // ================================================================
198 void ProductsView::setBinaries( QCheckListItem* item ) {
199 if ( item->childCount() > 0 ) {
200 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
201 QCheckListItem* srcItem = 0;
202 QCheckListItem* nativeItem = 0;
204 if ( subItem->text() == tr( "install sources" ) )
206 if ( subItem->text() == tr( "use native" ) )
207 nativeItem = subItem;
208 if ( subItem->text() == tr( "install binaries" ) ) {
209 subItem->setOn( true );
212 subItem = (QCheckListItem*)( subItem->nextSibling() );
214 if ( nativeItem ) // prefer native item
215 nativeItem->setOn( true );
217 srcItem->setOn( true );
223 // ================================================================
225 * ProductsView::setSources
226 * Sets "install sources" on for the item; if "sources" item
227 * is absent, set "install binaries" on if it is present
229 // ================================================================
230 void ProductsView::setSources( QCheckListItem* item ) {
231 if ( item->childCount() > 0 ) {
232 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
233 QCheckListItem* binItem = 0;
234 QCheckListItem* nativeItem = 0;
236 if ( subItem->text() == tr( "install binaries" ) )
238 if ( subItem->text() == tr( "use native" ) )
239 nativeItem = subItem;
240 if ( subItem->text() == tr( "install sources" ) ) {
241 subItem->setOn( true );
244 subItem = (QCheckListItem*)( subItem->nextSibling() );
246 if ( nativeItem ) // prefer native item
247 nativeItem->setOn( true );
249 binItem->setOn( true );
255 // ================================================================
257 * ProductsView::setNative
258 * Sets "use native" on for the item; if "sources" item
259 * is absent, set "install binaries" on if it is present
261 // ================================================================
262 void ProductsView::setNative( QCheckListItem* item ) {
263 if ( item->childCount() > 0 ) {
264 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
265 QCheckListItem* binItem = 0;
266 QCheckListItem* srcItem = 0;
268 if ( subItem->text() == tr( "install binaries" ) )
270 if ( subItem->text() == tr( "install sources" ) )
272 if ( subItem->text() == tr( "use native" ) ) {
273 subItem->setOn( true );
276 subItem = (QCheckListItem*)( subItem->nextSibling() );
278 if ( binItem ) // prefer binaries
279 binItem->setOn( true );
281 srcItem->setOn( true );
287 // ================================================================
289 * ProductsView::setNone
290 * Sets "not install" on for the item
292 // ================================================================
293 void ProductsView::setNone( QCheckListItem* item ) {
294 if ( item->childCount() > 0 ) {
295 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
297 if ( subItem->text() == tr( "not install" ) ) {
298 subItem->setOn( true );
301 subItem = (QCheckListItem*)( subItem->nextSibling() );
305 item->setOn( false );
309 // ================================================================
311 * ProductsView::hasBinaries
312 * Returns true if product supports "binaries" installation mode
314 // ================================================================
315 bool ProductsView::hasBinaries( QCheckListItem* item ) const
317 if ( item->childCount() > 0 ) {
318 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
320 if ( subItem->text() == tr( "install binaries" ) )
322 subItem = (QCheckListItem*)( subItem->nextSibling() );
328 // ================================================================
330 * ProductsView::hasSources
331 * Returns true if product supports "sources" installation mode
333 // ================================================================
334 bool ProductsView::hasSources( QCheckListItem* item ) const
336 if ( item->childCount() > 0 ) {
337 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
339 if ( subItem->text() == tr( "install sources" ) )
341 subItem = (QCheckListItem*)( subItem->nextSibling() );
347 // ================================================================
349 * ProductsView::hasNative
350 * Returns true if product supports "native" installation mode
352 // ================================================================
353 bool ProductsView::hasNative( QCheckListItem* item ) const
355 if ( item->childCount() > 0 ) {
356 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
358 if ( subItem->text() == tr( "use native" ) )
360 subItem = (QCheckListItem*)( subItem->nextSibling() );
366 // ================================================================
368 * ProductsView::setItemEnabled
369 * Enable/disable item
371 // ================================================================
372 void ProductsView::setItemEnabled( QCheckListItem* item, const bool enable )
374 item->setEnabled( enable );
375 QListViewItem* subItem = item->firstChild();
377 subItem->setEnabled( enable );
378 subItem = subItem->nextSibling();
382 // ================================================================
384 * ProductsView::findBinItem
385 * Find bin item which corresponds to the src item
387 // ================================================================
388 QCheckListItem* ProductsView::findBinItem( const QString& srcName )
390 QString binName = srcName.lower().replace( QRegExp("src"), "bin" );
391 QCheckListItem* subItem = (QCheckListItem*)( firstChild() );
393 if ( subItem->text().lower() == binName )
395 subItem = (QCheckListItem*)( subItem->nextSibling() );