Skip to content

Commit

Permalink
add method to insert a new row when creating a contour
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://orchestra.med.harvard.edu/svn/megason/Code/GoFigure2@1853 ef826fda-c0ae-4237-af8e-f8dcbcf7929c
  • Loading branch information
lsouhait committed Dec 7, 2009
1 parent ec7fb41 commit 48ab314
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 34 deletions.
110 changes: 83 additions & 27 deletions branches/GoFigure2Beta/Code/GUI/lib/QGoPrintDatabase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ void QGoPrintDatabase::closeEvent(QCloseEvent* iEvent)
void QGoPrintDatabase::UpdateTableFromDB()
{
//todo: make it ok for all tables
UpdateContentAndDisplayFromDB< GoDBContourRow >("contour",
ContourTable,m_DatabaseConnector);
//UpdateContentAndDisplayFromDB< GoDBContourRow >("contour",
// ContourTable,m_DatabaseConnector);
}
//--------------------------------------------------------------------------

Expand Down Expand Up @@ -272,32 +272,32 @@ void QGoPrintDatabase::DeleteTraces()
//add the tableWidgetChild in the CollectionOfTraces?
QStringList ContoursToDelete = this->ContourTable->ValuesForSelectedRows("ContourID");
m_CollectionOfContours->DeleteTraces(ContoursToDelete,m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBContourRow>("contour",
ContourTable,m_DatabaseConnector);
//this->UpdateContentAndDisplayFromDB<GoDBContourRow>("contour",
// ContourTable,m_DatabaseConnector);
break;
}
case 1: //mesh
{
QStringList MeshesToDelete = this->MeshTable->ValuesForSelectedRows("MeshID");
m_CollectionOfMeshes->DeleteTraces(MeshesToDelete,m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBMeshRow>("mesh",
MeshTable,m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBMeshRow>("mesh",
// MeshTable,m_DatabaseConnector);
break;
}
case 2: //track
{
QStringList TracksToDelete = this->TrackTable->ValuesForSelectedRows("TrackID");
m_CollectionOfTracks->DeleteTraces(TracksToDelete,m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBTrackRow>("track",
TrackTable,m_DatabaseConnector);
//this->UpdateContentAndDisplayFromDB<GoDBTrackRow>("track",
// TrackTable,m_DatabaseConnector);
break;
}
case 3: //lineage
{
QStringList LineagesToDelete = this->LineageTable->ValuesForSelectedRows("LineageID");
m_CollectionOfLineages->DeleteTraces(LineagesToDelete,m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBLineageRow>("lineage",
LineageTable,m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBLineageRow>("lineage",
// LineageTable,m_DatabaseConnector);
break;
}
default:
Expand Down Expand Up @@ -332,10 +332,10 @@ void QGoPrintDatabase::CreateCorrespondingCollection()

m_CollectionOfContours->CreateNewCollectionFromSelection<GoDBMeshRow>(ListSelectedContours,
m_DatabaseConnector,myNewMesh);
this->UpdateContentAndDisplayFromDB<GoDBContourRow>("contour",
ContourTable,m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBMeshRow>("mesh",
MeshTable,m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBContourRow>("contour",
// ContourTable,m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBMeshRow>("mesh",
// MeshTable,m_DatabaseConnector);
break;
}
case 1: //mesh
Expand All @@ -345,8 +345,8 @@ void QGoPrintDatabase::CreateCorrespondingCollection()
//myNewTrack.SetField("ColorID", to be defined for some color chosen by the user
m_CollectionOfMeshes->CreateNewCollectionFromSelection<GoDBTrackRow>(ListSelectedMeshes,
m_DatabaseConnector,myNewTrack);
this->UpdateContentAndDisplayFromDB<GoDBMeshRow>("mesh",MeshTable,m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBTrackRow>("track",TrackTable,m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBMeshRow>("mesh",MeshTable,m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBTrackRow>("track",TrackTable,m_DatabaseConnector);
break;
}
case 2: //track
Expand All @@ -356,8 +356,8 @@ void QGoPrintDatabase::CreateCorrespondingCollection()
//myNewLineage.SetField("ColorID", to be defined for some color chosen by the user
m_CollectionOfTracks->CreateNewCollectionFromSelection<GoDBLineageRow>(ListSelectedTracks,
m_DatabaseConnector,myNewLineage);
this->UpdateContentAndDisplayFromDB<GoDBTrackRow>("track",TrackTable,m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBLineageRow>("lineage",LineageTable,m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBTrackRow>("track",TrackTable,m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBLineageRow>("lineage",LineageTable,m_DatabaseConnector);
break;
}
default:
Expand Down Expand Up @@ -457,26 +457,26 @@ void QGoPrintDatabase::AddToExistingCollection()
QStringList ListContours = this->ContourTable->ValuesForSelectedRows("ContourID");
m_CollectionOfContours->AddSelectedTracesToCollection(ListContours,
CollectionID.toInt(),m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBContourRow>("contour",
ContourTable,m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBContourRow>("contour",
// ContourTable,m_DatabaseConnector);
break;
}
case 1: //mesh
{
QStringList ListMeshes = this->MeshTable->ValuesForSelectedRows("MeshID");
m_CollectionOfMeshes->AddSelectedTracesToCollection(ListMeshes,
CollectionID.toInt(),m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBMeshRow>("mesh",
MeshTable, m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBMeshRow>("mesh",
// MeshTable, m_DatabaseConnector);
break;
}
case 2: //track
{
QStringList ListTracks = this->TrackTable->ValuesForSelectedRows("TrackID");
m_CollectionOfTracks->AddSelectedTracesToCollection(ListTracks,
CollectionID.toInt(),m_DatabaseConnector);
this->UpdateContentAndDisplayFromDB<GoDBTrackRow>("track",
TrackTable, m_DatabaseConnector);
// this->UpdateContentAndDisplayFromDB<GoDBTrackRow>("track",
// TrackTable, m_DatabaseConnector);
break;
}
default:
Expand Down Expand Up @@ -592,8 +592,10 @@ void QGoPrintDatabase::SaveContoursFromVisuInDB(unsigned int iXCoordMin,

contour_row.SaveInDB( this->m_DatabaseConnector);

UpdateContentAndDisplayFromDB< GoDBContourRow >("contour",
ContourTable,m_DatabaseConnector);
// UpdateContentAndDisplayFromDB< GoDBContourRow >("contour",
// ContourTable,m_DatabaseConnector);
this->UpdateTableWidgetWithNewCreatedTrace("contour",this->ContourTable,this->m_DatabaseConnector,
this->m_CollectionOfContours);

CloseDBConnection();
}
Expand Down Expand Up @@ -792,4 +794,58 @@ std::list<std::string> QGoPrintDatabase::GetListExistingCollectionIDFromDB(
CloseDBConnection();

return oListCollectionIDs;
}
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void QGoPrintDatabase::UpdateTableWidgetWithNewCreatedTrace( QString TableName,
QTableWidgetChild* Table,vtkMySQLDatabase* DatabaseConnector,
GoDBCollectionOfTraces* iCollectionOfTraces)
{
/*Table->setSortingEnabled(false);
typedef GoDBRecordSet< myT > SetType;
typedef typename SetType::InternalObjectType InternalObjectType;
typedef typename SetType::RowContainerType RowContainerType;
RowContainerType* RowContainer;
SetType* mySet = new SetType;
mySet->SetConnector(DatabaseConnector);
mySet->SetTableName( TableName.toStdString() );
std::stringstream WhereClause;
WhereClause << "ImagingSessionID = ";
WhereClause << m_ImgSessionID;
WhereClause << ";";
mySet->SetWhereString(WhereClause.str());
mySet->PopulateFromDB();
myT myNewObject;
mySet->AddObject( myNewObject );
RowContainer = mySet->GetRowContainer();
if( RowContainer->size() < 2 )
{
std::cout<<"Table empty";
std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
std::cout << std::endl;
}
PrintOutContentFromDB< myT >( RowContainer, Table );
delete mySet;
emit TableContentChanged();
Table->setSortingEnabled(true);*/

//Get all the necessary data from the database:

//DBTableWidgetContainerType RowContainerForNewTrace =
// iCollectionOfTraces->GetNewCreatedTraceContainer(m_DatabaseConnector);
GoDBTableWidgetContainer* LinkToNewTrace = iCollectionOfTraces->GetLinkToNewCreatedTraceContainer(
this->m_DatabaseConnector);

Table->setSortingEnabled(false);

//iCollectionOfTraces->GetLinkToNewCreatedTraceContainer(this->m_DatabaseConnector);
Table->InsertNewRow( LinkToNewTrace,iCollectionOfTraces->GetTraceName(),
iCollectionOfTraces->GetCollectionName());

Table->setSortingEnabled(true);

}
7 changes: 5 additions & 2 deletions branches/GoFigure2Beta/Code/GUI/lib/QGoPrintDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class QGoPrintDatabase : public QWidget,
database, then display them in the QTableWidgetchild.
\todo check that the values hasn't been modified first, then update
only in the database the modified ones*/
template< class myT >
/*template< class myT >
void UpdateContentAndDisplayFromDB( QString TableName, QTableWidgetChild* Table,
vtkMySQLDatabase* DatabaseConnector)
{
Expand Down Expand Up @@ -214,7 +214,7 @@ class QGoPrintDatabase : public QWidget,
delete mySet;
emit TableContentChanged();
Table->setSortingEnabled(true);
}
}*/

/** \brief Display the values stored in the RowContainer (list of type T)
in the QTableWidgetChild TableToFill: */
Expand Down Expand Up @@ -270,6 +270,9 @@ class QGoPrintDatabase : public QWidget,


void closeEvent(QCloseEvent* event);
void UpdateTableWidgetWithNewCreatedTrace( QString TableName,
QTableWidgetChild* Table,vtkMySQLDatabase* DatabaseConnector,
GoDBCollectionOfTraces* iCollectionOfTraces);

protected slots:
void CreateContextMenu(const QPoint &pos);
Expand Down
48 changes: 45 additions & 3 deletions branches/GoFigure2Beta/Code/GUI/lib/QTableWidgetChild.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -292,19 +292,20 @@ void QTableWidgetChild::DisplayContent(GoDBTableWidgetContainer* iLinkToRowConta
}//ENDFOR
}//ENDIF
}//ENDFOR
SetSelectedColumn(NbofRows);
SetSelectedColumn(NbofRows,0);
this->SetColorForAllTable(iLinkToRowContainer,TraceName);
this->SetColorForAllTable(iLinkToRowContainer,CollectionName);
}//ENDELSE
}
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
void QTableWidgetChild::SetSelectedColumn(unsigned int iNbOfRows)
void QTableWidgetChild::SetSelectedColumn(unsigned int iNbOfRows,
unsigned int StartedRow)
{
//int indexCol = findColumnName( "Selected", recordHeaderNamesOrder());
int indexCol = findColumnName( "", recordHeaderNamesOrder());
for (unsigned int i =0 ; i < iNbOfRows ; i++)
for (unsigned int i = StartedRow ; i < iNbOfRows ; i++)
{
QTableWidgetNumericalItem* Checkbox = new QTableWidgetNumericalItem;
Checkbox->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled |
Expand Down Expand Up @@ -372,4 +373,45 @@ void QTableWidgetChild::SetColorForAllTable (GoDBTableWidgetContainer* iLinkToRo
int IndexForRowContainer(QTableWidgetChild::DBTableWidgetContainerType iRowContainer)
{
return 0;
}
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
void QTableWidgetChild::InsertNewRow(GoDBTableWidgetContainer* iLinkToRowContainer,
std::string TraceName, std::string CollectionName)
{
DBTableWidgetContainerType NewTraceRowContainer = iLinkToRowContainer->GetRowContainer();
if (NewTraceRowContainer.size() == 0 || NewTraceRowContainer[1].second.size() != 1)
{
std::cout<<"The New Trace Row Container is totally empty or there is more than 1 trace in it";
std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
std::cout << std::endl;
}
else
{
int NewRow = this->rowCount()+ 1;
int NbRow = NewRow;
this->setRowCount(NbRow);
for (unsigned int i = 0; i < NewTraceRowContainer.size(); i++)
{
if (NewTraceRowContainer[i].first.ColumnNameTableWidget != "None" && !NewTraceRowContainer[i].second.empty())
{
for (int j = 0; j < this->columnCount();j++)
{
std::string HeaderCol = this->horizontalHeaderItem(j)->text().toStdString();
if (HeaderCol == NewTraceRowContainer[i].first.ColumnNameTableWidget)
{
QTableWidgetNumericalItem* CellTable = new QTableWidgetNumericalItem;
std::string Value = NewTraceRowContainer[i].second[0];
CellTable->setText(Value.c_str());
CellTable->setTextAlignment(Qt::AlignCenter);
this->setItem(NewRow-1,j,CellTable);
}//ENDIF
}//ENDFOR
}//ENDIF
}//ENDFOR
SetSelectedColumn(1,NewRow-1);
this->SetColorForAllTable(iLinkToRowContainer,TraceName);
this->SetColorForAllTable(iLinkToRowContainer,CollectionName);
}//ENDELSE
}
4 changes: 3 additions & 1 deletion branches/GoFigure2Beta/Code/GUI/lib/QTableWidgetChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class QTableWidgetChild : public QTableWidget
void DisplayContent(GoDBTableWidgetContainer* iLinkToRowContainer,
std::string TraceName, std::string CollectionName);

void InsertNewRow(GoDBTableWidgetContainer* iLinkToRowContainer,
std::string TraceName, std::string CollectionName);


protected:
Expand Down Expand Up @@ -109,7 +111,7 @@ public slots:
QStringList ValuesForSelectedRows(QString ColumnName );

/** \brief Put checkboxes in the column "Selected" */
void SetSelectedColumn(unsigned int iNbOfRows);
void SetSelectedColumn(unsigned int iNbOfRows,unsigned int StartedRow);

void SetColorForAllTable (GoDBTableWidgetContainer* iLinkToRowContainer,
std::string NameGroupColor);
Expand Down
45 changes: 45 additions & 0 deletions branches/GoFigure2Beta/Code/IO/GoDBCollectionOfTraces.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,48 @@ GoDBCollectionOfTraces::DBTableWidgetContainerType
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
GoDBTableWidgetContainer* GoDBCollectionOfTraces::GetLinkToNewCreatedTraceContainer(
vtkMySQLDatabase* iDatabaseConnector)
{
GoDBTableWidgetContainer* LinkToNewCreatedTraceContainer = new
GoDBTableWidgetContainer(this->m_CollectionName,
this->m_TracesName);

/*first, get the right parts of the first query:
all the fields except the ones where table.field are already in the query:*/
std::vector<std::string> JoinFirstTablesOnTraceTable =
m_LinkToRowContainer->GetQueryStringForTraceJoinedTables(false);
std::vector<std::string> SelectFirstFields =
m_LinkToRowContainer->GetQueryStringForSelectFieldsTables(false);

//then, get the last ID in the database, corresponding to the new created trace:
int NewTraceID = MaxValueForOneColumnInTable(iDatabaseConnector,
this->m_TracesIDName,this->m_TracesName,"ImagingSessionID",
ConvertToString<unsigned int>(this->m_ImgSessionID));

//then, get the results of the first query:
std::vector<std::vector<std::string> >ResultsFirstQuery = GetValuesFromSeveralTables(
iDatabaseConnector,this->m_TracesName,SelectFirstFields, this->m_TracesIDName,
ConvertToString<int>(NewTraceID),JoinFirstTablesOnTraceTable);

//insert into the row container, the results of the first query:
// m_LinkToRowContainer->FillRowContainer(ResultsFirstQuery,SelectFirstFields);
LinkToNewCreatedTraceContainer->FillRowContainer(ResultsFirstQuery,SelectFirstFields);

//Get the right parts of the second query (with only the remaining fields):
std::vector<std::string> JoinSecondTablesOnTraceTable =
m_LinkToRowContainer->GetQueryStringForTraceJoinedTables(true);
std::vector<std::string> SelectSecondFields =
m_LinkToRowContainer->GetQueryStringForSelectFieldsTables(true);

//then, get the results of the second query:
std::vector<std::vector<std::string> >ResultsSecondQuery = GetValuesFromSeveralTables(
iDatabaseConnector,this->m_TracesName,SelectSecondFields, this->m_TracesIDName,
ConvertToString<int>(NewTraceID),JoinSecondTablesOnTraceTable);

//insert into the row container, the results of the second query:
//m_LinkToRowContainer->FillRowContainer(ResultsSecondQuery,SelectSecondFields);
LinkToNewCreatedTraceContainer->FillRowContainer(ResultsSecondQuery,SelectSecondFields);
GoDBCollectionOfTraces::DBTableWidgetContainerType test = LinkToNewCreatedTraceContainer->GetRowContainer();//for test
return LinkToNewCreatedTraceContainer;
}
2 changes: 2 additions & 0 deletions branches/GoFigure2Beta/Code/IO/GoDBCollectionOfTraces.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class GoDBCollectionOfTraces
}

DBTableWidgetContainerType GetRowContainer(vtkMySQLDatabase* DatabaseConnector);
GoDBTableWidgetContainer* GetLinkToNewCreatedTraceContainer(
vtkMySQLDatabase* iDatabaseConnector);

template< class myT >
void QMEGAVTKADDON2_EXPORT CreateNewCollectionFromSelection(
Expand Down
11 changes: 11 additions & 0 deletions branches/GoFigure2Beta/Code/IO/GoDBTableWidgetContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,14 @@ int GoDBTableWidgetContainer::GetIndexInsideRowContainer(std::string iInfoName)

return SelectedTracesIDFromRowContainer;
}
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
void GoDBTableWidgetContainer::InsertNewCreatedTrace()
{
/*std::vector<std::string> GetQueryStringForSelectFieldsTables(bool SameFieldsInQuery);
std::vector<std::string> GetQueryStringForTraceJoinedTables(bool SameFieldsInQuery);
int TraceID = int MaxValueForOneColumnInTable(DatabaseConnector,
std::string ColumnName,std::string TableName,std::string field,
std::string value);*/
}
Loading

0 comments on commit 48ab314

Please sign in to comment.