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

ENH: Improved VectorImageModel::Settings to keep track of modified and applied...

ENH: Improved VectorImageModel::Settings to keep track of modified and applied flag (replacing old dirty flag); Cought MainWindow::closeEvent() and displated confirm save/discard/cancel dialog.
parent 769e6832
......@@ -194,12 +194,6 @@ MainWindow
// add needed widget to the status bar
InitializeStatusBarWidgets();
// Connect Quit action of main menu to QApplication's quit() slot.
QObject::connect(
m_UI->action_Quit, SIGNAL( activated() ),
qApp, SLOT( quit() )
);
// Connect Appllication and MainWindow when selected model is about
// to change.
QObject::connect(
......@@ -380,6 +374,41 @@ MainWindow
return dockWidget;
}
/*****************************************************************************/
void
MainWindow::closeEvent( QCloseEvent* event )
{
qDebug() << "MainWindow::closeEvent(" << event << ")";
assert( event!=NULL );
/*
if( !GetModel()->IsModified() )
return;
*/
QMessageBox::StandardButton clickedButton = ConfirmSaveQuit( true );
switch( clickedButton )
{
case QMessageBox::Save:
break;
case QMessageBox::Discard:
break;
case QMessageBox::Cancel:
// Ignore event: do not close/quit.
event->ignore();
break;
default:
// should never be reached.
assert( false );
break;
}
}
/*****************************************************************************/
/* SLOTS */
/*****************************************************************************/
......@@ -399,6 +428,14 @@ MainWindow
emit OpenImageRequest( filename );
}
/*****************************************************************************/
void
MainWindow
::on_action_Quit_triggered()
{
close();
}
/*****************************************************************************/
void
MainWindow
......
......@@ -126,6 +126,11 @@ signals:
// Protected methods.
protected:
//
// QMainWindow overrides.
void closeEvent( QCloseEvent* event );
//
// Protected attributes.
protected:
......@@ -191,6 +196,10 @@ private:
/** Read settings from a settings file*/
void InitializeDsPathSettings();
/**
*/
inline QMessageBox::StandardButton ConfirmSaveQuit( bool canBeCancelled );
//
// Private attributes.
private:
......@@ -234,6 +243,12 @@ private slots:
*/
void on_action_Open_activated();
/**
* \brief Qt auto-connected slot which is called when File/Quit menu
* action is activated.
*/
void on_action_Quit_triggered();
/**
* \brief Qt auto-connected slots which are called when View/Quicklook,
* View/Color Setup, View/Color Dynamics check boxes are toggled.
......@@ -385,6 +400,24 @@ MainWindow
controller->SetModel( model );
}
/*****************************************************************************/
inline
QMessageBox::StandardButton
MainWindow
::ConfirmSaveQuit( bool canBeCancelled )
{
return QMessageBox::question(
this,
tr( PROJECT_NAME ),
tr( "Dataset has been modified.\n"
"Do you want to save settings before quitting?" ),
QMessageBox::Save |
QMessageBox::Discard |
( canBeCancelled ? QMessageBox::Cancel : QMessageBox::NoButton ),
QMessageBox::Save
);
}
} // end namespace 'mvd'
#endif // __MainWindow_h
......@@ -63,6 +63,7 @@ ColorSetupWidget
QWidget( parent, flags ),
m_UI( new mvd::Ui::ColorSetupWidget() )
{
// TODO: Change to static constant see Qt I18n documentation.
// This array is here to statically expose the main enhanced band
// names that OTB can returns for translation purposes.
const char*
......
......@@ -46,7 +46,10 @@
/* MACROS */
/** \brief Indent space when writing XML DOM documents. */
#define XML_INDENT 2
namespace
{
const int XML_INDENT = 2;
}
namespace mvd
{
......
......@@ -290,8 +290,11 @@ VectorImageModel
ParametersType::ValueType index = 2 * i;
GetSettings().DynamicsParam( index ) = histogramModel->Quantile( band , 0.02 );
GetSettings().DynamicsParam( index + 1) = histogramModel->Quantile( band , 0.02, BOUND_UPPER );
GetSettings().DynamicsParam( index ) =
histogramModel->Quantile( band , 0.02, BOUND_LOWER );
GetSettings().DynamicsParam( index + 1) =
histogramModel->Quantile( band , 0.02, BOUND_UPPER );
}
}
......@@ -335,7 +338,7 @@ VectorImageModel
// Don't do anything if the region did not changed
if ( m_PreviousRegion!=region ||
GetSettings().IsDirty() ||
!GetSettings().IsApplied() ||
refresh )
{
// check that the current and the previous region have some pixels in
......@@ -346,7 +349,7 @@ VectorImageModel
// if the first time or no pixels in common , reload all
if ( res &&
m_PreviousRegion!=ImageRegionType() &&
!GetSettings().IsDirty() &&
GetSettings().IsApplied() &&
!refresh )
{
// Compute loaded region, and the four regions not loaded yet
......@@ -418,7 +421,7 @@ VectorImageModel
}
// settings changes have been taken into account, clean the dirty flag
GetSettings().ClearDirty();
GetSettings().SetApplied();
// Store the region
m_PreviousRegion = region;
......
......@@ -92,49 +92,69 @@ public:
typedef DefaultImageType SourceImageType;
/**
* \brief WIP.
*/
class Settings
{
//
// Public types.
public:
/**
*/
typedef UIntVector ChannelVector;
//
// Public methods.
public:
/** Constructor */
/**
* \brief Constructor.
*/
Settings() :
m_IsDirty( false ),
m_RgbChannels(),
m_DynamicsParams( 6 )
m_DynamicsParams( 6 ),
m_IsModified( false ),
m_IsApplied( false )
{
}
/** Destructor */
/**
* \brief Destructor.
*/
~Settings()
{
}
/** */
/**
*/
inline
bool
IsDirty() const
IsApplied() const
{
return m_IsDirty;
return m_IsApplied;
}
/**
*/
inline
bool
IsModified() const
{
return m_IsModified;
}
/** */
inline
void
SetDirty()
SetModified()
{
m_IsDirty = true;
m_IsModified = true;
m_IsApplied = false;
}
/** */
inline void ClearDirty()
inline void SetApplied()
{
m_IsDirty = false;
m_IsApplied = true;
}
/** */
......@@ -143,7 +163,8 @@ public:
SetRgbChannels( const ChannelVector& rgb )
{
m_RgbChannels = rgb;
SetDirty();
SetModified();
}
/** */
......@@ -160,7 +181,8 @@ public:
ChannelVector::value_type&
RgbChannel( ChannelVector::size_type i )
{
SetDirty();
SetModified();
return m_RgbChannels[ i ];
}
......@@ -180,7 +202,8 @@ public:
SetDynamicsParams( const ParametersType& params )
{
m_DynamicsParams = params;
SetDirty();
SetModified();
}
/**
......@@ -207,44 +230,39 @@ public:
ParametersType::ValueType&
DynamicsParam( CountType i )
{
SetDirty();
SetModified();
return m_DynamicsParams[ i ];
}
#if 0
//
// Private attributes.
private:
/**
* \brief Color-composition setup (file-component to video
* RGB-components).
*/
inline
const ParametersType::ValueType&
DynamicsParam( RgbaChannel channel ) const
{
return m_DynamicsParams[ m_RgbChannels[ channel ] ];
}
ChannelVector m_RgbChannels;
/**
* \brief Color-dynamics parameters (\sa
* HistogramModel::Quantile()).
*/
inline
ParametersType::ValueType&
DynamicsParam( RgbaChannel channel )
{
return m_DynamicsParams[ m_RgbChannels[ channel ] ];
}
#endif
ParametersType m_DynamicsParams;
//
// Private attributes.
private:
/** Flag which notices when display Settings has been modified and
* have not yet been rendered.
*/
bool m_IsDirty;
/**
* Color-composition setup (file-component to video RGB-components).
* \brief Flag which notices that rendering settings have been
* edited.
*/
ChannelVector m_RgbChannels;
// TODO: Optimize using C++ bitset bool foo:1;
bool m_IsModified;
/**
* \brief Flag which notices that rendering settings have been
* applied to display.
*/
ParametersType m_DynamicsParams;
// TODO: Optimize using C++ bitset bool foo:1;
bool m_IsApplied;
};
//
......
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