Skip to content
Permalink
Browse files

Merge pull request #1312 from manisandro/composer_manager_nonmodal

Make QgsComposerManager non-modal
  • Loading branch information
nyalldawson committed Apr 30, 2014
2 parents 6f1b875 + a66893d commit ac5e92c4cbdfb88df8ae92628a3ae9ab6e0ad7cf
@@ -3369,3 +3369,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,27 +61,11 @@ 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();
#ifdef Q_WS_MAC
// Create action to select this window
mWindowAction = new QAction( windowTitle(), this );
connect( mWindowAction, SIGNAL( triggered() ), this, SLOT( activate() ) );
#endif

mTemplate->addItem( tr( "Empty composer" ) );
mTemplate->addItem( tr( "Specific" ) );
@@ -109,6 +95,49 @@ 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()
{
QString selName = mComposerListWidget->currentItem() ? mComposerListWidget->currentItem()->text() : "";

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();

// Restore selection
if ( !selName.isEmpty() )
{
QList<QListWidgetItem*> items = mComposerListWidget->findItems( selName, Qt::MatchExactly );
if ( !items.isEmpty() )
{
mComposerListWidget->setCurrentItem( items.first() );
}
}
}

void QgsComposerManager::activate()
{
raise();
setWindowState( windowState() & ~Qt::WindowMinimized );
activateWindow();
}

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

if ( 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 ( !loadedOK )
{
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" ) );
}
}
@@ -268,6 +283,32 @@ void QgsComposerManager::openLocalDirectory( const QString& localDirPath )
QDesktopServices::openUrl( QUrl::fromLocalFile( localDirPath ) );
}

#ifdef Q_WS_MAC
void QgsComposerManager::showEvent(QShowEvent* event)
{
if(!event->spontaneous()) {
QgisApp::instance()->addWindow( mWindowAction );
}
}

void QgsComposerManager::changeEvent( QEvent* event )
{
QDialog::changeEvent( event );
switch ( event->type() )
{
case QEvent::ActivationChange:
if ( QApplication::activeWindow() == this )
{
mWindowAction->setChecked( true );
}
break;

default:
break;
}
}
#endif

void QgsComposerManager::remove_clicked()
{
QListWidgetItem* item = mComposerListWidget->currentItem();
@@ -288,10 +329,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()
@@ -313,7 +350,6 @@ void QgsComposerManager::show_clicked()
{
// extra activation steps for Windows
bool shown = c->isVisible();
hide();

c->activate();

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

@@ -359,7 +394,6 @@ void QgsComposerManager::show_clicked()
c->activate();
}
#endif //0
close();
}

void QgsComposerManager::duplicate_clicked()
@@ -403,11 +437,7 @@ void QgsComposerManager::duplicate_clicked()
if ( newComposer )
{
// extra activation steps for Windows
hide();
newComposer->activate();

// no need to add new composer to list widget, if just closing this->exec();
close();
}
else
{
@@ -31,15 +31,15 @@ class QgsComposerManager: public QDialog, private Ui::QgsComposerManagerBase
QgsComposerManager( QWidget * parent = 0, Qt::WindowFlags f = 0 );
~QgsComposerManager();

public slots:
/** Raise, unminimize and activate this window */
void activate();

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)
*/
@@ -53,6 +53,13 @@ class QgsComposerManager: public QDialog, private Ui::QgsComposerManagerBase
QString mDefaultTemplatesDir;
QString mUserTemplatesDir;

#ifdef Q_WS_MAC
void showEvent(QShowEvent *event);
void changeEvent(QEvent *);

QAction* mWindowAction;
#endif

private slots:
void on_mAddButton_clicked();
/** Slot to track combobox to use specific template path
@@ -72,6 +79,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
@@ -452,6 +452,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
#ifdef Q_OS_WIN
, mSkipNextContextMenuEvent( 0 )
#endif
, mComposerManager( 0 )
, mpGpsWidget( 0 )
{
if ( smInstance )
@@ -776,6 +777,7 @@ QgisApp::QgisApp( )
, mInternalClipboard( 0 )
, mpMaptip( 0 )
, mPythonUtils( 0 )
, mComposerManager( 0 )
, mpGpsWidget( 0 )
{
smInstance = this;
@@ -845,6 +847,8 @@ QgisApp::~QgisApp()

delete mOverviewMapCursor;

delete mComposerManager;

deletePrintComposers();
removeAnnotationItems();

@@ -3931,8 +3935,19 @@ void QgisApp::newPrintComposer()

void QgisApp::showComposerManager()
{
QgsComposerManager m( this );
m.exec();
if ( !mComposerManager )
{
mComposerManager = new QgsComposerManager( this, Qt::Window );
connect( mComposerManager, SIGNAL( finished( int ) ), this, SLOT( deleteComposerManager() ) );
}
mComposerManager->show();
mComposerManager->activate();
}

void QgisApp::deleteComposerManager()
{
mComposerManager->deleteLater();
mComposerManager = 0;
}

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

@@ -42,6 +42,7 @@ class QgsAnnotationItem;
class QgsClipboard;
class QgsComposer;
class QgsComposerView;
class QgsComposerManager;
class QgsContrastEnhancement;
class QgsGeometry;
class QgsFeature;
@@ -1181,6 +1182,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! catch MapCanvas keyPress event so we can check if selected feature collection must be deleted
void mapCanvas_keyPressed( QKeyEvent *e );

//! Deletes the active QgsComposerManager instance
void deleteComposerManager();

signals:
/** emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
@@ -1217,6 +1221,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();
@@ -1518,6 +1526,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QgsPluginManager* mPluginManager;

QgsComposerManager* mComposerManager;

//! Persistent tile scale slider
QgsTileScaleWidget * mpTileScaleWidget;

0 comments on commit ac5e92c

Please sign in to comment.
You can’t perform that action at this time.