Commit 8863131c authored by Stéphane Albert's avatar Stéphane Albert
Browse files

ENH: Added AbstractModel::IsModified(); Tested IsModified() when closing...

ENH: Added AbstractModel::IsModified(); Tested IsModified() when closing window/quitting application.
parent ed705df7
......@@ -253,7 +253,7 @@ void
Application
::OnAboutToQuit()
{
qDebug() << tr( ">DEBUG> mvd::Application::OnAboutToQuit()." );
qDebug() << tr( "mvd::Application::OnAboutToQuit()." );
}
} // end namespace 'mvd'
......@@ -107,6 +107,16 @@ public:
*/
inline AbstractModel* GetModel();
/**
*/
template< typename TModel >
inline const TModel* GetModel() const;
/**
*/
template< typename TModel >
inline TModel* GetModel();
/**
*
*/
......@@ -256,6 +266,26 @@ Application
return m_Model;
}
/*****************************************************************************/
template< typename TModel >
inline
const TModel*
Application
::GetModel() const
{
return qobject_cast< const TModel* >( m_Model );
}
/*****************************************************************************/
template< typename TModel >
inline
TModel*
Application
::GetModel()
{
return qobject_cast< TModel* >( m_Model );
}
/*****************************************************************************/
} // end namespace 'mvd'
......
......@@ -378,14 +378,22 @@ MainWindow
void
MainWindow::closeEvent( QCloseEvent* event )
{
qDebug() << "MainWindow::closeEvent(" << event << ")";
assert( event!=NULL );
/*
if( !GetModel()->IsModified() )
qDebug() << "MainWindow::closeEvent(" << event << ")";
// Ensure there is an application instance.
assert( Application::ConstInstance()!=NULL );
// Ensure that there is no model or that the existing model is a
// DatasetModel.
assert( Application::ConstInstance()->GetModel()==
Application::ConstInstance()->GetModel< DatasetModel >() );
// Get model.
const DatasetModel* model =
Application::ConstInstance()->GetModel< DatasetModel >();
if( model==NULL || !model->IsModified() )
return;
*/
QMessageBox::StandardButton clickedButton = ConfirmSaveQuit( true );
......
......@@ -66,6 +66,14 @@ AbstractModel
{
}
/*******************************************************************************/
bool
AbstractModel
::IsModified() const
{
return false;
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
......
......@@ -104,6 +104,10 @@ public:
/** */
inline void BuildModel( void* context =NULL );
/**
*/
virtual bool IsModified() const;
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
......
......@@ -249,6 +249,27 @@ DatasetModel
m_Descriptor->Write( finfo.filePath() );
}
/*******************************************************************************/
bool
DatasetModel
::IsModified() const
{
ConstAbstractImageModelList aimList( GetImageModels() );
// If, at least one image-model is modified, then this dataset-model
// is considered modified.
for( ConstAbstractImageModelList::const_iterator it( aimList.begin() );
it!=aimList.end();
++it )
{
if( ( *it )->IsModified() )
return true;
}
// Otherwise, this dataset-model is not modified.
return false;
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
......
......@@ -118,17 +118,12 @@ public:
// Public methods.
public:
/** Constructor */
/** \brief Constructor. */
DatasetModel( QObject* parent =NULL );
/** Destructor */
/** \brief Destructor. */
virtual ~DatasetModel();
/** */
#if 0
bool SetContent( const QString& path, const QString& name );
#endif
/**
*/
inline const QDir& GetDirectory() const;
......@@ -157,6 +152,11 @@ public:
*/
inline ConstAbstractImageModelList GetImageModels() const;
//
// AbstractModel overrides.
virtual bool IsModified() const;
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
......
......@@ -737,6 +737,14 @@ VectorImageModel
return oss.str();
}
/*******************************************************************************/
bool
VectorImageModel
::IsModified() const
{
return GetSettings().IsModified();
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
......
......@@ -369,6 +369,11 @@ public:
*/
std::string GetCenterPixelPlaceName();
//
// AbstractModel overrides.
virtual bool IsModified() const;
/*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/
//
......
Supports Markdown
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