Salome HOME
18d02683466ef1d05b940b222194b40e72262f21
[modules/yacs.git] / src / genericgui / EditionContainer.cxx
1 // Copyright (C) 2006-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "EditionContainer.hxx"
21
22 //#define _DEVDEBUG_
23 #include "YacsTrace.hxx"
24
25 #include "FormContainer.hxx"
26 #include "QtGuiContext.hxx"
27 #include "guiObservers.hxx"
28 #include "Proc.hxx"
29 #include "Message.hxx"
30
31 #include <cassert>
32
33 using namespace std;
34
35 using namespace YACS;
36 using namespace YACS::HMI;
37 using namespace YACS::ENGINE;
38
39 EditionContainer::EditionContainer(Subject* subject,
40                                    QWidget* parent,
41                                    const char* name)
42   : ItemEdition(subject, parent, name)
43 {
44   _wContainer = new FormContainer(this);
45   _wid->gridLayout1->addWidget(_wContainer);
46   connect(_wContainer->cb_resource, SIGNAL(mousePressed()),
47           this, SLOT(fillContainerPanel()));
48   connect(_wContainer->tb_container, SIGNAL(toggled(bool)),
49           this, SLOT(fillContainerPanel())); // --- to update display of current selection
50   _wContainer->tb_container->toggle();
51 }
52
53 EditionContainer::~EditionContainer()
54 {
55 }
56
57 void EditionContainer::update(GuiEvent event, int type, Subject* son)
58 {
59   DEBTRACE("EditionContainer::update");
60   ItemEdition::update(event, type, son);
61   switch (event)
62     {
63     case RENAME:
64     case UPDATE:
65       _wContainer->le_name->setText((son->getName()).c_str());
66       fillContainerPanel();
67       break;
68     default:
69       ;
70     }
71 }
72
73 void EditionContainer::fillContainerPanel()
74 {
75   DEBTRACE("EditionContainer::fillContainerPanel");
76   SubjectContainer *scont = dynamic_cast<SubjectContainer*>(_subject);
77   YASSERT(scont);
78   _wContainer->FillPanel(scont->getContainer());
79 }
80
81 void EditionContainer::onApply()
82 {
83   DEBTRACE("EditionContainer::onApply");
84   bool edited = true;
85   if (!_wContainer->onApply())
86     {
87       _isEdited = true;
88       Message mess(GuiContext::getCurrent()->_lastErrorMessage);
89       return;
90     }
91   edited = false;
92   _isEdited = _isEdited || edited;
93   ItemEdition::onApply();
94 }
95
96 void EditionContainer::onCancel()
97 {
98   DEBTRACE("EditionContainer::onCancel");
99   _wContainer->onCancel();
100   ItemEdition::onCancel();
101 }