GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoDBNameDescEntityManager.h
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 =========================================================================*/
34 
35 #ifndef __QGoDBNameDescEntityManager_h
36 #define __QGoDBNameDescEntityManager_h
37 
38 #include <QWidget>
39 #include <QMessageBox>
40 #include "vtkMySQLDatabase.h"
42 
52  public QWidget
53 {
54  Q_OBJECT
55 public:
61  explicit QGoDBNameDescEntityManager (QWidget *iParent = 0,
62  std::string iEntityName = "", int iImgSessionID = 0);
63 
65 
66  typedef std::vector< std::pair< std::string, std::string > >
68 
76  std::string AddAnEntity(vtkMySQLDatabase *iDatabaseConnector);
77 
85  vtkMySQLDatabase *iDatabaseConnector);
86 
95  virtual bool DeleteEntity(vtkMySQLDatabase *iDatabaseConnector);
96 
101  std::string GetNameNewEntity();
102 
109  int GetTheEntityID(std::string iName, vtkMySQLDatabase *iDatabaseConnector);
110 
111 protected slots:
112 
121  virtual void ValidateName(
122  std::string iName, std::string iDescription) = 0;
123 
131  std::vector< std::string > iVectorNamesEntitiesToDelete);
132 
133 protected:
135  std::string m_EntityName;
137  vtkMySQLDatabase * m_DatabaseConnector;
138  std::string m_NameNewEntity;
139 
147  virtual void SaveNewEntityInDB() = 0;
148 
154  std::vector< std::string > GetNameExistingEntities(vtkMySQLDatabase *iDatabaseConnector);
155 
164  template< typename T >
165  bool CheckEntityAlreadyExists(T iNewEntity)
166  {
167  std::string Name = iNewEntity.GetMapValue("Name");
168 
169  if ( iNewEntity.DoesThisEntityAlreadyExistsAndReturnName(
170  this->m_DatabaseConnector, Name) != -1 )
171  {
172  QMessageBox msgBox;
173  msgBox.setText(
174  tr("This %1 already exists, its name is: ' %2 ' ")
175  .arg( this->m_EntityName.c_str() )
176  .arg( Name.c_str() ) );
177  msgBox.exec();
178  return true;
179  }
180  else
181  {
182  this->m_NameNewEntity = Name;
183  return false;
184  }
185  }
186 
195  template< typename T >
196  void ValidateNameTemplate(T & ioNewEntity, std::string iName, std::string iDescription)
197  {
198  ioNewEntity.SetField("Name", iName);
199  ioNewEntity.SetField("Description", iDescription);
200  if ( ioNewEntity.DoesThisNameAlreadyExists(
201  this->m_DatabaseConnector) != -1 )
202  {
204  }
205  else
206  {
207  this->m_NameDescDialog->accept();
208  this->SaveNewEntityInDB();
209  }
210  }
211 };
212 #endif
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.
void NameAlreadyExists()
open a messagebox to tell the user that the name he choose already exists
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)
void ValidateNameTemplate(T &ioNewEntity, std::string iName, std::string iDescription)
check if the name already exists for this entity in the database, if yes, let the user know...
int GetTheEntityID(std::string iName, vtkMySQLDatabase *iDatabaseConnector)
get the ID of the entity based on the name
QGoNameDescriptionInputDialog * m_NameDescDialog
QString tr(const char *sourceText, const char *disambiguation, int n)
bool CheckEntityAlreadyExists(T iNewEntity)
check if the entity already exists in the database, if yes, give the name of the existing entity to t...
Abstract class : the QGoDBNameDescEntityManager manages the interactions between the user and the dat...
virtual bool DeleteEntity(vtkMySQLDatabase *iDatabaseConnector)
show the list of the existing entities so the user can choose the ones he wants to delete...
void setText(const QString &text)
virtual void accept()
std::string GetNameNewEntity()
return the name of the new entity added
virtual void SaveNewEntityInDB()=0
Pure Virtual method : save the new entity in the database, the m_DatabaseConnectorForNewEntity needs ...
std::vector< std::pair< std::string, std::string > > NamesDescrContainerType
std::vector< std::string > GetNameExistingEntities(vtkMySQLDatabase *iDatabaseConnector)
return the names of all the entities stored in the database
std::string AddAnEntity(vtkMySQLDatabase *iDatabaseConnector)
execute the dialog asking the user to enter a name and a description, validates the name...