Commit 01d04f4a authored by Stéphane Albert's avatar Stéphane Albert
Browse files

ENH: Added settings pointer to AbstractImageModel::BuildContext; Improved...

ENH: Added settings pointer to AbstractImageModel::BuildContext; Improved ::BuildContext constructors; Simplified DatasetModel::Import/LoadImage() interface (using AbstractImageModel::BuildContext).
parent f31cf8e8
......@@ -95,12 +95,20 @@ public:
// Public methods.
public:
/** \brief Constructor. */
BuildContext( const QString& filename =QString(),
int id =-1,
const QString& quicklook =QString() ) :
m_Id( id ),
BuildContext( void* const settings ) :
m_Id( -1 ),
m_Filename(),
m_Quicklook(),
m_Settings( settings )
{
}
/** \brief Constructor. */
BuildContext( const QString& filename ) :
m_Id( -1 ),
m_Filename( filename ),
m_Quicklook( quicklook )
m_Quicklook(),
m_Settings( NULL )
{
}
......@@ -110,6 +118,7 @@ public:
int m_Id;
QString m_Filename;
QString m_Quicklook;
void * const m_Settings;
};
//
......
......@@ -89,53 +89,51 @@ void
DatasetModel
::ImportImage( const QString& filename, int width, int height )
{
LoadImage( filename, width, height, -1, QString() );
AbstractImageModel::BuildContext context( filename );
LoadImage( context, width, height );
}
/*******************************************************************************/
AbstractImageModel*
DatasetModel
::LoadImage( const QString& filename,
::LoadImage( AbstractImageModel::BuildContext& context,
int width,
int height,
int id,
const QString& quicklook )
int height )
{
// Check input parameters.
assert( (id<0 && quicklook.isEmpty()) ||
(id>=0 && !quicklook.isEmpty()) );
assert( (context.m_Id<0 && context.m_Quicklook.isEmpty()) ||
(context.m_Id>=0 && !context.m_Quicklook.isEmpty()) );
// 1. Instanciate local image model.
VectorImageModel* vectorImageModel = new VectorImageModel( this );
// 2. Safely load data from file.
try
//
// 1.1. Assign new image ID to build-context if first time loading.
// Remember provided ID.
int id = context.m_Id;
// Assign image-model ID to build-context if there is none
// provided but keep provided one to test if it's first time
// import or next time loading of image-model.
if( id<0 )
{
//
// 2.1. Fill-in image-model build-contex with provided id (which
// may be -1 if first-time import of image-model.
AbstractImageModel::BuildContext context( filename, id, quicklook );
// Assign image-model ID to build-context if there is none
// provided but keep provided one to test if it's first time
// import or next time loading of image-model.
if( id<0 )
{
AbstractImageModelList aimList( GetImageModels() );
context.m_Id = aimList.indexOf( vectorImageModel );
AbstractImageModelList aimList( GetImageModels() );
context.m_Id = aimList.indexOf( vectorImageModel );
qDebug()
<< "Generated ID" << context.m_Id
<< "for image-file " << context.m_Filename << ".";
}
qDebug()
<< "Generated ID" << context.m_Id
<< "for image-file " << context.m_Filename << ".";
}
// 2. Safely load data from file.
try
{
//
// 2.2. Set image-model content.
// 2.1. Set image-model content.
// TODO: SetFilename() into VectorImageModel::virtual_BuildModel().
vectorImageModel->SetFilename( context.m_Filename, width, height );
//
// 2.3. Build image-model structure and generate cached data).
// 2.2. Build image-model structure and generate cached data).
vectorImageModel->BuildModel( &context );
assert( vectorImageModel->GetQuicklookModel()!=NULL );
......@@ -143,7 +141,7 @@ DatasetModel
if( id<0 )
{
//
// 2.4a: Add image to Dataset descriptor file...
// 2.3a: Add image to Dataset descriptor file...
m_Descriptor->InsertImageModel(
// ...providing newly calculated image-model ID.
context.m_Id,
......@@ -153,13 +151,12 @@ DatasetModel
);
//
// 2.5a: Force writing descriptor with newly imported image.
// 2.4a: Force writing descriptor with newly imported image.
WriteDescriptor();
}
//
// 2.6
// Connect rendering-settings updated of image-model to
// 2.5. Connect rendering-settings updated of image-model to
// dataset-model in order to update XML descriptor.
QObject::connect(
vectorImageModel,
......@@ -249,30 +246,29 @@ DatasetModel
imageElt = DatasetDescriptor::NextImageSiblingElement( imageElt ) )
{
// Locals.
int id = -1;
QString filename;
QString quicklook;
VectorImageModel::Settings settings;
AbstractImageModel::BuildContext imageContext( &settings );
// Read image-model descriptor information.
DatasetDescriptor::GetImageModel(
imageElt,
id, filename, &settings, quicklook
imageContext.m_Id,
imageContext.m_Filename,
imageContext.m_Settings,
imageContext.m_Quicklook
);
// Traces.
qDebug()
<< "Input image:"
<< "\nID:" << id
<< "\nfilename:" << filename
<< "\nquicklook:" << quicklook;
<< "\nID:" << imageContext.m_Id
<< "\nfilename:" << imageContext.m_Filename
<< "\nquicklook:" << imageContext.m_Quicklook;
// TODO: 3) Remove WxH for screen best-fit during loading of model!
AbstractImageModel* imageModel = LoadImage(
filename,
context->m_Width, context->m_Height,
id,
quicklook
imageContext,
context->m_Width, context->m_Height
);
// Access vector image-model.
......
......@@ -44,7 +44,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdAbstractModel.h"
#include "mvdAbstractImageModel.h"
#include "mvdTypes.h"
......@@ -61,7 +61,6 @@ namespace mvd
{
//
// Internal classes pre-declaration.
class AbstractImageModel;
class DatasetDescriptor;
/*****************************************************************************/
......@@ -206,14 +205,12 @@ private:
inline AbstractImageModelList GetImageModels();
/** */
AbstractImageModel* LoadImage( const QString& filename,
AbstractImageModel* LoadImage( AbstractImageModel::BuildContext& context,
int width,
int height,
int id,
const QString& quicklook );
int height );
/** */
void ParseDescriptor(BuildContext* bContext );
void ParseDescriptor( BuildContext* context );
/** */
void WriteDescriptor() const;
......
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