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"
18 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
20 #include <qpushbutton.h>
24 #define DEFAULT_MARGIN 11
25 #define DEFAULT_SPACING 6
27 #define MIN_LIST_WIDTH 300
28 #define MIN_LIST_HEIGHT 150
30 class SalomeApp_PropItem : public SalomeApp_ListViewItem
34 SalomeApp_PropItem(SalomeApp_ListView* parent,
35 const QString theName,
36 const bool theEditable,
37 const int theUserType) :
38 SalomeApp_ListViewItem( parent, theName, theEditable )
40 setUserType(theUserType);
43 SalomeApp_PropItem(SalomeApp_ListView* parent,
44 SalomeApp_ListViewItem* after,
45 const QString theName,
46 const bool theEditable,
47 const int theUserType) :
48 SalomeApp_ListViewItem( parent, after, theName, theEditable )
50 setUserType(theUserType);
52 /*! fills widget with initial values (list or single value)*/
53 void fillWidgetWithValues( SalomeApp_EntityEdit* theWidget )
56 switch(getUserType()) {
57 case SalomeApp_StudyPropertiesDlg::prpModeId:
59 list << SalomeApp_StudyPropertiesDlg::tr("PRP_MODE_FROM_SCRATCH") <<
60 SalomeApp_StudyPropertiesDlg::tr("PRP_MODE_FROM_COPYFROM");
61 theWidget->insertList(list);
64 case SalomeApp_StudyPropertiesDlg::prpLockedId:
66 list << SalomeApp_StudyPropertiesDlg::tr( "PRP_NO" ) << SalomeApp_StudyPropertiesDlg::tr( "PRP_YES" );
67 theWidget->insertList(list, getValue() == SalomeApp_StudyPropertiesDlg::tr( "PRP_NO" ) ? 0 : 1 );
70 case SalomeApp_StudyPropertiesDlg::prpModificationsId:
72 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
74 _PTR(Study) studyDoc = study->studyDS();
75 _PTR(AttributeStudyProperties) propAttr;
77 propAttr = studyDoc->GetProperties();
79 std::vector<std::string> aUsers;
80 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
81 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
82 int aCnt = aUsers.size();
83 for ( int i = 0; i < aCnt; i++ ) {
85 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
91 val = val + " : " + QString( aUsers[i].c_str() );
94 theWidget->setDuplicatesEnabled(true);
95 theWidget->insertList(list);
103 SalomeApp_ListViewItem::fillWidgetWithValues(theWidget);
108 /*! finishes editing of entity */
109 virtual UpdateType finishEditing( SalomeApp_EntityEdit* theWidget ) {
110 if ( getUserType() == SalomeApp_StudyPropertiesDlg::prpModificationsId )
113 return SalomeApp_ListViewItem::finishEditing(theWidget);
117 /*!Constructor. Initialize study properties dialog.*/
118 SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
119 : QDialog(parent, "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
122 setCaption(tr("TLT_STUDY_PROPERTIES"));
123 setSizeGripEnabled( true );
125 clearWFlags(Qt::WStyle_ContextHelp);
127 QGridLayout* mainLayout = new QGridLayout(this);
128 mainLayout->setMargin(DEFAULT_MARGIN);
129 mainLayout->setSpacing(DEFAULT_SPACING);
131 myPropList = new SalomeApp_ListView(this);
132 myPropList->addColumn("");
133 myPropList->addColumn("");
134 myPropList->enableEditing(TRUE);
135 myPropList->setMinimumSize(MIN_LIST_WIDTH, MIN_LIST_HEIGHT);
136 mainLayout->addMultiCellWidget(myPropList, 0, 0, 0, 2);
138 myOKBtn = new QPushButton(tr("BUT_OK"), this);
139 mainLayout->addWidget(myOKBtn, 1, 0);
141 myCancelBtn = new QPushButton(tr("BUT_CANCEL"), this);
142 mainLayout->addWidget(myCancelBtn, 1, 2);
144 QSpacerItem* spacer1 = new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum);
145 mainLayout->addItem(spacer1, 1, 1);
147 // Display study properties
148 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
150 myStudyDoc = study->studyDS();
154 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
155 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
161 SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
166 Data initializetion for dialog.(Study author's name, date of creation etc.)
168 void SalomeApp_StudyPropertiesDlg::initData()
170 bool hasData = myStudyDoc;
171 _PTR(AttributeStudyProperties) propAttr;
173 propAttr = myStudyDoc->GetProperties();
174 hasData = hasData && propAttr;
176 // Study author's name
177 SalomeApp_PropItem* item = new SalomeApp_PropItem(myPropList, tr("PRP_AUTHOR")+":", true, prpAuthorId);
179 item->setValue(propAttr->GetUserName().c_str());
182 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_DATE")+":", false, prpDateId);
184 int minutes, hours, day, month, year;
185 if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
187 strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
188 item->setValue(strDate);
193 // item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODE")+":", true, prpModeId);
194 // item->setEditingType( SalomeApp_EntityEdit::etComboBox);
195 // if (hasData) item->setValue(propAttr->GetCreationMode());
198 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_LOCKED")+":", true, prpLockedId);
199 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
201 item->setValue( tr( propAttr->IsLocked() ? "PRP_YES" : "PRP_NO" ) );
204 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFIED")+":", false, prpSavedId);
206 if (propAttr->IsModified())
207 item->setValue( tr( "PRP_YES" ) );
209 item->setValue( tr( "PRP_NO" ) );
212 // Modifications list
213 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFICATIONS")+":", true, prpModificationsId);
214 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
216 std::vector<std::string> aUsers;
217 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
218 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
219 int aLast = aUsers.size()-1;
222 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
228 val = val + " : " + QString(aUsers[aUsers.size()-1].c_str());
233 myOKBtn->setEnabled(hasData);
237 accept data. Return true.
239 bool SalomeApp_StudyPropertiesDlg::acceptData()
245 Fill properties attributes.
247 void SalomeApp_StudyPropertiesDlg::onOK()
249 myPropList->accept();
252 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
253 myChanged = propChanged();
254 if ( propAttr && myChanged ) {
255 QListViewItemIterator it( myPropList );
256 // iterate through all items of the listview
257 for ( ; it.current(); ++it ) {
258 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
259 switch (item->getUserType()) {
261 propAttr->SetUserName(item->getValue().stripWhiteSpace().latin1());
264 propAttr->SetCreationMode(item->getValue().stripWhiteSpace().latin1());
267 propAttr->SetLocked(item->getValue().compare(tr("PRP_YES")) == 0);
279 Check is properties chenged?
281 bool SalomeApp_StudyPropertiesDlg::propChanged() {
282 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
284 QListViewItemIterator it( myPropList );
285 // iterate through all items of the listview
286 for ( ; it.current(); ++it ) {
287 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
288 switch (item->getUserType()) {
290 if ( QString( propAttr->GetUserName().c_str() ) != item->getValue().stripWhiteSpace() ) {
295 if ( QString( propAttr->GetCreationMode().c_str() ) != item->getValue().stripWhiteSpace() ) {
301 bool bLocked = item->getValue().compare( tr( "PRP_YES" ) ) == 0;
302 if ( propAttr->IsLocked() != bLocked ) {