Commit 598a59fe authored by Frédéric Larue's avatar Frédéric Larue
Browse files

Tool progress bar system changed.

parent 19f16973
......@@ -19,7 +19,8 @@ AlgorithmSelector::AlgorithmSelector(QWidget *parent) :
QWidget( parent ),
m_ui( new Ui::AlgorithmSelector ),
m_SelectedTool( NULL ),
m_SelectedToolParam( NULL )
m_SelectedToolParam( NULL ),
m_CurrentToolProgress( NULL )
{
m_ui->setupUi(this);
m_ui->groupToolDescription->hide();
......@@ -38,6 +39,7 @@ AlgorithmSelector::AlgorithmSelector(QWidget *parent) :
AlgorithmSelector::~AlgorithmSelector()
{
delete m_CurrentToolProgress;
delete m_ui;
}
......@@ -271,44 +273,66 @@ void AlgorithmSelector::applyCurrentToolOn( const QList<GenericUIData*> &items,
{
if( m_SelectedTool )
{
UIContext ctx;
ctx.mainwin = mainwin;
ctx.glviewer = glviewer;
ctx.project = project;
m_ToolContext.mainwin = mainwin;
m_ToolContext.glviewer = glviewer;
m_ToolContext.project = project;
QVector<QString> acceptedTypes;
m_SelectedTool->plugin->acceptedDataTypes( m_SelectedTool->id, acceptedTypes );
QMap<QString,int> acceptedTypeIds;
for( int i=0; i<acceptedTypes.size(); ++i )
acceptedTypeIds[ acceptedTypes[i] ] = i;
UIToolDataSet dataSet;
dataSet.items.resize( acceptedTypes.size() );
foreach( GenericUIData *m, items )
for( int k=0; k<acceptedTypes.size(); ++k )
if( m->GetTypeString() == acceptedTypes[k] )
dataSet.items[k].push_back( m );
unsigned int nProgressBars = m_SelectedTool->plugin->needProgressBars( m_SelectedTool->id );
UIMultiProgressDialog *progressDlg = NULL;
if( nProgressBars > 0 )
for( GenericUIData *m : items )
{
progressDlg = new UIMultiProgressDialog( nProgressBars, mainwin );
progressDlg->setWindowTitle( m_SelectedTool->plugin->name(m_SelectedTool->id) );
connect( m_SelectedTool->plugin, SIGNAL(notifyProgressBar(unsigned int,QString,int)), progressDlg, SLOT(setBar(unsigned int,QString,int)) );
connect( m_SelectedTool->plugin, SIGNAL(notifyProgressValue(unsigned int,int)), progressDlg, SLOT(setProgress(unsigned int,int)) );
auto found = acceptedTypeIds.find( m->GetTypeString() );
if( found != acceptedTypeIds.end() )
dataSet.items[ found.value() ].push_back( m );
}
connect( m_SelectedTool->plugin, SIGNAL(notifyCreateProgressBars(int)), this, SLOT(createProgressBars(int)) );
connect( m_SelectedTool->plugin, SIGNAL(notifyDeleteProgressBars()), this, SLOT(deleteProgressBars()) );
bool executionOk;
if( m_ActionId.isNull() )
executionOk = m_SelectedTool->plugin->exec( m_SelectedTool->id, dataSet, *m_SelectedToolParam, ctx );
executionOk = m_SelectedTool->plugin->exec( m_SelectedTool->id, dataSet, *m_SelectedToolParam, m_ToolContext );
else
executionOk = m_SelectedTool->plugin->execAction( m_SelectedTool->id, m_ActionId, dataSet, *m_SelectedToolParam, ctx );
executionOk = m_SelectedTool->plugin->execAction( m_SelectedTool->id, m_ActionId, dataSet, *m_SelectedToolParam, m_ToolContext );
if( progressDlg )
{
progressDlg->close();
progressDlg->deleteLater();
}
disconnect( m_SelectedTool->plugin, SIGNAL(notifyCreateProgressBars(int)), this, SLOT(createProgressBars(int)) );
disconnect( m_SelectedTool->plugin, SIGNAL(notifyDeleteProgressBars()), this, SLOT(deleteProgressBars()) );
deleteProgressBars();
emit toolExecutionFinished( executionOk );
}
}
void AlgorithmSelector::createProgressBars( int n )
{
deleteProgressBars();
if( n > 0 )
{
m_CurrentToolProgress = new UIMultiProgressDialog( n, m_ToolContext.mainwin );
m_CurrentToolProgress->setWindowTitle( m_SelectedTool->plugin->name(m_SelectedTool->id) );
connect( m_SelectedTool->plugin, SIGNAL(notifyProgressBar(unsigned int,QString,int)), m_CurrentToolProgress, SLOT(setBar(unsigned int,QString,int)) );
connect( m_SelectedTool->plugin, SIGNAL(notifyProgressValue(unsigned int,int)), m_CurrentToolProgress, SLOT(setProgress(unsigned int,int)) );
}
}
void AlgorithmSelector::deleteProgressBars()
{
if( m_CurrentToolProgress )
{
m_CurrentToolProgress->close();
m_CurrentToolProgress->deleteLater();
m_CurrentToolProgress = NULL;
}
}
......@@ -21,6 +21,7 @@
class UIMultiProgressDialog;
namespace Ui {
class AlgorithmSelector;
}
......@@ -51,6 +52,9 @@ private:
QVector< QVector<ToolDescriptor> > m_ToolsByCategory;
QVector< int > m_LastUsedInCategory;
UIContext m_ToolContext;
UIMultiProgressDialog *m_CurrentToolProgress;
public:
AlgorithmSelector( QWidget *parent = NULL );
......@@ -69,6 +73,8 @@ protected:
private slots:
void selectCategory( int categoryId );
void selectTool( int n );
void createProgressBars( int n );
void deleteProgressBars();
public slots:
void emitApplySignal();
......
......@@ -52,8 +52,6 @@ public:
virtual void declareParameters( int id, UIParamSet &params ) = 0;
/** Function called when the value of a parameter has changed. */
virtual void onUpdatingParameter( UIParam *p ) {}
/** Specify the number of progress bar to show. If 0, no progress bar is shown */
virtual unsigned int needProgressBars( int id ) const { return 0; }
/** Core function that effectively performs the tool execution. Data to be processed are
* given to the function through the vector *items*. Each cell of this vector contains
* a list of BaseManageable, whose concrete type is the one given by the corresponding
......@@ -68,16 +66,24 @@ public:
inline void logMsg( const QString& msg ) {}
/** Creates a dialog box containing N progress bars. */
inline void createProgressBars( int n ) { emit notifyCreateProgressBars(n); }
/** Delete a previously created progress bar dialog box. */
inline void deleteProgressBars() { emit notifyDeleteProgressBars(); }
/** Set up the label and maximum value of the specified progress bar. */
inline void setProgressBar( const QString& label,
int maxValue ) { emit notifyProgressBar( 0, label, maxValue ); }
inline void setProgressBar( unsigned int n,
const QString& label,
int maxValue ) { emit notifyProgressBar( n, label, maxValue ); }
/** Set the current progress value of the specified progress bar. */
inline void reportProgress( int value ) { emit notifyProgressValue( 0, value ); }
inline void reportProgress( unsigned int n, int value ) { emit notifyProgressValue( n, value ); }
signals:
void notifyCreateProgressBars( int n );
void notifyDeleteProgressBars();
void notifyProgressBar( unsigned int n, const QString& label, int maxValue );
void notifyProgressValue( unsigned int n, int value );
......
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