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 << QObject::tr("PRP_MODE_FROM_SCRATCH") <<
60 QObject::tr("PRP_MODE_FROM_COPYFROM");
61 theWidget->insertList(list);
64 case SalomeApp_StudyPropertiesDlg::prpLockedId:
66 list << QObject::tr("PRP_NO") << QObject::tr("PRP_YES");
67 theWidget->insertList(list, getValue() == QObject::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]);
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 SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
118 : QDialog(parent, "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
121 setCaption(tr("TLT_STUDY_PROPERTIES"));
122 setSizeGripEnabled( true );
124 clearWFlags(Qt::WStyle_ContextHelp);
126 QGridLayout* mainLayout = new QGridLayout(this);
127 mainLayout->setMargin(DEFAULT_MARGIN);
128 mainLayout->setSpacing(DEFAULT_SPACING);
130 myPropList = new SalomeApp_ListView(this);
131 myPropList->addColumn("");
132 myPropList->addColumn("");
133 myPropList->enableEditing(TRUE);
134 myPropList->setMinimumSize(MIN_LIST_WIDTH, MIN_LIST_HEIGHT);
135 mainLayout->addMultiCellWidget(myPropList, 0, 0, 0, 2);
137 myOKBtn = new QPushButton(tr("BUT_OK"), this);
138 mainLayout->addWidget(myOKBtn, 1, 0);
140 myCancelBtn = new QPushButton(tr("BUT_CANCEL"), this);
141 mainLayout->addWidget(myCancelBtn, 1, 2);
143 QSpacerItem* spacer1 = new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum);
144 mainLayout->addItem(spacer1, 1, 1);
146 // Display study properties
147 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
149 myStudyDoc = study->studyDS();
153 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
154 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
157 SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
161 void SalomeApp_StudyPropertiesDlg::initData()
163 bool hasData = myStudyDoc;
164 _PTR(AttributeStudyProperties) propAttr;
166 propAttr = myStudyDoc->GetProperties();
167 hasData = hasData && propAttr;
169 // Study author's name
170 SalomeApp_PropItem* item = new SalomeApp_PropItem(myPropList, tr("PRP_AUTHOR")+":", true, prpAuthorId);
172 item->setValue(propAttr->GetUserName());
175 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_DATE")+":", false, prpDateId);
177 int minutes, hours, day, month, year;
178 if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
180 strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
181 item->setValue(strDate);
186 // item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODE")+":", true, prpModeId);
187 // item->setEditingType( SalomeApp_EntityEdit::etComboBox);
188 // if (hasData) item->setValue(propAttr->GetCreationMode());
191 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_LOCKED")+":", true, prpLockedId);
192 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
193 if (hasData) (propAttr->IsLocked()) ? item->setValue(tr("PRP_YES")) : item->setValue(tr("PRP_NO"));
196 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFIED")+":", false, prpSavedId);
198 if (propAttr->IsModified())
199 item->setValue(tr("PRP_YES"));
201 item->setValue(tr("PRP_NO"));
204 // Modifications list
205 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFICATIONS")+":", true, prpModificationsId);
206 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
208 std::vector<std::string> aUsers;
209 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
210 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
211 int aLast = aUsers.size()-1;
214 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
220 val = val + " : " + QString(aUsers[aUsers.size()-1]);
225 myOKBtn->setEnabled(hasData);
228 bool SalomeApp_StudyPropertiesDlg::acceptData()
233 void SalomeApp_StudyPropertiesDlg::onOK()
235 myPropList->accept();
238 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
239 myChanged = propChanged();
240 if ( propAttr && myChanged ) {
241 QListViewItemIterator it( myPropList );
242 // iterate through all items of the listview
243 for ( ; it.current(); ++it ) {
244 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
245 switch (item->getUserType()) {
247 propAttr->SetUserName(item->getValue().stripWhiteSpace().latin1());
250 propAttr->SetCreationMode(item->getValue().stripWhiteSpace().latin1());
253 propAttr->SetLocked(item->getValue().compare(tr("PRP_YES")) == 0);
264 bool SalomeApp_StudyPropertiesDlg::propChanged() {
265 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
267 QListViewItemIterator it( myPropList );
268 // iterate through all items of the listview
269 for ( ; it.current(); ++it ) {
270 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
271 switch (item->getUserType()) {
273 if ( QString( propAttr->GetUserName() ) != item->getValue().stripWhiteSpace() ) {
278 if ( QString( propAttr->GetCreationMode() ) != item->getValue().stripWhiteSpace() ) {
284 bool bLocked = item->getValue().compare( tr( "PRP_YES" ) ) == 0;
285 if ( propAttr->IsLocked() != bLocked ) {