Salome HOME
Modifications in according to improvement 15165.
[tools/install.git] / src / SALOME_ProductsView.cxx
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)
4 //  Project   : SALOME
5 //  Module    : Installation Wizard
6 //  Copyright : 2002-2007 CEA
7
8 #include "SALOME_ProductsView.hxx"
9 #include <qstringlist.h>
10 #include <qregexp.h>
11
12 // ================================================================
13 /*!
14  *  ProductsViewItem::ProductsViewItem
15  *  Constructor
16  */
17 // ================================================================
18 ProductsViewItem::ProductsViewItem( ProductsView* parent, const QString& text, Type tt )
19      : QCheckListItem( parent, text, tt ) 
20 {
21 }
22 // ================================================================
23 /*!
24  *  ProductsViewItem::stateChange
25  *  Called when users switches item on/off
26  */
27 // ================================================================
28 void ProductsViewItem::stateChange( bool on ) {
29   QCheckListItem::stateChange( on );
30   ((ProductsView*)listView())->itemActivated( (QCheckListItem*)this );
31 }
32
33 // ================================================================
34 /*!
35  *  ProductsView::ProductsView
36  *  Constructor
37  */
38 // ================================================================
39 ProductsView::ProductsView( QWidget* parent, const char* name ) 
40   : QListView( parent, name )
41 {
42   setRootIsDecorated( false );
43   addColumn( tr( "Module" ) );
44   addColumn( tr( "Size" ) );
45   setResizeMode( LastColumn );
46   setSorting( -1, false );
47 }
48 // ================================================================
49 /*!
50  *  ProductsView::addItem
51  *  Adds product item into the list
52  */
53 // ================================================================
54 QCheckListItem* ProductsView::addItem( const QString& name, 
55                                        const QString& size, 
56                                        const QString& script )
57 {
58   QCheckListItem* item = 0;
59   item = new ProductsViewItem( this, name, QCheckListItem::CheckBox );
60   item->setText( 1, size );
61   item->setText( 2, script );
62   item->moveItem( this->lastItem() );
63   return item;
64 }
65 // ================================================================
66 /*!
67  *  ProductsView::renameColumn
68  *  Sets the given text as a heading of the given column
69  */
70 // ================================================================
71 void ProductsView::renameColumn( int column, const QString& label )
72 {
73   setColumnText( column, label );
74 }
75 // ================================================================
76 /*!
77  *  ProductsView::itemActivated
78  *  Emits signal when checkbox or radiobutton is switched
79  */
80 // ================================================================
81 void ProductsView::itemActivated( QCheckListItem* item ) {
82   emit itemToggled( item );
83 }
84 // ================================================================
85 /*!
86  *  ProductsView::setItemEnabled
87  *  Enable/disable item
88  */
89 // ================================================================
90 void ProductsView::setItemEnabled( QCheckListItem* item, const bool enable )
91 {
92   item->setEnabled( enable );
93   QListViewItem* subItem = item->firstChild();
94   while( subItem ) {
95     subItem->setEnabled( enable );
96     subItem = subItem->nextSibling();
97   }
98 }
99 // ================================================================
100 /*!
101  *  ProductsView::findBinItem
102  *  Find bin item which corresponds to the src item
103  */
104 // ================================================================
105 QCheckListItem* ProductsView::findBinItem( const QString& srcName )
106 {
107   QString binName = srcName.lower().replace( QRegExp("src"), "bin" );
108   QCheckListItem* subItem = (QCheckListItem*)( firstChild() );
109   while( subItem ) {
110     if ( subItem->text().lower() == binName )
111       return subItem;
112     subItem = (QCheckListItem*)( subItem->nextSibling() );
113   }
114   return 0;
115 }
116