GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoOpenCreateImgSessionPage.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
35 #include "QueryDataBaseHelper.h"
37 #include "QGoWizardDB.h"
38 
39 #include <QGridLayout>
40 
42  QWizardPage(iParent),
43  m_DatabaseConnector(0)
44 {
45  QFont tfont;
46 
47  tfont.setBold(false);
48  this->setFont(tfont);
49 
51  new QRadioButton( tr("Create a new Imaging Session ") );
53  new QRadioButton( tr("Open an existing Imaging Session") );
54 
55  textChoiceImgSession = new QLabel( tr("Imaging Session to open:") );
57  textDescription = new QLabel( tr("Description:") );
61 
62  QVBoxLayout *vlayout = new QVBoxLayout;
63  QVBoxLayout *RadioButtonLayout = new QVBoxLayout;
64  RadioButtonLayout->addWidget(CreateImgSessionRadioButton);
65  RadioButtonLayout->addWidget(OpenImgSessionRadioButton);
66  vlayout->addLayout(RadioButtonLayout);
67  vlayout->setAlignment(RadioButtonLayout, Qt::AlignHCenter);
68  QGridLayout *gridlayout = new QGridLayout;
69  gridlayout->addWidget(textChoiceImgSession, 0, 0);
70  gridlayout->addWidget(ChoiceImgSession, 0, 1);
71  gridlayout->addWidget(textDescription, 3, 0);
72  gridlayout->addWidget(lineDescription, 3, 1);
73  vlayout->addLayout(gridlayout);
74  setLayout(vlayout);
75 
76  registerField("ImgSessionName", lineImgSessionName);
77  registerField("ImgSessionID", lineImgSessionID);
78 
79  QObject::connect( this->ChoiceImgSession, SIGNAL( currentIndexChanged(QString) ),
80  this, SLOT( DisplayInfoImgSession(QString) ) );
81 
82  QObject::connect( this->OpenImgSessionRadioButton, SIGNAL( clicked() ),
83  this, SLOT( ChangeToOpenImgSessionDisplay() ) );
84 
85  QObject::connect( this->CreateImgSessionRadioButton, SIGNAL( clicked() ),
86  this, SLOT( ChangeToCreateImgSessionDisplay() ) );
87 }
88 
89 //-------------------------------------------------------------------------
90 
91 //-------------------------------------------------------------------------
93 {
94  delete lineImgSessionID;
95  delete lineImgSessionName;
96 }
97 
98 //-------------------------------------------------------------------------
99 
100 //-------------------------------------------------------------------------
102 {
103  if ( !m_ListImgSession.isEmpty() )
104  {
106  }
108 
110 
111  if ( !GetListImgSession() )
112  {
113  std::cout << "Pb, there is no existing Img session" << std::endl;
114  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
115  std::cout << std::endl;
116  }
117  else
118  {
123  this->setFinalPage(false);
124  }
125 
127 }
128 
129 //-------------------------------------------------------------------------
130 
131 //-------------------------------------------------------------------------
133 {
136  m_MapImgSessionIDName.clear();
137 
138  //m_MapImgSessionIDName = MapTwoColumnsFromTable( m_DatabaseConnector,
139  // "Name", "ImagingSessionID",
140  // "imagingsession", "ProjectName",
141  //
142  //
143  //
144  //
145  //
146  //
147  //
148  //
149  //
150  //
151  //
152  //
153  //
154  //
155  //
156  //
157  //
158  // field("ProjectName").toString().toStdString()
159  // );
160  std::vector< std::string > ImgSessionAttributes (2);
161  ImgSessionAttributes[0] = "Name";
162  ImgSessionAttributes[1] = "ImagingSessionID";
164  MapTwoColumnsFromTable( m_DatabaseConnector, ImgSessionAttributes, "imagingsession", "ProjectName",
165  field(
166  "ProjectName").toString().toStdString() );
167 
168  boost::unordered_map< std::string, std::string >::iterator it = m_MapImgSessionIDName.begin();
169  if ( !m_MapImgSessionIDName.empty() )
170  {
171  while ( it != m_MapImgSessionIDName.end() )
172  {
173  m_ListImgSession.append( it->first.c_str() );
174  ++it;
175  }
176  return true;
177  }
178  return false;
179 }
180 
181 //-------------------------------------------------------------------------
182 
183 //-------------------------------------------------------------------------
185 {
186  if ( m_DatabaseConnector == 0 && !LeavingPage )
187  {
189  }
190 
192  {
194  }
195  return -1;
196 }
197 
198 //-------------------------------------------------------------------------
199 
200 //-------------------------------------------------------------------------
202 {
204  {
206  }
207  LeavingPage = true;
208 
209  //get the imagingsessionID from the selected imagingsession in the combobox
210  //in case the user wants to open an imagingsession:
212  {
213  std::string ImgID =
215  setField( "ImgSessionID", ImgID.c_str() );
216  setField( "ImgSessionName", ChoiceImgSession->currentText() );
217  }
218  return true;
219 }
220 
221 //-------------------------------------------------------------------------
222 
223 //-------------------------------------------------------------------------
225 {
227  {
229  }
230 }
231 
232 //-------------------------------------------------------------------------
233 
234 //-------------------------------------------------------------------------
236 {
237  std::string Server = field("ServerName").toString().toStdString();
238  std::string User = field("User").toString().toStdString();
239  std::string Password = field("Password").toString().toStdString();
240  std::string DBName = field("DBName").toString().toStdString();
241 
242  m_DatabaseConnector = OpenDatabaseConnection(Server, User, Password, DBName);
243 
244  LeavingPage = false;
245 }
246 
247 //-------------------------------------------------------------------------
248 
249 //-------------------------------------------------------------------------
251  QString ImgSessionName)
252 {
253  // First, get the corresponding ImagingSessionID from the map:
254  std::string ImagingSessionID = "0";
255 
256  if ( ImgSessionName != "" )
257  {
258  boost::unordered_map< std::string, std::string >::iterator it = m_MapImgSessionIDName.begin();
259  while ( it != m_MapImgSessionIDName.end() && ImagingSessionID == "0" )
260  {
261  if ( it->first == ImgSessionName.toStdString() )
262  {
263  ImagingSessionID = it->second;
264  }
265  ++it;
266  }
267 
268  std::vector< std::string > ListDescription = ListSpecificValuesForOneColumn(
269  m_DatabaseConnector, "imagingsession", "Description",
270  "ImagingSessionID", ImagingSessionID);
271  if ( ListDescription.size() != 1 )
272  {
273  std::cout << "Pb, the imagingsession " << ImgSessionName.toStdString().c_str()
274  << "has more than 1 description" << std::endl;
275  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
276  std::cout << std::endl;
277  }
278 
279  lineDescription->setText( ListDescription[0].c_str() );
280  }
281  this->setFinalPage(false);
282 }
283 
284 //-------------------------------------------------------------------------
285 
286 //-------------------------------------------------------------------------
288 {
289  setSubTitle(
290  tr("Click on 'Next' if you want to import a new dataset\n or choose 'Open an imaging session':") );
293  lineDescription->setVisible(false);
294  textDescription->setVisible(false);
295  this->setFinalPage(false);
296 }
297 
298 //-------------------------------------------------------------------------
299 
300 //-------------------------------------------------------------------------
302 {
303  setSubTitle(
304  tr(
305  "Select the imaging session you want to open and click on 'Finish' to load the corresponding images or choose 'Create a new imaging session':") );
310  this->setFinalPage(false);
311 }
312 
313 //-------------------------------------------------------------------------
314 
315 //-------------------------------------------------------------------------
std::string toStdString() const
void clear()
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
void registerField(const QString &name, QWidget *widget, const char *property, const char *changedSignal)
void setSubTitle(const QString &subTitle)
bool CloseDatabaseConnection(vtkMySQLDatabase *DatabaseConnector)
return true if the connection has been closed, false if the connection was already closed ...
void clear()
virtual void setVisible(bool visible)
vtkMySQLDatabase * OpenDatabaseConnection(std::string ServerName, std::string login, std::string Password, std::string DBName)
void DisplayInfoImgSession(QString ImgSessionName)
display in the description text the existing description stored in the database for a given Imaging S...
QString tr(const char *sourceText, const char *disambiguation, int n)
void setField(const QString &name, const QVariant &value)
boost::unordered_map< std::string, std::string > MapTwoColumnsFromTable(vtkMySQLDatabase *DatabaseConnector, const std::vector< std::string > &iColumnNames, const std::string &iTableName, std::string iField, std::string iValue)
query: "SELECT ColumnName1, ColumnName2 FROM TableName"
void setBold(bool enable)
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
void append(const T &value)
void setLayout(QLayout *layout)
bool GetListImgSession()
fill the m_MapImgSessionIDName with the names of the existing imaging session stored in the database ...
bool isEmpty() const
std::vector< std::string > ListSpecificValuesForOneColumn(vtkMySQLDatabase *iDatabaseConnector, const std::string &TableName, const std::string &ColumnName, const std::string &field, const std::string &value, bool ExcludeZero)
SELECT ColumnName FROM TableName WHERE field = value and ColumnName <> 0 (if excludezero) ...
QVariant field(const QString &name) const
void setFont(const QFont &)
void setChecked(bool)
bool setAlignment(QWidget *w, QFlags< Qt::AlignmentFlag > alignment)
void setFinalPage(bool finalPage)
boost::unordered_map< std::string, std::string > m_MapImgSessionIDName
void addItems(const QStringList &texts)
void setReadOnly(bool ro)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setText(const QString &text)
QString toString() const
void addLayout(QLayout *layout, int stretch)