Commit a6de4144 authored by Stéphane Albert's avatar Stéphane Albert

BUG: MANTIS-790 (Crash when selecting inconsitent dataset).

parent c63058ff
......@@ -163,7 +163,6 @@ QtWidgetView
this->setLayout(finalLayout);
}
/*******************************************************************************/
QWidget*
QtWidgetView
......
......@@ -135,6 +135,32 @@ DatabaseModel
if( datasetModel==m_SelectedDatasetModel )
return datasetModel;
#if 1
// Release memory from previous model
if( m_SelectedDatasetModel!=NULL )
{
m_SelectedDatasetModel->GetSelectedImageModel()->ReleaseMemory();
}
try
{
// Load dataset sub-models.
datasetModel->LoadImageModels( -1, -1 );
// If dataset model has been loaded, select it.
SetSelectedDatasetModel( datasetModel );
}
catch( ... )
{
// If dataset model has not beed successfully loaded, clear
// selection...
SetSelectedDatasetModel( NULL );
// ...and forward exception.
throw;
}
#else
// Load dataset sub-models.
datasetModel->LoadImageModels( -1, -1 );
......@@ -146,6 +172,7 @@ DatabaseModel
// If dataset model has been loaded, select it.
SetSelectedDatasetModel( datasetModel );
#endif
// Return loaded and selected dataset model.
return datasetModel;
......
......@@ -144,7 +144,12 @@ DatasetModel
if( m_Descriptor==NULL )
return false;
for( QDomElement imageElt( m_Descriptor->FirstImageElement() );
QDomElement imageElt( m_Descriptor->FirstImageElement() );
if( imageElt.isNull() )
return false;
for( ;
!imageElt.isNull() && isConsistent;
imageElt = DatasetDescriptor::NextImageSiblingElement( imageElt ) )
{
......@@ -385,6 +390,8 @@ DatasetModel
assert( context );
assert( context->m_IsLoadSubModelsEnabled );
// throw std::runtime_error( "Debugging error!" );
if( !context->m_IsLoadSubModelsEnabled )
{
return;
......@@ -778,7 +785,7 @@ DatasetModel
QThread* thread = new QThread;
m_PlacenameLoader = new ImagePlacenameLoader( viModel );
m_PlacenameLoader->moveToThread(thread);
// At thread startup, trigger the processing function
QObject::connect(thread,
SIGNAL(started()),
......
......@@ -167,7 +167,7 @@ I18nCoreApplication
// Dataset is stored into application cache-directory.
// E.g. '$HOME/<CACHE_DIR>'
path = I18nCoreApplication::Instance()->GetCacheDir().path();
// get the md5 of the filename
QByteArray result = QCryptographicHash::hash(fileInfo.absoluteFilePath().toAscii(),
QCryptographicHash::Md5);
......@@ -195,8 +195,10 @@ I18nCoreApplication
qDebug() << "Dataset path:" << path;
qDebug() << "Dataset name:" << name;
QString pathname( QDir( path ).filePath( name ) );
// Setup QObject
model->setObjectName( QDir( path ).filePath( name ) );
model->setObjectName( pathname );
try
{
......
......@@ -37,14 +37,12 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "Core/mvdDatabaseModel.h"
//
#include "Gui/mvdDatabaseBrowserWidget.h"
#include "Core/mvdDatabaseModel.h"
#include "Core/mvdVectorImageModel.h"
//
#include "Gui/mvdDatabaseBrowserWidget.h"
#include "Gui/mvdDatabaseTreeWidget.h"
//
#include "Gui/mvdDatasetTreeWidgetItem.h"
namespace mvd
......@@ -82,10 +80,11 @@ DatabaseBrowserController
DatabaseBrowserWidget* widget = GetWidget< DatabaseBrowserWidget >();
QObject::connect(
widget, SIGNAL( CurrentDatasetChanged( const QString& ) ),
widget,
SIGNAL( CurrentDatasetChanged( const QString&, const QString& ) ),
// to:
this,
SLOT( OnCurrentDatasetChanged( const QString& ) )
SLOT( OnCurrentDatasetChanged( const QString&, const QString& ) )
);
QObject::connect(
......@@ -148,11 +147,13 @@ DatabaseBrowserController
DatabaseBrowserWidget* widget = GetWidget< DatabaseBrowserWidget >();
QObject::disconnect(
widget, SIGNAL( CurrentDatasetChanged( const QString& ) ),
widget,
SIGNAL( CurrentDatasetChanged( const QString&, const QString& ) ),
// from:
this, SLOT( OnCurrentDatasetChanged( const QString& ) )
this,
SLOT( OnCurrentDatasetChanged( const QString&, const QString& ) )
);
//
QObject::disconnect(
this,
......@@ -185,18 +186,7 @@ void
DatabaseBrowserController
::ResetWidget()
{
#if 0
//
// Access model.
DatabaseModel* model = GetModel< DatabaseModel >();
assert( model!=NULL );
ResetDatasetTree( model->QueryDatasetModels() );
#else
RefreshWidget();
#endif
}
/*******************************************************************************/
......@@ -255,6 +245,8 @@ DatabaseBrowserController
);
QString datasetId = currentDatasetItem->GetId();
// qDebug() << "Checking dataset:" << currentDatasetItem->GetId();
const DatasetModel* datasetModel = model->FindDatasetModel( datasetId );
assert( datasetModel!=NULL );
......@@ -279,7 +271,7 @@ DatabaseBrowserController
/*******************************************************************************/
void
DatabaseBrowserController
::OnCurrentDatasetChanged( const QString& id )
::OnCurrentDatasetChanged( const QString& id, const QString& previousId )
{
// qDebug() << this << "::OnCurrentDatasetChanged(" << id << ")";
......@@ -288,17 +280,60 @@ DatabaseBrowserController
DatabaseModel* model = GetModel< DatabaseModel >();
// set the newly selected dataset id
model->SelectDatasetModel( id );
try
{
// set the newly selected dataset id
model->SelectDatasetModel( id );
}
catch( std::exception& exc )
{
QMessageBox::warning(
GetWidget(),
PROJECT_NAME,
tr( "Failed to load dataset.\n\n%1" ).arg( exc.what() ),
QMessageBox::Ok
);
// assert( false && "Debug SetCurrentDataset() or remove call." );
/*
assert( GetWidget< DatabaseBrowserWidget >()==GetWidget() );
GetWidget< DatabaseBrowserWidget >()->SetCurrentDataset( previousId );
*/
emit SelectedDatasetFilenameChanged( QString() );
return;
}
catch( ... )
{
QMessageBox::warning(
GetWidget(),
PROJECT_NAME,
tr( "Failed to load dataset.\n" ),
QMessageBox::Ok
);
/*
assert( GetWidget< DatabaseBrowserWidget >()==GetWidget() );
GetWidget< DatabaseBrowserWidget >()->SetCurrentDataset( previousId );
*/
emit SelectedDatasetFilenameChanged( QString() );
return;
}
// emit selected dataset image filename
VectorImageModel * imageModel
= qobject_cast< VectorImageModel *>(model->GetSelectedDatasetModel()->GetSelectedImageModel());
= qobject_cast< VectorImageModel *>(
model->GetSelectedDatasetModel()->GetSelectedImageModel()
);
//
// this signal is used to pass the current dataset input filename.
// it is connected to the DatabaseBrowserWidget custom QTreeWidget
emit SelectedDatasetFilenameChanged(imageModel->GetFilename());
emit SelectedDatasetFilenameChanged( imageModel->GetFilename() );
}
/*******************************************************************************/
......
......@@ -43,8 +43,8 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdAbstractModelController.h"
#include "mvdGui.h"
#include "Gui/mvdAbstractModelController.h"
#include "Gui/mvdGui.h"
/*****************************************************************************/
......@@ -167,12 +167,12 @@ private:
private slots:
/**
* \brief Slot called when the current (selected) dataset has
* changed.
* \brief Slot called when the currently selected dataset has changed.
*
* \param name The name of the newly selected dataset.
* \param id The ID of the newly selected dataset.
* \param previousId The ID of the previously selected dataset.
*/
void OnCurrentDatasetChanged( const QString& name );
void OnCurrentDatasetChanged( const QString& id, const QString& previousId );
/**
*/
......
......@@ -243,10 +243,26 @@ DatabaseBrowserWidget
assert( items.isEmpty() || items.size() == 1 );
/*
qDebug()
<< ( items.isEmpty() ? "NONE" : items.first()->text( 0 ) )
<< m_UI->databaseTreeWidget->selectionModel()->selectedIndexes().size();
*/
#if 0
m_UI->databaseTreeWidget->setCurrentItem(
items.isEmpty() ? NULL : items.first(),
0,
QItemSelectionModel::Clear |
QItemSelectionModel::Current
);
#else
if( items.isEmpty() )
return;
m_UI->databaseTreeWidget->setCurrentItem( items.first() );
#endif
}
/*******************************************************************************/
......@@ -255,30 +271,35 @@ DatabaseBrowserWidget
void
DatabaseBrowserWidget
::on_databaseTreeWidget_currentItemChanged( QTreeWidgetItem* current,
QTreeWidgetItem* previous )
QTreeWidgetItem* previous )
{
/*
qDebug() <<
this <<
"::on_databaseTreeWidget_currentItemChanged(" <<
current << ", " << previous <<
")";
*/
//
// Current
// assert( current!=previous );
// TODO: Should be DatabaseModel::DatasetId but widgets should not depend on models!!!
QString currentId;
// if current is root and not NULL get the Id of the
// corresponding Dataset
if ( current && current->parent() )
{
emit CurrentDatasetChanged(
dynamic_cast<DatasetTreeWidgetItem*>(current)->GetId()
);
}
else
{
emit CurrentDatasetChanged( QString() );
}
DatasetTreeWidgetItem* currentItem = dynamic_cast< DatasetTreeWidgetItem* >( current );
if( currentItem!=NULL && currentItem->parent()!=NULL )
// if current is root and not NULL get the Id of the corresponding
// Dataset.
currentId = currentItem->GetId();
//
// Previous
// TODO: Should be DatabaseModel::DatasetId but widgets should not depend on models!!!
QString previousId;
DatasetTreeWidgetItem* previousItem = dynamic_cast< DatasetTreeWidgetItem* >( previous );
if( previousItem!=NULL )
previousId = previousItem->GetId();
//
// Emit event.
emit CurrentDatasetChanged( currentId, previousId );
}
/*******************************************************************************/
......
......@@ -131,12 +131,13 @@ public slots:
signals:
/**
* \brief Slot emitted when the current (selected) dataset has
* changed.
* \brief Slot emitted when the currently selected dataset has changed.
*
* \param text Name of new current (selected) dataset.
* \param id ID of newly selected dataset.
* \param previousId ID of the previously selected dataset.
*/
void CurrentDatasetChanged( const QString& text );
void CurrentDatasetChanged( const QString& id,
const QString& previousId =QString() );
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>94</width>
<width>262</width>
<height>116</height>
</rect>
</property>
......@@ -38,6 +38,12 @@
</item>
<item row="1" column="0">
<widget class="mvd::DatabaseTreeWidget" name="databaseTreeWidget">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<column>
<property name="text">
<string>Name</string>
......
......@@ -204,7 +204,8 @@ DatabaseTreeWidget::dropEvent(QDropEvent *event)
/* SLOTS */
/*******************************************************************************/
void
DatabaseTreeWidget::OnSelectedDatasetFilenameChanged(const QString& filename)
DatabaseTreeWidget
::OnSelectedDatasetFilenameChanged( const QString& filename )
{
//
// update the dataset image filename to be used in the dragged mime data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment