Salome HOME
Merge branch 'BR_v14_rc' into BR_SINUSX_FORMAT
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ExportSinusXDlg.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROGUI_ExportSinusXDlg.h>
20 #include <HYDROGUI_Module.h>
21 #include <QtxDoubleSpinBox.h>
22 #include <QLayout>
23 #include <QLabel>
24 #include <QStackedWidget>
25 #include <QPushButton>
26 #include "HYDROGUI_Module.h"
27 #include <CAM_Application.h>
28 #include <SUIT_Desktop.h>
29 #include <QListWidget.h>
30
31
32 HYDROGUI_ExportSinusXDlg::HYDROGUI_ExportSinusXDlg( HYDROGUI_Module* theModule, const QString& theTitle )
33 : HYDROGUI_InputPanel( theModule, theTitle, false )
34 {
35   QFrame* aFrame = new QFrame( mainFrame() );
36   addWidget( aFrame, 1 );
37
38   QGridLayout* aLayout = new QGridLayout( aFrame );
39   aLayout->setMargin( 5 );
40   aLayout->setSpacing( 5 );
41
42   myQListW = new QListWidget(mainFrame());
43
44   myQListW->setSelectionMode(QAbstractItemView::ExtendedSelection);
45   aLayout->addWidget(myQListW, 0, 0, 1, 2);
46
47   myIncludeBtn = new QPushButton( tr( "INCLUDE" ) );
48   myExcludeBtn = new QPushButton( tr( "EXCLUDE" ) );
49   aLayout->addWidget(myIncludeBtn, 1, 0 );
50   aLayout->addWidget(myExcludeBtn, 1, 1 );
51
52   myExport = new QPushButton( tr( "EXPORT" ) );
53
54   QHBoxLayout* aBtnsLayout = qobject_cast<QHBoxLayout*>(buttonFrame()->layout());
55   aBtnsLayout->addWidget( myExport, 0 );
56   aBtnsLayout->addWidget( myCancel, 0 );
57   aBtnsLayout->addStretch( 1 );
58   aBtnsLayout->addWidget( myHelp, 0 );
59   
60   //TODO connect 
61   //connect( myExport,  SIGNAL( clicked() ), SLOT( onExport() ) );
62   connect( myIncludeBtn, SIGNAL( clicked() ), SIGNAL( IncludeItems() ) );
63   connect( myExcludeBtn, SIGNAL( clicked() ), SIGNAL( ExcludeItems() ) );
64
65   myEnt2WIMap.clear();
66
67 }
68
69 HYDROGUI_ExportSinusXDlg::~HYDROGUI_ExportSinusXDlg()
70 {
71 }
72
73 void HYDROGUI_ExportSinusXDlg::addItems(const HYDROData_SequenceOfObjects& theSelectedItems)
74 {
75   for (int i = 1; i <= theSelectedItems.Size(); i++)
76   {
77     QString anEntName = theSelectedItems.Value(i)->GetName();
78     if (!myEnt2WIMap.contains(anEntName))
79     {
80       QListWidgetItem* aWI = new QListWidgetItem();
81       aWI->setText(anEntName);
82       myEnt2WIMap[anEntName] = aWI; ///TODO free this map
83       myQListW->addItem(aWI);
84     }
85   }
86   myQListW->update();
87 }
88
89 void HYDROGUI_ExportSinusXDlg::RemoveItems()
90 {
91   for (int i = 0; i < myQListW->selectedItems().size(); i++)
92   {
93     QListWidgetItem* anItem = myQListW->selectedItems()[i];
94     QMap<QString, QListWidgetItem*>::iterator aMapIt;
95     for (aMapIt = myEnt2WIMap.begin(); aMapIt != myEnt2WIMap.end(); ++aMapIt)
96       if (aMapIt.value() == anItem)
97       {
98         aMapIt = myEnt2WIMap.erase(aMapIt);
99         delete anItem;
100         //myQListW->takeItem(anItem);
101       }
102       else
103         ++aMapIt;
104   }
105   myQListW->update();
106 }
107