3 // Copyright (C) 2005 CEA/DEN, EDF R&D
7 // File : SalomeApp_StudyPropertiesDlg.cxx
8 // Author : Sergey ANIKIN
12 #include "SalomeApp_StudyPropertiesDlg.h"
13 #include "SalomeApp_ListView.h"
14 #include "SalomeApp_Study.h"
16 #include "SUIT_Session.h"
17 #include <SUIT_Desktop.h>
18 #include <SUIT_MessageBox.h>
21 #include <OSD_Process.hxx>
22 #include <Quantity_Date.hxx>
25 #include <SALOMEconfig.h>
26 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
29 #include <qpushbutton.h>
34 #define DEFAULT_MARGIN 11
35 #define DEFAULT_SPACING 6
37 #define MIN_LIST_WIDTH 300
38 #define MIN_LIST_HEIGHT 150
40 class SalomeApp_PropItem : public SalomeApp_ListViewItem
44 SalomeApp_PropItem(SalomeApp_ListView* parent,
45 const QString theName,
46 const bool theEditable,
47 const int theUserType) :
48 SalomeApp_ListViewItem( parent, theName, theEditable )
50 setUserType(theUserType);
53 SalomeApp_PropItem(SalomeApp_ListView* parent,
54 SalomeApp_ListViewItem* after,
55 const QString theName,
56 const bool theEditable,
57 const int theUserType) :
58 SalomeApp_ListViewItem( parent, after, theName, theEditable )
60 setUserType(theUserType);
62 /*! fills widget with initial values (list or single value)*/
63 void fillWidgetWithValues( SalomeApp_EntityEdit* theWidget )
66 switch(getUserType()) {
67 //case SalomeApp_StudyPropertiesDlg::prpModeId:
69 // list << SalomeApp_StudyPropertiesDlg::tr("PRP_MODE_FROM_SCRATCH") <<
70 // SalomeApp_StudyPropertiesDlg::tr("PRP_MODE_FROM_COPYFROM");
71 // theWidget->insertList(list);
74 case SalomeApp_StudyPropertiesDlg::prpLockedId:
76 list << SalomeApp_StudyPropertiesDlg::tr( "PRP_NO" ) << SalomeApp_StudyPropertiesDlg::tr( "PRP_YES" );
77 theWidget->insertList(list, getValue() == SalomeApp_StudyPropertiesDlg::tr( "PRP_NO" ) ? 0 : 1 );
80 case SalomeApp_StudyPropertiesDlg::prpModificationsId:
82 SalomeApp_Study* study =
83 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
85 _PTR(Study) studyDoc = study->studyDS();
86 _PTR(AttributeStudyProperties) propAttr;
88 propAttr = studyDoc->GetProperties();
90 std::vector<std::string> aUsers;
91 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
92 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
93 int aCnt = aUsers.size();
94 for ( int i = 0; i < aCnt; i++ ) {
96 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
102 val = val + " : " + QString( aUsers[i].c_str() );
105 theWidget->setDuplicatesEnabled(true);
106 theWidget->insertList(list);
114 SalomeApp_ListViewItem::fillWidgetWithValues(theWidget);
119 /*! finishes editing of entity */
120 virtual UpdateType finishEditing( SalomeApp_EntityEdit* theWidget ) {
121 if ( getUserType() == SalomeApp_StudyPropertiesDlg::prpModificationsId )
124 return SalomeApp_ListViewItem::finishEditing(theWidget);
128 /*!Constructor. Initialize study properties dialog.*/
129 SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
130 : QDialog(parent, "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
133 setCaption(tr("TLT_STUDY_PROPERTIES"));
134 setSizeGripEnabled( true );
136 clearWFlags(Qt::WStyle_ContextHelp);
138 QGridLayout* mainLayout = new QGridLayout(this);
139 mainLayout->setMargin(DEFAULT_MARGIN);
140 mainLayout->setSpacing(DEFAULT_SPACING);
142 myPropList = new SalomeApp_ListView(this);
143 myPropList->addColumn("");
144 myPropList->addColumn("");
145 myPropList->enableEditing(TRUE);
146 myPropList->setMinimumSize(MIN_LIST_WIDTH, MIN_LIST_HEIGHT);
147 mainLayout->addMultiCellWidget(myPropList, 0, 0, 0, 2);
149 myOKBtn = new QPushButton(tr("BUT_OK"), this);
150 mainLayout->addWidget(myOKBtn, 1, 0);
152 myCancelBtn = new QPushButton(tr("BUT_CANCEL"), this);
153 mainLayout->addWidget(myCancelBtn, 1, 2);
155 QSpacerItem* spacer1 =
156 new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum);
157 mainLayout->addItem(spacer1, 1, 1);
159 // Display study properties
160 SalomeApp_Study* study =
161 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
163 myStudyDoc = study->studyDS();
167 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
168 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
174 SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
179 Data initializetion for dialog.(Study author's name, date of creation etc.)
181 void SalomeApp_StudyPropertiesDlg::initData()
183 bool hasData = myStudyDoc;
184 _PTR(AttributeStudyProperties) propAttr;
186 propAttr = myStudyDoc->GetProperties();
187 hasData = hasData && propAttr;
189 // Study author's name
190 SalomeApp_PropItem* item = new SalomeApp_PropItem(myPropList, tr("PRP_AUTHOR")+":", true, prpAuthorId);
192 item->setValue(propAttr->GetUserName().c_str());
195 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_DATE")+":", false, prpDateId);
197 int minutes, hours, day, month, year;
198 if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
200 strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
201 item->setValue(strDate);
206 // item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODE")+":", true, prpModeId);
207 // item->setEditingType( SalomeApp_EntityEdit::etComboBox);
208 // if (hasData) item->setValue(propAttr->GetCreationMode());
211 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_LOCKED")+":", true, prpLockedId);
212 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
214 item->setValue( tr( propAttr->IsLocked() ? "PRP_YES" : "PRP_NO" ) );
217 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFIED")+":", false, prpSavedId);
218 bool isModified = false;
219 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>
220 (SUIT_Session::session()->activeApplication()->activeStudy());
222 isModified = study->isModified();
224 if (propAttr->IsModified() != isModified) {
225 propAttr->SetModified((int)isModified);
230 if (propAttr->IsModified())
231 item->setValue( tr( "PRP_YES" ) );
233 item->setValue( tr( "PRP_NO" ) );
236 // Modifications list
237 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFICATIONS")+":", true, prpModificationsId);
238 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
240 std::vector<std::string> aUsers;
241 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
242 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
243 int aLast = aUsers.size()-1;
246 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
252 val = val + " : " + QString(aUsers[aUsers.size()-1].c_str());
257 myOKBtn->setEnabled(hasData);
261 accept data. Return true.
263 bool SalomeApp_StudyPropertiesDlg::acceptData()
269 Fill properties attributes.
271 void SalomeApp_StudyPropertiesDlg::onOK()
273 myPropList->accept();
276 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
277 //myChanged = propChanged();
278 if ( propAttr /*&& myChanged*/ ) {
279 QListViewItemIterator it( myPropList );
280 // iterate through all items of the listview
281 for ( ; it.current(); ++it ) {
282 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
283 switch (item->getUserType()) {
285 if (QString(propAttr->GetUserName().c_str()) != item->getValue().stripWhiteSpace()) {
286 if (!propAttr->IsLocked()) {
287 propAttr->SetUserName(item->getValue().stripWhiteSpace().latin1());
290 SUIT_MessageBox::warn1(SUIT_Session::session()->activeApplication()->desktop(),
291 QObject::tr("WRN_WARNING"),
292 QObject::tr("WRN_STUDY_LOCKED"),
293 QObject::tr("BUT_OK"));
298 // propAttr->SetCreationMode(item->getValue().stripWhiteSpace().latin1());
302 bool bLocked = item->getValue().compare(tr("PRP_YES")) == 0;
303 if (propAttr->IsLocked() != bLocked) {
304 propAttr->SetLocked(bLocked);
319 Check is properties changed?
321 bool SalomeApp_StudyPropertiesDlg::propChanged()
323 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
325 QListViewItemIterator it (myPropList);
326 // iterate through all items of the listview
327 for (; it.current(); ++it) {
328 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
329 switch (item->getUserType()) {
331 if ( QString( propAttr->GetUserName().c_str() ) != item->getValue().stripWhiteSpace() ) {
336 // if ( QString( propAttr->GetCreationMode().c_str() ) != item->getValue().stripWhiteSpace() ) {
342 bool bLocked = item->getValue().compare( tr( "PRP_YES" ) ) == 0;
343 if ( propAttr->IsLocked() != bLocked ) {