Commit 46555cd1 authored by Stéphane Albert's avatar Stéphane Albert

ENH: Added I18nApplication::Instance<>() and ::ConstInstance<>() methods;...

ENH: Added I18nApplication::Instance<>() and ::ConstInstance<>() methods; Create Dataset directory into Application::CacheDir().
parent 0c2d1680
......@@ -13,6 +13,13 @@ if(WIN32)
add_definitions(-DWIN32)
endif(WIN32)
#----------------------------------------------------------------------------
# ensure DEBUG definitions
#if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
# add_definitions( -D_DEBUG )
#endif()
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG" )
#----------------------------------------------------------------------------
# Monteverdi2 version number. An even minor number corresponds to releases.
set(Monteverdi2_VERSION_MAJOR "0")
......
......@@ -58,12 +58,12 @@ main( int argc, char* argv[] )
mvd::MainWindow mainWindow;
#if 0
// TODO: Correctly manage main-window state via application settings.
mainWindow.showMaximized();
#else
#if defined( _DEBUG )
// Usefull when developping/debugging to avoid overlapping other windows.
mainWindow.show();
#else
// TODO: Correctly manage main-window state via application settings.
mainWindow.showMaximized();
#endif
// This code is here to propagate events from maximization to child
......
......@@ -62,6 +62,36 @@ const char* Application::DATASET_EXT = ".ds";
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
/*****************************************************************************/
void
Application
::DatasetPathName( QString& path,
QString& name,
const QString& imageFilename )
{
// '/tmp/archive.tar.gz'
QFileInfo fileInfo( imageFilename );
#if 0
// Dataset is stored into image-file path.
// E.g. '/tmp'
path = fileInfo.path();
#else
// Dataset is stored into application cache-directory.
// E.g. '$HOME/<CACHE_DIR>'
path = Application::Instance()->GetCacheDir().path();
#endif
// '[_tmp_]archive.tar.gz.<SUFFIX>'
name =
#if 1
fileInfo.canonicalPath().replace( QRegExp( "[/\\\\:]+", "_"), "_" ) +
"_" +
#endif
fileInfo.fileName() +
Application::DATASET_EXT;
}
/*****************************************************************************/
DatasetModel*
Application::LoadDatasetModel( const QString& imageFilename,
......
......@@ -117,10 +117,18 @@ public:
// STATIC METHODS.
/**
* \brief Get the singleton instance of application as an
* Application pointer.
*
* \return The singleton instance of Application.
*/
inline static Application* Instance();
/**
* \brief Get the singleton constant instance of application as an
* Application pointer.
*
* \return The singleton constant instance of I18nApplication.
*/
inline static const Application* ConstInstance();
......@@ -201,7 +209,7 @@ Application*
Application
::Instance()
{
return qobject_cast< Application* >( qApp );
return I18nApplication::Instance< Application >();
}
/*****************************************************************************/
......@@ -210,28 +218,7 @@ const Application*
Application
::ConstInstance()
{
return qobject_cast< const Application* >( qApp );
}
/*****************************************************************************/
inline
void
Application
::DatasetPathName( QString& path,
QString& name,
const QString& imageFilename )
{
// '/tmp/archive.tar.gz'
QFileInfo fileInfo( imageFilename );
// '/tmp/'
path = fileInfo.path();
// 'archive_tar_gz.<SUFFIX>'
name =
fileInfo.baseName() +
"_" + fileInfo.completeSuffix().replace( ".", "_" ) +
Application::DATASET_EXT;
return I18nApplication::ConstInstance< Application >();
}
/*****************************************************************************/
......
......@@ -47,8 +47,14 @@ namespace mvd
Context comment for translator.
*/
/*****************************************************************************/
/* CONSTANTS */
const char* I18nApplication::CACHE_DIR = "mvd2";
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
......
......@@ -97,6 +97,42 @@ public:
/** \brief Destructor. */
virtual ~I18nApplication();
/**
* \brief Get the singleton instance of application as a
* I18Application pointer.
*
* \return The singleton instance of I18nApplication.
*/
inline static I18nApplication* Instance();
/**
* \brief Get the singleton constant instance of application as a
* I18Application pointer.
*
* \return The singleton constant instance of I18nApplication.
*/
inline static const I18nApplication* ConstInstance();
/**
* \brief Get the singleton instance of application (safe) casted
* into the TApplication type.
*
* \return The singleton instance of application (safely) casted
* into TApplication type.
*/
template< typename TApplication >
inline static TApplication* Instance();
/**
* \brief Get the constant singleton instance of application (safe)
* casted into the TApplication type.
*
* \return The constant singleton instance of application (safely)
* casted into TApplication type.
*/
template< typename TApplication >
inline static const TApplication* ConstInstance();
/**
* \brief Create cache directory if not already existing.
*
......@@ -194,6 +230,42 @@ private slots:
namespace mvd
{
/*****************************************************************************/
I18nApplication*
I18nApplication
::Instance()
{
return I18nApplication::Instance< I18nApplication >();
}
/*****************************************************************************/
const I18nApplication*
I18nApplication
::ConstInstance()
{
return I18nApplication::ConstInstance< I18nApplication >();
}
/*****************************************************************************/
template< typename TApplication >
inline
TApplication*
I18nApplication
::Instance()
{
return qobject_cast< TApplication* >( qApp );
}
/*****************************************************************************/
template< typename TApplication >
inline
const TApplication*
I18nApplication
::ConstInstance()
{
return qobject_cast< const TApplication* >( qApp );
}
/*****************************************************************************/
const QDir&
I18nApplication
......
......@@ -49,6 +49,14 @@ namespace mvd
*/
/*****************************************************************************/
/* CONSTANTS */
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
......
......@@ -89,7 +89,7 @@ public:
/** \brief Destructor. */
virtual ~MyClass();
/*-[ PUBLIC SLOTS SECTION ]-----------------------------------------------**/
/*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/
//
// Public SLOTS.
......
......@@ -19,6 +19,10 @@
#include "mvdMyWidget.h"
#include "ui_mvdMyWidget.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
......@@ -45,6 +49,18 @@ namespace mvd
Context comment for translator.
*/
/*****************************************************************************/
/* CONSTANTS */
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
/*******************************************************************************/
MyWidget
::MyWidget( QWidget* parent, Qt::WindowFlags flags ):
......@@ -64,6 +80,4 @@ MyWidget
/* SLOTS */
/*******************************************************************************/
/*******************************************************************************/
} // end namespace 'mvd'
......@@ -94,6 +94,12 @@ public:
/** \brief Destructor. */
virtual ~MyWidget();
/*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/
//
// Public SLOTS.
public slots:
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
......@@ -106,6 +112,8 @@ signals:
// Protected methods.
protected:
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
//
// Protected attributes.
protected:
......@@ -114,8 +122,6 @@ protected:
// Private methods.
private:
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
//
// Private attributes.
private:
......
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