GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoDBInitCreateMicroscopePage.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 "CreateDataBaseHelper.h"
37 #include "vtkSQLQuery.h"
38 #include "QueryDataBaseHelper.h"
40 #include <QFormLayout>
41 #include <QMessageBox>
42 #include <QVariant>
43 #include <QInputDialog>
44 #include <QDir>
45 #include <QPushButton>
46 
48  QWizardPage(iParent)
49 {
50  QFont tfont;
51 
52  tfont.setBold(false);
53  this->setFont(tfont);
55  setSubTitle( tr("Create the microscopes for the gofigure projects:") );
56 
57  QFormLayout *formLayout = new QFormLayout;
58 
60  CreateButton = new QPushButton( tr("Create Microscope") );
61 
62  formLayout->addRow(tr("Enter the Microscope Name:"), lineMicroscopeName);
63  formLayout->addWidget(CreateButton);
64 
65  QObject::connect( this->CreateButton, SIGNAL( clicked() ),
66  this, SLOT( CreateMicroscope() ) );
67 
68  setLayout(formLayout);
69  //registerField( "MicroscopeName", lineMicroscopeName );
70 }
71 
72 //-------------------------------------------------------------------------
73 
74 //-------------------------------------------------------------------------
76 {
77  this->OpenDBConnection();
78  QMessageBox msgBox;
80  "Name", "microscope").empty() )
81  {
82  msgBox.setText(
83  tr("Please create at least one microscope.") );
84  msgBox.exec();
86  {
88  }
89  return false;
90  }
92  {
94  }
95  msgBox.setText( QObject::tr(
96  "The MySql user and the GoFigure Database \n\
97  have been successfully created !!\n\
98  Now you can save the work you do with GoFigure into the Database !!") );
99  msgBox.exec();
100  return true;
101 }
102 
103 //-------------------------------------------------------------------------
104 
105 //-------------------------------------------------------------------------
107 {
108  this->OpenDBConnection();
109  QMessageBox msgBox;
110  //std::string MicroscopeName =
111  // field("MicroscopeName").toString().toStdString();
112  std::string MicroscopeName = this->lineMicroscopeName->text().toStdString();
113  if ( MicroscopeName.empty() )
114  {
115  msgBox.setText(
116  tr("Please enter a name for your microscope.") );
117  msgBox.exec();
118  return;
119  }
120 
121  if ( ListSpecificValuesForOneColumn(this->m_DatabaseConnector, "microscope",
122  "Name", "Name", MicroscopeName).size() > 0 )
123  {
124  msgBox.setText(
125  tr("There is already a Microscope with the same name, please choose another one") );
126  msgBox.exec();
127  return;
128  }
129 
130  vtkSQLQuery * query = this->m_DatabaseConnector->GetQueryInstance();
131  std::stringstream queryScript;
132  queryScript << "INSERT INTO microscope VALUES ('";
133  queryScript << MicroscopeName;
134  queryScript << "') ;";
135 
136  query->SetQuery( queryScript.str().c_str() );
137  if ( !query->Execute() )
138  {
139  std::cout << "Insert Microscope query failed." << std::endl;
140  query->Delete();
141  return;
142  }
143  query->Delete();
144  msgBox.setText(
145  tr("Your microscope has been successfully created") );
146  msgBox.exec();
147  emit NewMicroscopeCreated();
148 
150  {
152  }
153 }
154 
155 //------------------------------------------------------------------------------
156 
157 //------------------------------------------------------------------------------
159 {
160  if ( this->m_User.empty() || this->m_Password.empty() )
161  {
162  this->SetDatabaseVariables( field("User").toString().toStdString(),
163  field("Password").toString().toStdString() );
164  }
165  if ( this->m_DatabaseConnector == 0 )
166  {
168  this->m_Server, this->m_User, this->m_Password, this->m_DBName);
169  }
170 }
171 
172 //-------------------------------------------------------------------------
173 
174 //-------------------------------------------------------------------------
176  std::string iUser, std::string iPassword)
177 {
178  this->m_User = iUser;
179  this->m_Password = iPassword;
180  this->m_Server = "localhost";
181  this->m_DBName = "gofiguredatabase";
182 }
void setSubTitle(const QString &subTitle)
bool CloseDatabaseConnection(vtkMySQLDatabase *DatabaseConnector)
return true if the connection has been closed, false if the connection was already closed ...
vtkMySQLDatabase * OpenDatabaseConnection(std::string ServerName, std::string login, std::string Password, std::string DBName)
QString tr(const char *sourceText, const char *disambiguation, int n)
void setBold(bool enable)
QSize size() const
void setLayout(QLayout *layout)
std::vector< std::string > ListAllValuesForOneColumn(vtkMySQLDatabase *DatabaseConnector, const std::string &ColumnName, const std::string &TableName, std::string OrderByColumnName)
SELECT ColumnName from TableName ORDER BY OrderbyColumnName.
void setText(const QString &text)
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 &lt;&gt; 0 (if excludezero) ...
void addWidget(QWidget *w)
void addRow(QWidget *label, QWidget *field)
QVariant field(const QString &name) const
void setFont(const QFont &)
void SetDatabaseVariables(std::string iUser, std::string iPassword)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)