Skip to content
Permalink
Browse files
Make QgsComposerManager non-modal, ensure consistency of composer man…
…ager composer list
  • Loading branch information
manisandro committed Apr 9, 2014
1 parent e71930f commit c51be63d75438f9ad669fb1331c6d242ba13adce
@@ -3184,3 +3184,4 @@ void QgsComposer::updateAtlasMapLayerAction( bool atlasEnabled )
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, QgsFeature* ) ) );
}
}

@@ -42,6 +42,8 @@ QgsComposerManager::QgsComposerManager( QWidget * parent, Qt::WindowFlags f ): Q
restoreGeometry( settings.value( "/Windows/ComposerManager/geometry" ).toByteArray() );

connect( mButtonBox, SIGNAL( rejected() ), this, SLOT( close() ) );
connect( QgisApp::instance(), SIGNAL( composerAdded( QgsComposerView* ) ), this, SLOT( refreshComposers() ) );
connect( QgisApp::instance(), SIGNAL( composerRemoved( QgsComposerView* ) ), this, SLOT( refreshComposers() ) );

pb = new QPushButton( tr( "&Show" ) );
mButtonBox->addButton( pb, QDialogButtonBox::ActionRole );
@@ -59,28 +61,6 @@ QgsComposerManager::QgsComposerManager( QWidget * parent, Qt::WindowFlags f ): Q
mButtonBox->addButton( pb, QDialogButtonBox::ActionRole );
connect( pb, SIGNAL( clicked() ), this, SLOT( rename_clicked() ) );

initialize();
}

QgsComposerManager::~QgsComposerManager()
{
QSettings settings;
settings.setValue( "/Windows/ComposerManager/geometry", saveGeometry() );
}

void QgsComposerManager::initialize()
{
QSettings settings;
QSet<QgsComposer*> composers = QgisApp::instance()->printComposers();
QSet<QgsComposer*>::const_iterator it = composers.constBegin();
for ( ; it != composers.constEnd(); ++it )
{
QListWidgetItem* item = new QListWidgetItem(( *it )->title(), mComposerListWidget );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
mItemComposerMap.insert( item, *it );
}
mComposerListWidget->sortItems();

mTemplate->addItem( tr( "Empty composer" ) );
mTemplate->addItem( tr( "Specific" ) );

@@ -109,6 +89,30 @@ void QgsComposerManager::initialize()
}

mTemplatePathLineEdit->setText( settings.value( "/UI/ComposerManager/templatePath", QString( "" ) ).toString() );

refreshComposers();
}

QgsComposerManager::~QgsComposerManager()
{
QSettings settings;
settings.setValue( "/Windows/ComposerManager/geometry", saveGeometry() );
}

void QgsComposerManager::refreshComposers()
{
mItemComposerMap.clear();
mComposerListWidget->clear();

QSet<QgsComposer*> composers = QgisApp::instance()->printComposers();
QSet<QgsComposer*>::const_iterator it = composers.constBegin();
for ( ; it != composers.constEnd(); ++it )
{
QListWidgetItem* item = new QListWidgetItem(( *it )->title(), mComposerListWidget );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
mItemComposerMap.insert( item, *it );
}
mComposerListWidget->sortItems();
}

QMap<QString, QString> QgsComposerManager::defaultTemplates( bool fromUser ) const
@@ -200,25 +204,11 @@ void QgsComposerManager::on_mAddButton_clicked()
}
}

if ( loadedOK )
if ( newComposer && !loadedOK )
{
// do not close on Add, since user may want to add multiple composers from templates
QListWidgetItem* item = new QListWidgetItem( newComposer->title(), mComposerListWidget );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
mItemComposerMap.insert( item, newComposer );

mComposerListWidget->sortItems();
mComposerListWidget->setCurrentItem( item );
mComposerListWidget->setFocus();
}
else
{
if ( newComposer )
{
newComposer->close();
QgisApp::instance()->deleteComposer( newComposer );
newComposer = 0;
}
newComposer->close();
QgisApp::instance()->deleteComposer( newComposer );
newComposer = 0;
QMessageBox::warning( this, tr( "Template error" ), tr( "Error, could not load template file" ) );
}
}
@@ -288,10 +278,6 @@ void QgsComposerManager::remove_clicked()
{
QgisApp::instance()->deleteComposer( it.value() );
}
mItemComposerMap.remove( item );
mComposerListWidget->removeItemWidget( item );
//and remove the list widget row
delete( mComposerListWidget->takeItem( mComposerListWidget->row( item ) ) );
}

void QgsComposerManager::show_clicked()
@@ -350,7 +336,6 @@ void QgsComposerManager::show_clicked()
if ( c )
{
c->readXML( templateDoc );
mItemComposerMap.insert( it.key(), c );
}
}

@@ -31,15 +31,11 @@ class QgsComposerManager: public QDialog, private Ui::QgsComposerManagerBase
QgsComposerManager( QWidget * parent = 0, Qt::WindowFlags f = 0 );
~QgsComposerManager();


private:
/**Stores the relation between items and composer pointers. A 0 pointer for the composer means that
this composer needs to be created from a default template*/
QMap<QListWidgetItem*, QgsComposer*> mItemComposerMap;

/**Enters the composer instances and created the item-composer map*/
void initialize();

/** Returns the default templates (key: template name, value: absolute path to template file)
* @param fromUser whether to return user templates from ~/.qgis/composer_templates (added in 1.9)
*/
@@ -72,6 +68,9 @@ class QgsComposerManager: public QDialog, private Ui::QgsComposerManagerBase
*/
void on_mTemplatesUserDirBtn_pressed();

/** Refreshes the list of composers */
void refreshComposers();

void remove_clicked();
void show_clicked();
/** Duplicate composer
@@ -3919,8 +3919,11 @@ void QgisApp::newPrintComposer()

void QgisApp::showComposerManager()
{
QgsComposerManager m( this );
m.exec();
QgsComposerManager* m = new QgsComposerManager( this, Qt::Window );
connect( m, SIGNAL( finished( int ) ), m, SLOT( deleteLater() ) );
m->show();
m->raise();
m->activateWindow();
}

void QgisApp::saveMapAsImage()
@@ -5004,6 +5007,7 @@ void QgisApp::deleteComposer( QgsComposer* c )
mPrintComposers.remove( c );
mPrintComposersMenu->removeAction( c->windowAction() );
markDirty();
emit composerRemoved( c->view() );
delete c;
}

@@ -1208,6 +1208,10 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
@note added in version 1.4*/
void composerWillBeRemoved( QgsComposerView* v );

/**This signal is emitted when a composer instance has been removed
@note added in version 2.3*/
void composerRemoved( QgsComposerView* v );

/**This signal is emitted when QGIS' initialization is complete
@note added in version 1.6*/
void initializationCompleted();

0 comments on commit c51be63

Please sign in to comment.