1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SalomeApp_StudyPropertiesDlg.cxx
25 // Author : Roman NIKOLAEV
27 #include "SalomeApp_StudyPropertiesDlg.h"
28 #include "SalomeApp_Study.h"
30 #include "SUIT_Session.h"
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
35 #include <SALOMEconfig.h>
36 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
39 #include <QPushButton>
40 #include <QGridLayout>
41 #include <QHBoxLayout>
48 #include <QTreeWidget>
49 #include <QPushButton>
53 #define DEFAULT_MARGIN 11
54 #define DEFAULT_SPACING 6
56 #define MIN_LIST_WIDTH 300
57 #define MIN_LIST_HEIGHT 150
60 /*!Constructor. Initialize study properties dialog.*/
61 SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
62 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
67 setWindowTitle(tr("TLT_STUDY_PROPERTIES"));
68 setSizeGripEnabled( true );
70 setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
72 // Display study properties
73 SalomeApp_Study* study =
74 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
76 myStudyDoc = study->studyDS();
79 QLabel* authorLbl = new QLabel(tr("PRP_AUTHOR"),this);
80 myAuthor = new QLineEdit(this);
83 QLabel* dateLbl = new QLabel(tr("PRP_DATE"),this);
84 myDate = new QLabel(this);
87 myLocked = new QCheckBox(tr("PRP_LOCKED"), this);
90 myModification = new QLabel(this);
93 QLabel* unitsLbl = new QLabel(tr("PRP_UNITS"),this);
94 myUnits = new QComboBox(this);
97 QLabel* commentLabel = new QLabel(tr("PRP_COMMENT"),this);
98 myComment = new QTextEdit(this);
99 myComment->setMaximumHeight(80);
102 QLabel* modificationsLabel = new QLabel(tr("PRP_MODIFICATIONS"),this);
103 myModifications = new QTreeWidget(this);
104 myModifications->setRootIsDecorated(false);
105 myModifications->setUniformRowHeights(true);
106 myModifications->setAllColumnsShowFocus(true);
107 myModifications->setColumnCount(2);
108 myModifications->setMaximumHeight(80);
109 QStringList columnNames;
110 columnNames.append(tr("PRP_AUTHOR"));
111 columnNames.append(tr("PRP_DATE_MODIF"));
113 QTreeWidgetItem * headerItem = new QTreeWidgetItem(columnNames);
114 myModifications->setHeaderItem ( headerItem );
116 QFrame* buttonFrame = new QFrame(this);
118 QHBoxLayout* horizontalLayout = new QHBoxLayout(buttonFrame);
120 myOkButton = new QPushButton(tr("BUT_OK"), buttonFrame);
121 myCancelButton = new QPushButton(tr("BUT_CANCEL"), buttonFrame);
123 horizontalLayout->addWidget(myOkButton);
124 horizontalLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum) );
125 horizontalLayout->addWidget(myCancelButton);
127 QGridLayout* gridLayout = new QGridLayout(this);
128 gridLayout->setMargin(DEFAULT_MARGIN);
129 gridLayout->setSpacing(DEFAULT_SPACING);
130 gridLayout->addWidget(authorLbl, 0, 0, 1, 1);
131 gridLayout->addWidget(myAuthor, 0, 1, 1, 1);
132 gridLayout->addWidget(dateLbl, 1, 0, 1, 1);
133 gridLayout->addWidget(myDate, 1, 1, 1, 1);
134 gridLayout->addWidget(myLocked, 2, 0, 1, 1);
135 gridLayout->addWidget(myModification, 2, 1, 1, 1);
136 gridLayout->addWidget(unitsLbl, 3, 0, 1, 1);
137 gridLayout->addWidget(myUnits, 3, 1, 1, 1);
138 gridLayout->addItem(new QSpacerItem(/*72*/0, 0/*20*/, QSizePolicy::Expanding, QSizePolicy::Minimum), 3, 2, 1, 1);
139 gridLayout->addWidget(commentLabel, 4, 0, 1, 1);
140 gridLayout->addWidget(myComment, 4, 1, 1, 2);
141 gridLayout->addWidget(modificationsLabel, 5, 0, 1, 1);
142 gridLayout->addWidget(myModifications, 5, 1, 1, 2);
143 gridLayout->addWidget(buttonFrame, 6, 0, 1, 3);
145 connect(myOkButton, SIGNAL(clicked()), this, SLOT(clickOnOk()));
146 connect(myCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
154 SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
159 Data initializetion for dialog.(Study author's name, date of creation etc.)
161 void SalomeApp_StudyPropertiesDlg::initData()
163 bool hasData = myStudyDoc;
164 _PTR(AttributeStudyProperties) propAttr;
166 propAttr = myStudyDoc->GetProperties();
167 hasData = hasData && propAttr;
170 //Creator and creation date
171 myAuthor->setText(propAttr->GetUserName().c_str());
172 int 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 myDate->setText(strDate);
180 myLocked->setChecked(propAttr->IsLocked());
183 bool isModified = false;
184 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>
185 (SUIT_Session::session()->activeApplication()->activeStudy());
187 isModified = study->isModified();
189 if (propAttr->IsModified() != isModified) {
190 propAttr->SetModified((int)isModified);
195 QString modif = propAttr->IsModified() ? tr( "PRP_MODIFIED" ) : tr( "PRP_NOT_MODIFIED" );
196 myModification->setText(modif);
200 theList <<""<<"mm"<<"cm"<<"m"<<"km"<<"inch";
201 myUnits->insertItems(0,theList);
203 QString anUnit = propAttr->GetUnits().c_str();
206 for (int i = 0; i < myUnits->count(); i++) {
207 if ( myUnits->itemText(i) == anUnit ) {
214 myUnits->setCurrentIndex(aFound);
218 myComment->setPlainText(propAttr->GetComment().c_str());
221 std::vector<std::string> aUsers;
222 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
223 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
224 int aCnt = aUsers.size();
225 for ( int i = 0; i < aCnt; i++ ) {
227 date.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
234 aList.append(aUsers[i].c_str());
236 QTreeWidgetItem* item = new QTreeWidgetItem(aList);
237 myModifications->addTopLevelItem(item);
244 Fill properties attributes.
246 void SalomeApp_StudyPropertiesDlg::clickOnOk()
248 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
249 //Firstly, store locked flag
251 bool bLocked = myLocked->isChecked();
252 if (propAttr->IsLocked() != bLocked) {
253 propAttr->SetLocked(bLocked);
257 bool needWarning = false;
260 if (QString(propAttr->GetUserName().c_str()) != myAuthor->text().trimmed()) {
261 if(!propAttr->IsLocked()) {
262 propAttr->SetUserName(myAuthor->text().trimmed().toStdString());
270 if (QString(propAttr->GetUnits().c_str()) != myUnits->currentText()) {
271 if(!propAttr->IsLocked()) {
272 propAttr->SetUnits(myUnits->currentText().toStdString());
280 if (QString(propAttr->GetComment().c_str()) != myComment->toPlainText()) {
281 if(!propAttr->IsLocked()) {
282 propAttr->SetComment(myComment->toPlainText().toStdString());
290 SUIT_MessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(),
291 QObject::tr("WRN_WARNING"),
292 QObject::tr("WRN_STUDY_LOCKED") );