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-2006 CEA
8 #include "SALOME_ProductsView.hxx"
9 #include <qstringlist.h>
11 // ================================================================
13 * ProductsViewItem::ProductsViewItem
16 // ================================================================
17 ProductsViewItem::ProductsViewItem( ProductsView* parent, const QString& text, Type tt )
18 : QCheckListItem( parent, text, tt )
21 // ================================================================
23 * ProductsViewItem::ProductsViewItem
26 // ================================================================
27 ProductsViewItem::ProductsViewItem( QCheckListItem* parent, const QString& text, Type tt )
28 : QCheckListItem( parent, text, tt )
31 // ================================================================
33 * ProductsViewItem::stateChange
34 * Called when users switches item on/off
36 // ================================================================
37 void ProductsViewItem::stateChange( bool on ) {
38 QCheckListItem::stateChange( on );
39 ((ProductsView*)listView())->itemActivated( (QCheckListItem*)this );
43 // ================================================================
45 * ProductsView::ProductsView
48 // ================================================================
49 ProductsView::ProductsView( QWidget* parent ) : QListView( parent )
51 setRootIsDecorated( false );
52 addColumn( tr( "Product" ) );
53 addColumn( tr( "Version" ) );
54 setResizeMode( LastColumn );
55 setSorting( -1, false );
57 // ================================================================
59 * ProductsView::addItem
60 * Adds product item(s) into the list
62 // ================================================================
63 QCheckListItem* ProductsView::addItem( const QString& name,
64 const QString& version,
65 const QString& install,
66 const QStringList& supported,
67 const QString& script )
69 QCheckListItem* item = 0;
70 QListViewItem* lItem = this->firstChild();
71 while( lItem && lItem->nextSibling() )
72 lItem = lItem->nextSibling();
74 if ( install.isNull() || install.isEmpty() ) {
75 item = new ProductsViewItem( this, name, QCheckListItem::CheckBox );
76 item->setText( 1, version );
77 item->setText( 2, script );
78 item->moveItem( lItem );
81 item = new ProductsViewItem( this, name, QCheckListItem::Controller );
82 item->setText( 1, version );
83 item->setText( 2, script );
85 QCheckListItem* subitem = 0;
86 subitem = new ProductsViewItem( item, tr( "not install" ), QCheckListItem::RadioButton );
87 subitem->setOn( true );
88 QCheckListItem* previtem = subitem;
89 subitem->moveItem( previtem );
90 for ( int i = 0; i < (int)supported.count(); i++ ) {
91 subitem = new ProductsViewItem( item, supported[ i ], QCheckListItem::RadioButton );
92 if ( supported[i] == install )
93 subitem->setOn( true );
94 subitem->moveItem( previtem );
97 item->moveItem( lItem );
98 item->setOpen( true );
102 // ================================================================
104 * ProductsView::eventFilter
105 * Event filter - prevents collapsing/expanding of items
107 // ================================================================
108 bool ProductsView::eventFilter( QObject* o, QEvent* e )
110 if ( o == viewport() && e->type() == QEvent::MouseButtonDblClick )
112 return QListView::eventFilter( o, e );
114 // ================================================================
116 * ProductsView::itemActivated
117 * Emits signal when checkbox or radiobutton is switched
119 // ================================================================
120 void ProductsView::itemActivated( QCheckListItem* item ) {
121 emit itemToggled( item );
123 // ================================================================
125 * ProductsView::isBinaries
126 * Returns true if "install binaries" is on for the item
128 // ================================================================
129 bool ProductsView::isBinaries( QCheckListItem* item ) const
131 if ( item->childCount() > 0 && item->isEnabled() ) {
132 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
134 if ( subItem->isOn() )
135 return subItem->text() == tr( "install binaries" );
136 subItem = (QCheckListItem*)( subItem->nextSibling() );
141 // ================================================================
143 * ProductsView::isSources
144 * Returns true if "install sources" is on for the item
146 // ================================================================
147 bool ProductsView::isSources( QCheckListItem* item ) const
149 if ( item->childCount() > 0 && item->isEnabled() ) {
150 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
152 if ( subItem->isOn() )
153 return subItem->text() == tr( "install sources" );
154 subItem = (QCheckListItem*)( subItem->nextSibling() );
162 // ================================================================
164 * ProductsView::isNative
165 * Returns true if "use native" is on for the item
167 // ================================================================
168 bool ProductsView::isNative( QCheckListItem* item ) const
170 if ( item->childCount() > 0 && item->isEnabled() ) {
171 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
173 if ( subItem->isOn() )
174 return subItem->text() == tr( "use native" );
175 subItem = (QCheckListItem*)( subItem->nextSibling() );
180 // ================================================================
182 * ProductsView::isNone
183 * Returns true if "not install" is on for the item
185 // ================================================================
186 bool ProductsView::isNone( QCheckListItem* item ) const
188 return !isBinaries( item ) && !isSources( item ) && !isNative( item );
190 // ================================================================
192 * ProductsView::setBinaries
193 * Sets "install binaries" on for the item; if "binaries" item
194 * is absent, set "install sources" on if it is present
196 // ================================================================
197 void ProductsView::setBinaries( QCheckListItem* item ) {
198 if ( item->childCount() > 0 ) {
199 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
200 QCheckListItem* srcItem = 0;
201 QCheckListItem* nativeItem = 0;
203 if ( subItem->text() == tr( "install sources" ) )
205 if ( subItem->text() == tr( "use native" ) )
206 nativeItem = subItem;
207 if ( subItem->text() == tr( "install binaries" ) ) {
208 subItem->setOn( true );
211 subItem = (QCheckListItem*)( subItem->nextSibling() );
213 if ( nativeItem ) // prefer native item
214 nativeItem->setOn( true );
216 srcItem->setOn( true );
222 // ================================================================
224 * ProductsView::setSources
225 * Sets "install sources" on for the item; if "sources" item
226 * is absent, set "install binaries" on if it is present
228 // ================================================================
229 void ProductsView::setSources( QCheckListItem* item ) {
230 if ( item->childCount() > 0 ) {
231 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
232 QCheckListItem* binItem = 0;
233 QCheckListItem* nativeItem = 0;
235 if ( subItem->text() == tr( "install binaries" ) )
237 if ( subItem->text() == tr( "use native" ) )
238 nativeItem = subItem;
239 if ( subItem->text() == tr( "install sources" ) ) {
240 subItem->setOn( true );
243 subItem = (QCheckListItem*)( subItem->nextSibling() );
245 if ( nativeItem ) // prefer native item
246 nativeItem->setOn( true );
248 binItem->setOn( true );
254 // ================================================================
256 * ProductsView::setNative
257 * Sets "use native" on for the item; if "sources" item
258 * is absent, set "install binaries" on if it is present
260 // ================================================================
261 void ProductsView::setNative( QCheckListItem* item ) {
262 if ( item->childCount() > 0 ) {
263 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
264 QCheckListItem* binItem = 0;
265 QCheckListItem* srcItem = 0;
267 if ( subItem->text() == tr( "install binaries" ) )
269 if ( subItem->text() == tr( "install sources" ) )
271 if ( subItem->text() == tr( "use native" ) ) {
272 subItem->setOn( true );
275 subItem = (QCheckListItem*)( subItem->nextSibling() );
277 if ( binItem ) // prefer binaries
278 binItem->setOn( true );
280 srcItem->setOn( true );
286 // ================================================================
288 * ProductsView::setNone
289 * Sets "not install" on for the item
291 // ================================================================
292 void ProductsView::setNone( QCheckListItem* item ) {
293 if ( item->childCount() > 0 ) {
294 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
296 if ( subItem->text() == tr( "not install" ) ) {
297 subItem->setOn( true );
300 subItem = (QCheckListItem*)( subItem->nextSibling() );
304 item->setOn( false );
308 // ================================================================
310 * ProductsView::hasBinaries
311 * Returns true if product supports "binaries" installation mode
313 // ================================================================
314 bool ProductsView::hasBinaries( QCheckListItem* item ) const
316 if ( item->childCount() > 0 ) {
317 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
319 if ( subItem->text() == tr( "install binaries" ) )
321 subItem = (QCheckListItem*)( subItem->nextSibling() );
327 // ================================================================
329 * ProductsView::hasSources
330 * Returns true if product supports "sources" installation mode
332 // ================================================================
333 bool ProductsView::hasSources( QCheckListItem* item ) const
335 if ( item->childCount() > 0 ) {
336 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
338 if ( subItem->text() == tr( "install sources" ) )
340 subItem = (QCheckListItem*)( subItem->nextSibling() );
346 // ================================================================
348 * ProductsView::hasNative
349 * Returns true if product supports "native" installation mode
351 // ================================================================
352 bool ProductsView::hasNative( QCheckListItem* item ) const
354 if ( item->childCount() > 0 ) {
355 QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
357 if ( subItem->text() == tr( "use native" ) )
359 subItem = (QCheckListItem*)( subItem->nextSibling() );
365 // ================================================================
367 * ProductsView::setItemEnabled
368 * Enable/disable item
370 // ================================================================
371 void ProductsView::setItemEnabled( QCheckListItem* item, const bool enable )
373 item->setEnabled( enable );
374 QListViewItem* subItem = item->firstChild();
376 subItem->setEnabled( enable );
377 subItem = subItem->nextSibling();
381 // ================================================================
383 * ProductsView::findBinItem
384 * Find bin item which corresponds to the src item
386 // ================================================================
387 QCheckListItem* ProductsView::findBinItem( const QString& srcName )
389 QString binName = srcName.lower().replace( "src", "bin" );
390 QCheckListItem* subItem = (QCheckListItem*)( firstChild() );
392 if ( subItem->text().lower() == binName )
394 subItem = (QCheckListItem*)( subItem->nextSibling() );