Skip to content

Commit

Permalink
add method to save a new color in the database
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://orchestra.med.harvard.edu/svn/megason/Code/GoFigure2@1829 ef826fda-c0ae-4237-af8e-f8dcbcf7929c
  • Loading branch information
lsouhait committed Dec 3, 2009
1 parent c6d0d13 commit d85b77c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 8 deletions.
24 changes: 24 additions & 0 deletions branches/GoFigure2Beta/Code/GUI/lib/QGoPrintDatabase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "GoDBTrackRow.h"
#include "GoDBLineageRow.h"
#include "GoDBCoordinateRow.h"
#include "GoDBColorRow.h"
#include "QueryDataBaseHelper.h"
#include "ConvertToStringHelper.h"
#include "GoDBTraceInfoForTableWidget.h"
Expand Down Expand Up @@ -676,4 +677,27 @@ std::list<std::pair<std::string,std::vector<int> > > QGoPrintDatabase::
CloseDBConnection();

return oInfoColors;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void QGoPrintDatabase::SaveNewColorInDB(std::vector<std::string> iDataNewColor)
{
this->OpenDBConnection();
GoDBColorRow NewColor;
if (iDataNewColor.size() != 5)
{
std::cout<<"Pb: the number of data for the new color is not 5";
std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
std::cout << std::endl;
}
else
{
NewColor.SetField("Name",iDataNewColor[0]);
NewColor.SetField("Red",iDataNewColor[1]);
NewColor.SetField("Green",iDataNewColor[2]);
NewColor.SetField("Blue",iDataNewColor[3]);
NewColor.SetField("Alpha",iDataNewColor[4]);
AddOnlyOneNewObjectInTable<GoDBColorRow>(m_DatabaseConnector,"color",NewColor);
}
}
2 changes: 2 additions & 0 deletions branches/GoFigure2Beta/Code/GUI/lib/QGoPrintDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class QGoPrintDatabase : public QWidget,
/** \brief return a list containing the exisiting colornames with their corresponding rgba
from the database*/
std::list<std::pair<std::string,std::vector<int> > > GetColorComboBoxInfofromDB();

void SaveNewColorInDB(std::vector<std::string> iDataNewColor);

QTableWidgetChild* ContourTable;
QTableWidgetChild* MeshTable;
Expand Down
21 changes: 16 additions & 5 deletions branches/GoFigure2Beta/Code/GUI/lib/QGoTabImageView3DwT.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ void QGoTabImageView3DwT::CreateManualSegmentationdockWidget()

this->m_SegmentationActions.push_back(
m_ManualSegmentationDockWidget->toggleViewAction() );

QObject::connect( this->m_DataBaseTables,
SIGNAL( FillDatabaseFinished() ),
this, SLOT( PassInfoForColorComboBox() ) );
}
//-------------------------------------------------------------------------

Expand Down Expand Up @@ -175,6 +171,14 @@ void QGoTabImageView3DwT::CreateVisuDockWidget()

QObject::connect( m_VisuDockWidget, SIGNAL( ShowOneChannelChanged( int ) ),
this, SLOT( ShowOneChannel( int ) ) );

QObject::connect( this->m_DataBaseTables,
SIGNAL( FillDatabaseFinished() ),
this, SLOT( PassInfoForColorComboBoxFromDB() ) );

QObject::connect( this->m_VisuDockWidget->ColorComboBox,
SIGNAL( NewColorToBeSaved()),
this, SLOT( PassInfoForDBFromColorComboBox()() ) );
}
//-------------------------------------------------------------------------

