GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoDBColorManager.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 #include "QGoDBColorManager.h"
35 #include <QColorDialog>
36 #include <QInputDialog>
38 
40  QGoDBNameDescEntityManager(iParent, "color", 0)
41 {
42 }
43 
44 //------------------------------------------------------------------------------
45 
46 //------------------------------------------------------------------------------
48 {
49  //this->m_DatabaseConnector->Close();
50  //this->m_DatabaseConnector->Delete();
51 }
52 
53 //------------------------------------------------------------------------------
54 
55 //------------------------------------------------------------------------------
57  vtkMySQLDatabase *iDatabaseConnector)
58 {
59  this->m_NewColorData.first.clear();
60  QColor col = QColorDialog::getColor(Qt::white, NULL, "Pick a new color",
61  QColorDialog::ShowAlphaChannel);
62  if ( col.isValid() )
63  {
64  this->m_NewColorData.second = col;
65  this->m_NewColorData.first = QGoDBNameDescEntityManager::AddAnEntity(iDatabaseConnector);
66  }
67  return this->m_NewColorData;
68 }
69 
70 //-------------------------------------------------------------------------
71 
72 //-------------------------------------------------------------------------
74 {
75  if ( !this->CheckEntityAlreadyExists< GoDBColorRow >(this->m_NewColor) )
76  {
77  QColor col = this->m_NewColorData.second;
78  this->m_NewColor.SetField< int >( "Red", col.red() );
79  this->m_NewColor.SetField< int >( "Green", col.green() );
80  this->m_NewColor.SetField< int >( "Blue", col.blue() );
81  this->m_NewColor.SetField< int >( "Alpha", col.alpha() );
83  }
84 }
85 
86 //------------------------------------------------------------------------------
87 
88 //------------------------------------------------------------------------------
89 void QGoDBColorManager::ValidateName(std::string iName, std::string iDescription)
90 {
91  this->ValidateNameTemplate< GoDBColorRow >(this->m_NewColor, iName,
92  iDescription);
93 }
94 
95 //------------------------------------------------------------------------------
96 
97 //------------------------------------------------------------------------------
98 bool QGoDBColorManager::DeleteEntity(vtkMySQLDatabase *iDatabaseConnector)
99 {
101  this->GetListExistingColors(iDatabaseConnector),
102  this, this->m_EntityName);
103 
104  this->m_DatabaseConnector = iDatabaseConnector;
105  QObject::connect(Dialog,
106  SIGNAL( ListEntitiesToDelete(std::vector< std::string > ) ),
107  this,
108  SLOT( DeleteEntitiesFromList(std::vector< std::string > ) )
109  );
110 
111  Dialog->show();
112  return Dialog->exec();
113 }
114 
115 //------------------------------------------------------------------------------
116 
117 //------------------------------------------------------------------------------
118 std::list< QGoDBColorManager::ItemColorComboboxData >
119 QGoDBColorManager::GetListExistingColors(vtkMySQLDatabase *iDatabaseConnector)
120 {
121  std::list< ItemColorComboboxData > oInfoColors;
122  std::vector< std::string > ResultsQuery = ListAllValuesForOneColumn(
123  iDatabaseConnector, "*", "color", "name");
124  unsigned int i = 0;
125  while ( i < ResultsQuery.size() )
126  {
128  temp.first = ResultsQuery[i + 1];
129  QColor tempColor( atoi( ResultsQuery[i + 2].c_str() ), atoi( ResultsQuery[i + 3].c_str() ),
130  atoi( ResultsQuery[i + 4].c_str() ), atoi( ResultsQuery[i + 5].c_str() ) );
131  temp.second = tempColor;
132  oInfoColors.push_back(temp);
133  i = i + 7;
134  }
135  return oInfoColors;
136 }
void DeleteEntitiesFromList(std::vector< std::string > iVectorNamesEntitiesToDelete)
Delete in the database the entities with the names contained in the vector.
virtual bool DeleteEntity(vtkMySQLDatabase *iDatabaseConnector)
show the list of the existing entities so the user can choose the ones he wants to delete...
QGoDBColorManager(QWidget *iParent=0)
int exec()
virtual int SaveInDB(vtkMySQLDatabase *iDatabaseConnector)
Pure Virtual :check if the entity already exists in the DB, if yes, return the existing ID...
Abstract class : the QGoDBNameDescEntityManager manages the interactions between the user and the dat...
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.
int red() const
ItemColorComboboxData AddANewColor(vtkMySQLDatabase *iDatabaseConnector)
ask the user the color he wants, the name, description of the new color and saves it in the database...
int alpha() const
int green() const
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QFlags< QColorDialog::ColorDialogOption > options)
int blue() const
GoDBColorRow m_NewColor
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
this class displays a list of entities and return the list of the ones selected by the user...
ItemColorComboboxData m_NewColorData
void show()
QGoDeleteFromListDialog::ItemColorComboboxData ItemColorComboboxData
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
std::list< ItemColorComboboxData > GetListExistingColors(vtkMySQLDatabase *iDatabaseConnector)
get the list of the existing colors from the database
virtual void SaveNewEntityInDB()
Pure Virtual method : save the new entity in the database, the m_DatabaseConnectorForNewEntity needs ...
virtual void ValidateName(std::string iName, std::string iDescription)
std::string AddAnEntity(vtkMySQLDatabase *iDatabaseConnector)
execute the dialog asking the user to enter a name and a description, validates the name...
bool isValid() const