GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoDBNameDescEntityManager.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 "ConvertToStringHelper.h"
37 #include "QueryDataBaseHelper.h"
39 
42  QWidget *iParent,
43  std::string iEntityName,
44  int iImgSessionID) : QWidget(iParent),
45  m_NameDescDialog(NULL),
46  m_DatabaseConnector(NULL)
47 {
48  this->m_EntityName = iEntityName;
49  this->m_ImgSessionID = iImgSessionID;
50  this->m_NameNewEntity = "";
51 }
52 
53 //-------------------------------------------------------------------------
54 
55 //-------------------------------------------------------------------------
57 {
58 }
59 
60 //-------------------------------------------------------------------------
61 
62 //-------------------------------------------------------------------------
64  vtkMySQLDatabase *iDatabaseConnector)
65 {
67  this, this->m_EntityName.c_str() );
68 
69  this->m_DatabaseConnector = iDatabaseConnector;
70  QObject::connect ( this->m_NameDescDialog, SIGNAL( NewNameDescription(std::string,
71  std::string) ),
72  this, SLOT( ValidateName(std::string, std::string) ) );
73  bool ok = this->m_NameDescDialog->exec();
74  if ( !ok )
75  {
76  this->m_NameNewEntity.clear();
77  }
78  return this->m_NameNewEntity;
79 }
80 
81 //-------------------------------------------------------------------------
82 
83 //-------------------------------------------------------------------------
85 QGoDBNameDescEntityManager::GetListExistingEntities(vtkMySQLDatabase *iDatabaseConnector)
86 {
87  if ( this->m_ImgSessionID != 0 )
88  {
89  return ListSpecificValuesForTwoColumns(iDatabaseConnector,
90  this->m_EntityName, "Name", "Description", "ImagingSessionID",
91  ConvertToString< int >(this->m_ImgSessionID), "Name");
92  }
93  else
94  {
95  return VectorTwoColumnsFromTable(iDatabaseConnector, "Name",
96  "Description", this->m_EntityName, "Name");
97  }
98 }
99 
100 //-------------------------------------------------------------------------
101 
102 //-------------------------------------------------------------------------
104  vtkMySQLDatabase *iDatabaseConnector)
105 {
107  this->GetNameExistingEntities(iDatabaseConnector),
108  this, this->m_EntityName);
109 
110  this->m_DatabaseConnector = iDatabaseConnector;
111  QObject::connect(Dialog,
112  SIGNAL( ListEntitiesToDelete(std::vector< std::string > ) ),
113  this,
114  SLOT( DeleteEntitiesFromList(std::vector< std::string > ) )
115  );
116  Dialog->show();
117  return Dialog->exec();
118 }
119 
120 //-------------------------------------------------------------------------
121 
122 //-------------------------------------------------------------------------
124  std::vector< std::string > iVectorNamesEntitiesToDelete)
125 {
126  if ( this->m_DatabaseConnector != 0 )
127  {
129  "Name", iVectorNamesEntitiesToDelete);
130  }
131 }
132 
133 //-------------------------------------------------------------------------
134 
135 //-------------------------------------------------------------------------
137 {
138  return this->m_NameNewEntity;
139 }
140 
141 //-------------------------------------------------------------------------
142 
143 //-------------------------------------------------------------------------
144 std::vector< std::string > QGoDBNameDescEntityManager::GetNameExistingEntities(vtkMySQLDatabase *iDatabaseConnector)
145 {
146  std::vector< std::string > ResultsQuery;
147  if ( iDatabaseConnector )
148  {
149  // if m_ImgSessionID = 0, the entity name is not related to an
150  // imagingsession
151  if ( this->m_ImgSessionID != 0 )
152  {
153  ResultsQuery = ListSpecificValuesForOneColumn(
154  iDatabaseConnector, this->m_EntityName, "Name", "ImagingSessionID",
155  ConvertToString< int >(this->m_ImgSessionID), "Name");
156  }
157  else
158  {
159  ResultsQuery = ListAllValuesForOneColumn(iDatabaseConnector,
160  "Name", this->m_EntityName);
161  }
162  }
163  return ResultsQuery;
164 }
165 
166 //-------------------------------------------------------------------------
167 
168 //-------------------------------------------------------------------------
170  vtkMySQLDatabase *iDatabaseConnector)
171 {
172  std::string EntityNameID = this->m_EntityName;
173 
174  EntityNameID += "ID";
175  return FindOneID(iDatabaseConnector,
176  this->m_EntityName, EntityNameID, "Name", iName);
177 }
NamesDescrContainerType GetListExistingEntities(vtkMySQLDatabase *iDatabaseConnector)
return the list of all the existing entities stored in the database
void DeleteEntitiesFromList(std::vector< std::string > iVectorNamesEntitiesToDelete)
Delete in the database the entities with the names contained in the vector.
virtual void ValidateName(std::string iName, std::string iDescription)=0
Pure Virtual method : check that the name doesn't already exists in the database, if so...
QGoDBNameDescEntityManager(QWidget *iParent=0, std::string iEntityName="", int iImgSessionID=0)
int exec()
int GetTheEntityID(std::string iName, vtkMySQLDatabase *iDatabaseConnector)
get the ID of the entity based on the name
QGoNameDescriptionInputDialog * m_NameDescDialog
std::vector< std::pair< std::string, std::string > > VectorTwoColumnsFromTable(vtkMySQLDatabase *DatabaseConnector, const std::string &ColumnNameOne, const std::string &ColumnNameTwo, const std::string &TableName, const std::string &OrderByColumnName)
SELECT ColumnNameOne,ColumnNameTwo FROM TableName ORDER BY ColumnName ASC.
virtual bool DeleteEntity(vtkMySQLDatabase *iDatabaseConnector)
show the list of the existing entities so the user can choose the ones he wants to delete...
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 DeleteRows(vtkMySQLDatabase *DatabaseConnector, std::string TableName, std::string field, std::vector< std::string > VectorValues)
std::vector< std::pair< std::string, std::string > > ListSpecificValuesForTwoColumns(vtkMySQLDatabase *DatabaseConnector, const std::string &TableName, const std::string &ColumnNameOne, const std::string &ColumnNameTwo, const std::string &field, const std::string &value, const std::string &ColumnNameOrder)
SELECT ColumnNameOne,ColumnName2 FROM TableName WHERE field = value ORDER BY ColumnNameOrder ASC"...
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) ...
int FindOneID(vtkMySQLDatabase *DatabaseConnector, const std::string &TableName, const std::string &ColumnName, const std::string &field, const std::string &value)
SELECT ColumnName FROM TableName WHERE field = value.
std::string GetNameNewEntity()
return the name of the new entity added
std::vector< std::pair< std::string, std::string > > NamesDescrContainerType
this class displays a list of entities and return the list of the ones selected by the user...
std::vector< std::string > GetNameExistingEntities(vtkMySQLDatabase *iDatabaseConnector)
return the names of all the entities stored in the database
void show()
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
std::string AddAnEntity(vtkMySQLDatabase *iDatabaseConnector)
execute the dialog asking the user to enter a name and a description, validates the name...