1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SalomeApp_StudyPropertiesDlg.cxx
24 // Author : Sergey ANIKIN
28 #include "SalomeApp_StudyPropertiesDlg.h"
29 #include "SalomeApp_ListView.h"
30 #include "SalomeApp_Study.h"
32 #include "SUIT_Session.h"
33 #include <SUIT_Desktop.h>
34 #include <SUIT_MessageBox.h>
37 #include <SALOMEconfig.h>
38 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
41 #include <QPushButton>
42 #include <QGridLayout>
46 #define DEFAULT_MARGIN 11
47 #define DEFAULT_SPACING 6
49 #define MIN_LIST_WIDTH 300
50 #define MIN_LIST_HEIGHT 150
52 class SalomeApp_PropItem : public SalomeApp_ListViewItem
56 SalomeApp_PropItem(SalomeApp_ListView* parent,
57 const QString theName,
58 const bool theEditable,
59 const int theUserType) :
60 SalomeApp_ListViewItem( parent, QStringList(theName), theEditable )
62 setUserType(theUserType);
65 SalomeApp_PropItem(SalomeApp_ListView* parent,
66 SalomeApp_ListViewItem* after,
67 const QString theName,
68 const bool theEditable,
69 const int theUserType) :
70 SalomeApp_ListViewItem( parent, after, theName, theEditable )
72 setUserType(theUserType);
74 /*! fills widget with initial values (list or single value)*/
75 void fillWidgetWithValues( SalomeApp_EntityEdit* theWidget )
78 switch(getUserType()) {
79 //case SalomeApp_StudyPropertiesDlg::prpModeId:
81 // list << SalomeApp_StudyPropertiesDlg::tr("PRP_MODE_FROM_SCRATCH") <<
82 // SalomeApp_StudyPropertiesDlg::tr("PRP_MODE_FROM_COPYFROM");
83 // theWidget->insertList(list);
86 case SalomeApp_StudyPropertiesDlg::prpLockedId:
88 list << SalomeApp_StudyPropertiesDlg::tr( "PRP_NO" ) << SalomeApp_StudyPropertiesDlg::tr( "PRP_YES" );
89 theWidget->insertList(list, getValue() == SalomeApp_StudyPropertiesDlg::tr( "PRP_NO" ) ? 0 : 1 );
92 case SalomeApp_StudyPropertiesDlg::prpModificationsId:
94 SalomeApp_Study* study =
95 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
97 _PTR(Study) studyDoc = study->studyDS();
98 _PTR(AttributeStudyProperties) propAttr;
100 propAttr = studyDoc->GetProperties();
102 std::vector<std::string> aUsers;
103 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
104 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
105 int aCnt = aUsers.size();
106 for ( int i = 0; i < aCnt; i++ ) {
108 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
114 val = val + " : " + QString( aUsers[i].c_str() );
117 theWidget->setDuplicatesEnabled(true);
118 theWidget->insertList(list);
126 SalomeApp_ListViewItem::fillWidgetWithValues(theWidget);
131 /*! finishes editing of entity */
132 virtual UpdateType finishEditing( SalomeApp_EntityEdit* theWidget ) {
133 if ( getUserType() == SalomeApp_StudyPropertiesDlg::prpModificationsId )
136 return SalomeApp_ListViewItem::finishEditing(theWidget);
140 /*!Constructor. Initialize study properties dialog.*/
141 SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
142 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
148 setWindowTitle(tr("TLT_STUDY_PROPERTIES"));
149 setSizeGripEnabled( true );
151 setWindowFlags( windowFlags() ^ QFlags<Qt::WindowType>(!Qt::WindowContextHelpButtonHint) );
153 QGridLayout* mainLayout = new QGridLayout(this);
154 mainLayout->setMargin(DEFAULT_MARGIN);
155 mainLayout->setSpacing(DEFAULT_SPACING);
157 myPropList = new SalomeApp_ListView(this);
158 myPropList->setColumnCount(2);
161 myPropList->setHeaderLabels( aLabels );
162 myPropList->enableEditing(TRUE);
163 myPropList->setMinimumSize(MIN_LIST_WIDTH, MIN_LIST_HEIGHT);
164 mainLayout->addWidget(myPropList, 0, 0, 1, 3);
166 myOKBtn = new QPushButton(tr("BUT_OK"), this);
167 mainLayout->addWidget(myOKBtn, 1, 0);
169 myCancelBtn = new QPushButton(tr("BUT_CANCEL"), this);
170 mainLayout->addWidget(myCancelBtn, 1, 2);
172 QSpacerItem* spacer1 =
173 new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum);
174 mainLayout->addItem(spacer1, 1, 1);
176 // Display study properties
177 SalomeApp_Study* study =
178 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
180 myStudyDoc = study->studyDS();
184 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
185 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
191 SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
196 Data initializetion for dialog.(Study author's name, date of creation etc.)
198 void SalomeApp_StudyPropertiesDlg::initData()
200 bool hasData = myStudyDoc;
201 _PTR(AttributeStudyProperties) propAttr;
203 propAttr = myStudyDoc->GetProperties();
204 hasData = hasData && propAttr;
206 // Study author's name
207 SalomeApp_PropItem* item = new SalomeApp_PropItem(myPropList, tr("PRP_AUTHOR")+":", true, prpAuthorId);
209 item->setValue(propAttr->GetUserName().c_str());
212 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_DATE")+":", false, prpDateId);
214 int minutes, hours, day, month, year;
215 if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
217 strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
218 item->setValue(strDate);
223 // item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODE")+":", true, prpModeId);
224 // item->setEditingType( SalomeApp_EntityEdit::etComboBox);
225 // if (hasData) item->setValue(propAttr->GetCreationMode());
228 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_LOCKED")+":", true, prpLockedId);
229 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
231 item->setValue( tr( propAttr->IsLocked() ? "PRP_YES" : "PRP_NO" ) );
234 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFIED")+":", false, prpSavedId);
235 bool isModified = false;
236 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>
237 (SUIT_Session::session()->activeApplication()->activeStudy());
239 isModified = study->isModified();
241 if (propAttr->IsModified() != isModified) {
242 propAttr->SetModified((int)isModified);
247 if (propAttr->IsModified())
248 item->setValue( tr( "PRP_YES" ) );
250 item->setValue( tr( "PRP_NO" ) );
253 // Modifications list
254 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFICATIONS")+":", true, prpModificationsId);
255 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
257 std::vector<std::string> aUsers;
258 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
259 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
260 int aLast = aUsers.size()-1;
263 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
269 val = val + " : " + QString(aUsers[aUsers.size()-1].c_str());
274 myOKBtn->setEnabled(hasData);
278 accept data. Return true.
280 bool SalomeApp_StudyPropertiesDlg::acceptData()
286 Fill properties attributes.
288 void SalomeApp_StudyPropertiesDlg::onOK()
290 myPropList->accept();
293 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
294 //myChanged = propChanged();
295 if ( propAttr /*&& myChanged*/ ) {
296 QTreeWidgetItemIterator it( myPropList );
297 // iterate through all items of the listview
299 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(*it);
300 switch (item->getUserType()) {
302 if (QString(propAttr->GetUserName().c_str()) != item->getValue().trimmed()) {
303 if (!propAttr->IsLocked()) {
304 propAttr->SetUserName(item->getValue().trimmed().toStdString());
307 SUIT_MessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(),
308 QObject::tr("WRN_WARNING"),
309 QObject::tr("WRN_STUDY_LOCKED") );
314 // propAttr->SetCreationMode(item->getValue().trimmed().latin1());
318 bool bLocked = item->getValue().compare(tr("PRP_YES")) == 0;
319 if (propAttr->IsLocked() != bLocked) {
320 propAttr->SetLocked(bLocked);
336 Check is properties changed?
338 bool SalomeApp_StudyPropertiesDlg::propChanged()
340 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
342 QTreeWidgetItemIterator it (myPropList);
344 // iterate through all items of the listview
346 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(*it);
347 switch (item->getUserType()) {
349 if ( QString( propAttr->GetUserName().c_str() ) != item->getValue().trimmed() ) {
354 // if ( QString( propAttr->GetCreationMode().c_str() ) != item->getValue().trimmed() ) {
360 bool bLocked = item->getValue().compare( tr( "PRP_YES" ) ) == 0;
361 if ( propAttr->IsLocked() != bLocked ) {