GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoDBBookmarkManager.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 =========================================================================*/
34 
35 #include "QGoDBBookmarkManager.h"
36 #include <QDateTime>
38 
40  int iImgSessionID) :
41  QGoDBNameDescEntityManager(iParent, "bookmark", iImgSessionID)
42 {
43 }
44 
45 //-------------------------------------------------------------------------
46 
47 //-------------------------------------------------------------------------
49 {
50 }
51 
52 //-------------------------------------------------------------------------
53 
54 //-------------------------------------------------------------------------
56  vtkMySQLDatabase *iDatabaseConnector)
57 {
58  this->m_CoordIDForNewBookmark = iCoordID;
59  this->AddAnEntity(iDatabaseConnector);
60 }
61 
62 //-------------------------------------------------------------------------
63 
64 //-------------------------------------------------------------------------
66 {
67  QDateTime CreationDate = QDateTime::currentDateTime();
68  std::string CreationDateStr =
69  CreationDate.toString(Qt::ISODate).toStdString();
70 
71  this->m_NewBookmark.SetField("CreationDate", CreationDateStr);
72  this->m_NewBookmark.SetField< int >("CoordID", this->m_CoordIDForNewBookmark);
73  this->m_NewBookmark.SetField< int >("ImagingSessionID", this->m_ImgSessionID);
74 
75  if ( !this->CheckEntityAlreadyExists< GoDBBookmarkRow >(this->m_NewBookmark) )
76  {
78  emit ListBookmarksChanged();
79  }
80 }
81 
82 //-------------------------------------------------------------------------
83 
84 //-------------------------------------------------------------------------
86  vtkMySQLDatabase *iDatabaseConnector, std::string iName)
87 {
88  GoDBCoordinateRow BookmarkCoord;
89 
90  BookmarkCoord.SetValuesForSpecificID(
91  this->GetCoordIDForBookmark(iDatabaseConnector, iName), iDatabaseConnector);
92  return BookmarkCoord;
93 }
94 
95 //-------------------------------------------------------------------------
96 
97 //-------------------------------------------------------------------------
99  vtkMySQLDatabase *iDatabaseConnector, std::string iName)
100 {
101  return FindOneID(iDatabaseConnector, "bookmark",
102  "CoordID", "Name", iName);
103 }
104 
105 //-------------------------------------------------------------------------
106 
107 //-------------------------------------------------------------------------
108 void QGoDBBookmarkManager::ValidateName(std::string iName,
109  std::string iDescription)
110 {
111  this->ValidateNameTemplate< GoDBBookmarkRow >(this->m_NewBookmark,
112  iName, iDescription);
113 }
114 
115 //-------------------------------------------------------------------------
116 
117 //-------------------------------------------------------------------------
119  vtkMySQLDatabase *iDatabaseConnector)
120 {
121  bool ok = this->DeleteEntity(iDatabaseConnector);
122 
123  if ( ok )
124  {
125  emit ListBookmarksChanged(); //to update the menu for bookmarks;
126  }
127 }
std::string toStdString() const
QString toString(Qt::DateFormat format) const
QGoDBBookmarkManager(QWidget *iParent=0, int iImgSessionID=0)
void DeleteBookmark(vtkMySQLDatabase *iDatabaseConnector)
delete the bookmarks from the database from a list the user selects and send a signal to tell that th...
manages a map with keys matching fields of the gofiguredatabase Coordinate table and values of the ma...
virtual bool SetValuesForSpecificID(int ID, vtkMySQLDatabase *iDatabaseConnector)
get the data from the database corresponding to the specific ID and put them in the map ...
Definition: GoDBRow.cxx:209
void AddABookmark(int iCoordID, vtkMySQLDatabase *iDatabaseConnector)
execute the dialog asking the user to enter a name and a description, validates the name...
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...
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.
GoDBBookmarkRow m_NewBookmark
QDateTime currentDateTime()
void SetField(const std::string &key, const T &value)
convert the value into a string and assign it to the key in the map
Definition: GoDBRow.h:73
void ValidateName(std::string iName, std::string iDescription)
virtual int SaveInDB(vtkMySQLDatabase *DatabaseConnector)
Pure Virtual :check if the entity already exists in the DB, if yes, return the existing ID...
std::string AddAnEntity(vtkMySQLDatabase *iDatabaseConnector)
execute the dialog asking the user to enter a name and a description, validates the name...
GoDBCoordinateRow GetCoordinatesForBookmark(vtkMySQLDatabase *iDatabaseConnector, std::string iName)
return the coordinate for the bookmark with the name iName
int GetCoordIDForBookmark(vtkMySQLDatabase *iDatabaseConnector, std::string iName)
get the coordid for the bookmark with the name iName