Expand Down Expand Up @@ -1277,8 +1281,15 @@ AddPolyData( vtkPolyData* iMesh )
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
void QGoTabImageView3DwT::PassInfoForColorComboBox()
void QGoTabImageView3DwT::PassInfoForColorComboBoxFromDB()
{
this->m_VisuDockWidget->ColorComboBox->SetDataForColors(
this->m_DataBaseTables->GetColorComboBoxInfofromDB());
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
void QGoTabImageView3DwT::PassInfoForDBFromColorComboBox()
{
this->m_DataBaseTables->SaveNewColorInDB(
this->m_VisuDockWidget->ColorComboBox->GetDataForNewColorToBeSaved());
}
3 changes: 2 additions & 1 deletion branches/GoFigure2Beta/Code/GUI/lib/QGoTabImageView3DwT.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public slots:
void ActivateManualSegmentationEditor( const bool& iActivate );
void ValidateContour();
void ChangeContourRepresentationProperty();
void PassInfoForColorComboBox();
void PassInfoForColorComboBoxFromDB();
void PassInfoForDBFromColorComboBox();

protected:
QHBoxLayout* m_LayOut;
Expand Down
23 changes: 23 additions & 0 deletions branches/GoFigure2Beta/Code/GUI/lib/qtcolorcombobox.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <QtGui/QFontMetrics>
#include <QInputDialog>
#include "qtcolorcombobox.h"
#include "ConvertToStringHelper.h"

/*! \class QtColorComboBox
Expand Down Expand Up @@ -238,6 +239,7 @@ void QtColorComboBox::emitActivatedColor(int index)
{
addColor(col, ColorName);
setCurrentIndex(index);
this->StoreDataForNewColorToBeSaved(col,ColorName.toStdString());
}
} else {
// The user pressed cancel - reset the current color to
Expand Down Expand Up @@ -353,4 +355,25 @@ void QtColorComboBox::setExistingColors()
this->show();
}
this->setColorDialogEnabled(true);
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void QtColorComboBox::StoreDataForNewColorToBeSaved(
QColor Color, std::string NameColor)
{
m_NewColorData.push_back(NameColor);
m_NewColorData.push_back(ConvertToString<int>(Color.red()));
m_NewColorData.push_back(ConvertToString<int>(Color.green()));
m_NewColorData.push_back(ConvertToString<int>(Color.blue()));
m_NewColorData.push_back(ConvertToString<int>(Color.alpha()));

NewColorToBeSaved();
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
std::vector<std::string> QtColorComboBox::GetDataForNewColorToBeSaved()
{
return m_NewColorData;
}
6 changes: 6 additions & 0 deletions branches/GoFigure2Beta/Code/GUI/lib/qtcolorcombobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ class QT_QTCOLORCOMBOBOX_EXPORT QtColorComboBox : public QComboBox
void SetDataForColors(
std::list<std::pair<std::string,std::vector<int> > > iDataColors);

std::vector<std::string> GetDataForNewColorToBeSaved();

Q_SIGNALS:
void activated(const QColor &color);
void highlighted(const QColor &color);
void NewColorToBeSaved();

private Q_SLOTS:
void emitActivatedColor(int index);
Expand All @@ -105,6 +108,9 @@ private Q_SLOTS:
bool colorDialogEnabled;
void SetColorNamesAndRgb ();
void setExistingColors();
void StoreDataForNewColorToBeSaved(
QColor Color,std::string NameColor);
std::vector<std::string> m_NewColorData;
};

#endif
Expand Down
18 changes: 16 additions & 2 deletions branches/GoFigure2Beta/Code/IO/SelectQueryDatabaseHelper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,24 @@ std::vector<std::string> ListAllValuesForOneColumn(vtkMySQLDatabase* DatabaseCon
query->Delete();
return result;
}
while( query->NextRow() )
if (ColumnName != "*")
{
while( query->NextRow() )
{
result.push_back( query->DataValue( 0 ).ToString() );
}
}
else
{
result.push_back( query->DataValue( 0 ).ToString() );
while(query->NextRow())
{
for( int i = 0; i < query->GetNumberOfFields(); i++)
{
result.push_back( query->DataValue( i ).ToString() );
}
}
}

query->Delete();

return result;
Expand Down

0 comments on commit d85b77c

Please sign in to comment.