1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOMEGUI_StudyPropertiesDlg.cxx
8 // Author : Sergey ANIKIN
13 #include "SALOMEGUI_StudyPropertiesDlg.h"
15 #include "QAD_Desktop.h"
16 #include "QAD_ListView.h"
18 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
20 #include <qpushbutton.h>
23 #define DEFAULT_MARGIN 11
24 #define DEFAULT_SPACING 6
26 #define MIN_LIST_WIDTH 300
27 #define MIN_LIST_HEIGHT 150
29 class SALOMEGUI_PropItem : public QAD_ListViewItem
33 SALOMEGUI_PropItem(QAD_ListView* parent,
34 const QString theName,
35 const bool theEditable,
36 const int theUserType) :
37 QAD_ListViewItem(parent, theName, theEditable)
39 setUserType(theUserType);
42 SALOMEGUI_PropItem(QAD_ListView* parent,
43 QAD_ListViewItem* after,
44 const QString theName,
45 const bool theEditable,
46 const int theUserType) :
47 QAD_ListViewItem(parent, after, theName, theEditable)
49 setUserType(theUserType);
51 // fills widget with initial values (list or single value)
52 void fillWidgetWithValues(QAD_EntityEdit* theWidget)
55 switch(getUserType()) {
56 case SALOMEGUI_StudyPropertiesDlg::prpModeId:
58 list << QObject::tr("PRP_MODE_FROM_SCRATCH")<< QObject::tr("PRP_MODE_FROM_COPYFROM");
59 theWidget->insertList(list);
62 case SALOMEGUI_StudyPropertiesDlg::prpLockedId:
64 list << QObject::tr("PRP_NO") << QObject::tr("PRP_YES");
65 theWidget->insertList(list, getValue() == QObject::tr("PRP_NO") ? 0 : 1);
68 case SALOMEGUI_StudyPropertiesDlg::prpModificationsId:
70 QAD_Study* study = QAD_Application::getDesktop()->getActiveStudy();
72 SALOMEDS::Study_var studyDoc = study->getStudyDocument();
73 SALOMEDS::AttributeStudyProperties_var propAttr;
74 if (!studyDoc->_is_nil()) {
75 propAttr = studyDoc->GetProperties();
76 if (!propAttr->_is_nil()) {
77 SALOMEDS::StringSeq_var aUsers;
78 SALOMEDS::LongSeq_var aMins, aHours, aDays, aMonths, aYears;
79 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
80 int aCnt = aUsers->length();
81 for ( int i = 0; i < aCnt; i++ ) {
83 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
89 val = val + " : " + QString(aUsers[i]);
92 theWidget->setDuplicatesEnabled(true);
93 theWidget->insertList(list);
101 QAD_ListViewItem::fillWidgetWithValues(theWidget);
106 // finishes editing of entity
107 virtual UpdateType finishEditing(QAD_EntityEdit* theWidget) {
108 if ( getUserType() == SALOMEGUI_StudyPropertiesDlg::prpModificationsId )
111 return QAD_ListViewItem::finishEditing(theWidget);
115 SALOMEGUI_StudyPropertiesDlg::SALOMEGUI_StudyPropertiesDlg(QWidget* parent)
116 : QDialog(parent, "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
119 setCaption(tr("TLT_STUDY_PROPERTIES"));
120 setSizeGripEnabled( true );
122 clearWFlags(Qt::WStyle_ContextHelp);
124 QGridLayout* mainLayout = new QGridLayout(this);
125 mainLayout->setMargin(DEFAULT_MARGIN);
126 mainLayout->setSpacing(DEFAULT_SPACING);
128 myPropList = new QAD_ListView(this);
129 myPropList->addColumn("");
130 myPropList->addColumn("");
131 myPropList->enableEditing(TRUE);
132 myPropList->setMinimumSize(MIN_LIST_WIDTH, MIN_LIST_HEIGHT);
133 mainLayout->addMultiCellWidget(myPropList, 0, 0, 0, 2);
135 myOKBtn = new QPushButton(tr("BUT_OK"), this);
136 mainLayout->addWidget(myOKBtn, 1, 0);
138 myCancelBtn = new QPushButton(tr("BUT_CANCEL"), this);
139 mainLayout->addWidget(myCancelBtn, 1, 2);
141 QSpacerItem* spacer1 = new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum);
142 mainLayout->addItem(spacer1, 1, 1);
144 // Display study properties
145 QAD_Study* study = ((QAD_Desktop*)parent)->getActiveStudy();
146 if (study) myStudyDoc = study->getStudyDocument();
150 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
151 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
154 SALOMEGUI_StudyPropertiesDlg::~SALOMEGUI_StudyPropertiesDlg()
158 void SALOMEGUI_StudyPropertiesDlg::initData()
160 bool hasData = !myStudyDoc->_is_nil();
161 SALOMEDS::AttributeStudyProperties_var propAttr;
162 if (hasData) propAttr = myStudyDoc->GetProperties();
163 hasData = hasData && !propAttr->_is_nil();
165 // Study author's name
166 SALOMEGUI_PropItem* item = new SALOMEGUI_PropItem(myPropList, tr("PRP_AUTHOR")+":", true, prpAuthorId);
167 if (hasData) item->setValue(propAttr->GetUserName());
170 item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_DATE")+":", false, prpDateId);
172 CORBA::Long minutes, hours, day, month, year;
173 if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
175 strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
176 item->setValue(strDate);
181 // item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_MODE")+":", true, prpModeId);
182 // item->setEditingType(QAD_EntityEdit::etComboBox);
183 // if (hasData) item->setValue(propAttr->GetCreationMode());
186 item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_LOCKED")+":", true, prpLockedId);
187 item->setEditingType(QAD_EntityEdit::etComboBox);
188 if (hasData) (propAttr->IsLocked()) ? item->setValue(tr("PRP_YES")) : item->setValue(tr("PRP_NO"));
191 item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_MODIFIED")+":", false, prpSavedId);
193 if (propAttr->IsModified())
194 item->setValue(tr("PRP_YES"));
196 item->setValue(tr("PRP_NO"));
199 // Modifications list
200 item = new SALOMEGUI_PropItem(myPropList, item, tr("PRP_MODIFICATIONS")+":", true, prpModificationsId);
201 item->setEditingType(QAD_EntityEdit::etComboBox);
203 SALOMEDS::StringSeq_var aUsers;
204 SALOMEDS::LongSeq_var aMins, aHours, aDays, aMonths, aYears;
205 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
206 int aLast = aUsers->length()-1;
209 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
215 val = val + " : " + QString(aUsers[aUsers->length()-1]);
220 myOKBtn->setEnabled(hasData);
223 bool SALOMEGUI_StudyPropertiesDlg::acceptData()
228 void SALOMEGUI_StudyPropertiesDlg::onOK()
230 myPropList->accept();
233 SALOMEDS::AttributeStudyProperties_var propAttr = myStudyDoc->GetProperties();
234 myChanged = propChanged();
235 if ( !propAttr->_is_nil() && myChanged ) {
236 QListViewItemIterator it( myPropList );
237 // iterate through all items of the listview
238 for ( ; it.current(); ++it ) {
239 SALOMEGUI_PropItem* item = (SALOMEGUI_PropItem*)(it.current());
240 switch (item->getUserType()) {
242 propAttr->SetUserName(item->getValue().stripWhiteSpace().latin1());
245 propAttr->SetCreationMode(item->getValue().stripWhiteSpace().latin1());
248 propAttr->SetLocked(item->getValue().compare(tr("PRP_YES")) == 0);
259 bool SALOMEGUI_StudyPropertiesDlg::propChanged() {
260 SALOMEDS::AttributeStudyProperties_var propAttr = myStudyDoc->GetProperties();
261 if ( !propAttr->_is_nil() ) {
262 QListViewItemIterator it( myPropList );
263 // iterate through all items of the listview
264 for ( ; it.current(); ++it ) {
265 SALOMEGUI_PropItem* item = (SALOMEGUI_PropItem*)(it.current());
266 switch (item->getUserType()) {
268 if ( QString( propAttr->GetUserName() ) != item->getValue().stripWhiteSpace() ) {
273 if ( QString( propAttr->GetCreationMode() ) != item->getValue().stripWhiteSpace() ) {
279 bool bLocked = item->getValue().compare( tr( "PRP_YES" ) ) == 0;
280 if ( propAttr->IsLocked() != bLocked ) {