2 // File : SALOMEGUI_StudyPropertiesDlg.cxx
3 // Created : Tue Oct 22 12:28:23 2002
4 // Descr : Dialog box for editing of study properties
6 // Author : Sergey ANIKIN
7 // Project : SALOME Pro
9 // Copyright : Open CASCADE
12 #include "SALOMEGUI_StudyPropertiesDlg.h"
14 #include "QAD_Desktop.h"
15 #include "QAD_ListView.h"
17 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
19 #include <qpushbutton.h>
22 #define DEFAULT_MARGIN 11
23 #define DEFAULT_SPACING 6
25 #define MIN_LIST_WIDTH 300
26 #define MIN_LIST_HEIGHT 150
28 class SALOMEGUI_PropItem : public QAD_ListViewItem
32 SALOMEGUI_PropItem(QAD_ListView* parent,
33 const QString theName,
34 const bool theEditable,
35 const int theUserType) :
36 QAD_ListViewItem(parent, theName, theEditable)
38 setUserType(theUserType);
41 SALOMEGUI_PropItem(QAD_ListView* parent,
42 QAD_ListViewItem* after,
43 const QString theName,
44 const bool theEditable,
45 const int theUserType) :
46 QAD_ListViewItem(parent, after, theName, theEditable)
48 setUserType(theUserType);
50 // fills widget with initial values (list or single value)
51 void fillWidgetWithValues(QAD_EntityEdit* theWidget)
54 switch(getUserType()) {
55 case SALOMEGUI_StudyPropertiesDlg::prpModeId:
57 list << QObject::tr("PRP_MODE_FROM_SCRATCH")<< QObject::tr("PRP_MODE_FROM_COPYFROM");
58 theWidget->insertList(list);
61 case SALOMEGUI_StudyPropertiesDlg::prpLockedId:
63 list << QObject::tr("PRP_NO") << QObject::tr("PRP_YES");
64 theWidget->insertList(list, getValue() == QObject::tr("PRP_NO") ? 0 : 1);
67 case SALOMEGUI_StudyPropertiesDlg::prpModificationsId:
69 QAD_Study* study = QAD_Application::getDesktop()->getActiveStudy();
71 SALOMEDS::Study_var studyDoc = study->getStudyDocument();
72 SALOMEDS::AttributeStudyProperties_var propAttr;
73 if (!studyDoc->_is_nil()) {
74 propAttr = studyDoc->GetProperties();
75 if (!propAttr->_is_nil()) {
76 SALOMEDS::StringSeq_var aUsers;
77 SALOMEDS::LongSeq_var aMins, aHours, aDays, aMonths, aYears;
78 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
79 int aCnt = aUsers->length();
80 for ( int i = 0; i < aCnt; i++ ) {
82 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
88 val = val + " : " + QString(aUsers[i]);
91 theWidget->setDuplicatesEnabled(true);
92 theWidget->insertList(list);
100 QAD_ListViewItem::fillWidgetWithValues(theWidget);
105 // finishes editing of entity
106 virtual UpdateType finishEditing(QAD_EntityEdit* theWidget) {
107 if ( getUserType() == SALOMEGUI_StudyPropertiesDlg::prpModificationsId )
110 return QAD_ListViewItem::finishEditing(theWidget);
114 SALOMEGUI_StudyPropertiesDlg::SALOMEGUI_StudyPropertiesDlg(QWidget* parent)
115 : QDialog(parent, "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
118 setCaption(tr("TLT_STUDY_PROPERTIES"));
119 setSizeGripEnabled( true );
121 clearWFlags(Qt::WStyle_ContextHelp);
123 QGridLayout* mainLayout = new QGridLayout(this);
124 mainLayout->setMargin(DEFAULT_MARGIN);
125 mainLayout->setSpacing(DEFAULT_SPACING);
127 myPropList = new QAD_ListView(this);
128 myPropList->addColumn("");
129 myPropList->addColumn("");
130 myPropList->enableEditing(TRUE);
131 myPropList->setMinimumSize(MIN_LIST_WIDTH, MIN_LIST_HEIGHT);
132 mainLayout->addMultiCellWidget(myPropList, 0, 0, 0, 2);
134 myOKBtn = new QPushButton(tr("BUT_OK"), this);
135 mainLayout->addWidget(myOKBtn, 1, 0);
137 myCancelBtn = new QPushButton(tr("BUT_CANCEL"), this);
138 mainLayout->addWidget(myCancelBtn, 1, 2);
140 QSpacerItem* spacer1 = new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum);
141 mainLayout->addItem(spacer1, 1, 1);
143 // Display study properties
144 QAD_Study* study = ((QAD_Desktop*)parent)->getActiveStudy();
145 if (study) myStudyDoc = study->getStudyDocument();
149 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
150 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
153 SALOMEGUI_StudyPropertiesDlg::~SALOMEGUI_StudyPropertiesDlg()
157 void SALOMEGUI_StudyPropertiesDlg::initData()
159 bool hasData = !myStudyDoc->_is_nil();
160 SALOMEDS::AttributeStudyProperties_var propAttr;
161 if (hasData) propAttr = myStudyDoc->GetProperties();
162 hasData = hasData && !propAttr->_is_nil();
164 // Study author's name
165 SALOMEGUI_PropItem* item = new SALOMEGUI_PropItem(myPropList, tr("PRP_AUTHOR")+":", true, prpAuthorId);
166 if (hasData) item->setValue(propAttr->GetUserName());
169 item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_DATE")+":", false, prpDateId);
171 CORBA::Long minutes, hours, day, month, year;
172 if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
174 strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
175 item->setValue(strDate);
180 // item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_MODE")+":", true, prpModeId);
181 // item->setEditingType(QAD_EntityEdit::etComboBox);
182 // if (hasData) item->setValue(propAttr->GetCreationMode());
185 item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_LOCKED")+":", true, prpLockedId);
186 item->setEditingType(QAD_EntityEdit::etComboBox);
187 if (hasData) (propAttr->IsLocked()) ? item->setValue(tr("PRP_YES")) : item->setValue(tr("PRP_NO"));
190 item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_MODIFIED")+":", false, prpSavedId);
192 if (propAttr->IsModified())
193 item->setValue(tr("PRP_YES"));
195 item->setValue(tr("PRP_NO"));
198 // Modifications list
199 item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_MODIFICATIONS")+":", true, prpModificationsId);
200 item->setEditingType(QAD_EntityEdit::etComboBox);
202 SALOMEDS::StringSeq_var aUsers;
203 SALOMEDS::LongSeq_var aMins, aHours, aDays, aMonths, aYears;
204 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
205 int aLast = aUsers->length()-1;
208 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
214 val = val + " : " + QString(aUsers[aUsers->length()-1]);
219 myOKBtn->setEnabled(hasData);
222 bool SALOMEGUI_StudyPropertiesDlg::acceptData()
227 void SALOMEGUI_StudyPropertiesDlg::onOK()
229 myPropList->accept();
232 SALOMEDS::AttributeStudyProperties_var propAttr = myStudyDoc->GetProperties();
233 myChanged = propChanged();
234 if ( !propAttr->_is_nil() && myChanged ) {
235 QListViewItemIterator it( myPropList );
236 // iterate through all items of the listview
237 for ( ; it.current(); ++it ) {
238 SALOMEGUI_PropItem* item = (SALOMEGUI_PropItem*)(it.current());
239 switch (item->getUserType()) {
241 propAttr->SetUserName(item->getValue().stripWhiteSpace().latin1());
244 propAttr->SetCreationMode(item->getValue().stripWhiteSpace().latin1());
247 propAttr->SetLocked(item->getValue().compare(tr("PRP_YES")) == 0);
258 bool SALOMEGUI_StudyPropertiesDlg::propChanged() {
259 SALOMEDS::AttributeStudyProperties_var propAttr = myStudyDoc->GetProperties();
260 if ( !propAttr->_is_nil() ) {
261 QListViewItemIterator it( myPropList );
262 // iterate through all items of the listview
263 for ( ; it.current(); ++it ) {
264 SALOMEGUI_PropItem* item = (SALOMEGUI_PropItem*)(it.current());
265 switch (item->getUserType()) {
267 if ( QString( propAttr->GetUserName() ) != item->getValue().stripWhiteSpace() ) {
272 if ( QString( propAttr->GetCreationMode() ) != item->getValue().stripWhiteSpace() ) {
278 bool bLocked = item->getValue().compare( tr( "PRP_YES" ) ) == 0;
279 if ( propAttr->IsLocked() != bLocked ) {