[QGIS Commit] r14951 - in trunk/qgis/src: app app/composer
core/composer ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Dec 20 20:27:40 EST 2010
Author: timlinux
Date: 2010-12-20 17:27:40 -0800 (Mon, 20 Dec 2010)
New Revision: 14951
Added:
trunk/qgis/src/app/composer/qgscomposerlegendlayersdialog.cpp
trunk/qgis/src/app/composer/qgscomposerlegendlayersdialog.h
trunk/qgis/src/ui/qgscomposerlegendlayersdialogbase.ui
Modified:
trunk/qgis/src/app/CMakeLists.txt
trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp
trunk/qgis/src/app/composer/qgscomposerlegendwidget.h
trunk/qgis/src/core/composer/qgslegendmodel.cpp
trunk/qgis/src/core/composer/qgslegendmodel.h
trunk/qgis/src/ui/qgscomposerlegendwidgetbase.ui
Log:
applied patch from NathanW for ticket #3339
Modified: trunk/qgis/src/app/CMakeLists.txt
===================================================================
--- trunk/qgis/src/app/CMakeLists.txt 2010-12-21 01:27:05 UTC (rev 14950)
+++ trunk/qgis/src/app/CMakeLists.txt 2010-12-21 01:27:40 UTC (rev 14951)
@@ -103,6 +103,7 @@
composer/qgscomposershapewidget.cpp
composer/qgscomposertablewidget.cpp
composer/qgscomposerlegenditemdialog.cpp
+ composer/qgscomposerlegendlayersdialog.cpp
composer/qgscomposerlegendwidget.cpp
composer/qgscompositionwidget.cpp
composer/qgsitempositiondialog.cpp
Added: trunk/qgis/src/app/composer/qgscomposerlegendlayersdialog.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlegendlayersdialog.cpp (rev 0)
+++ trunk/qgis/src/app/composer/qgscomposerlegendlayersdialog.cpp 2010-12-21 01:27:40 UTC (rev 14951)
@@ -0,0 +1,53 @@
+/***************************************************************************
+ qgscomposerlegendlayersdialog.cpp
+ -------------------------------
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "qgscomposerlegendlayersdialog.h"
+
+#include <QStandardItem>
+
+QgsComposerLegendLayersDialog::QgsComposerLegendLayersDialog( QList<QgsMapLayer*> layers, QWidget* parent ): QDialog( parent )
+{
+ setupUi( this );
+
+ QList<QgsMapLayer*>::iterator layerIt = layers.begin();
+ for (; layerIt != layers.end(); ++layerIt )
+ {
+ QListWidgetItem* item = new QListWidgetItem(( *layerIt )->name(), listMapLayers );
+ mItemLayerMap.insert( item, *layerIt );
+ }
+}
+
+QgsComposerLegendLayersDialog::QgsComposerLegendLayersDialog(): QDialog( 0 )
+{
+
+}
+
+QgsComposerLegendLayersDialog::~QgsComposerLegendLayersDialog()
+{
+
+}
+
+QgsMapLayer* QgsComposerLegendLayersDialog::selectedLayer()
+{
+ QListWidgetItem* item = listMapLayers->currentItem();
+ if ( !item )
+ {
+ return 0;
+ }
+
+ QMap<QListWidgetItem*, QgsMapLayer*>::iterator it = mItemLayerMap.find( item );
+ QgsMapLayer* c = 0;
+ c = it.value();
+ return c;
+}
Added: trunk/qgis/src/app/composer/qgscomposerlegendlayersdialog.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlegendlayersdialog.h (rev 0)
+++ trunk/qgis/src/app/composer/qgscomposerlegendlayersdialog.h 2010-12-21 01:27:40 UTC (rev 14951)
@@ -0,0 +1,38 @@
+/***************************************************************************
+ qgscomposerlegenditemdialog.h
+ -----------------------------
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef QGSCOMPOSERLEGENDLAYERSDIALOG_H
+#define QGSCOMPOSERLEGENDLAYERSDIALOG_H
+
+#include "ui_qgscomposerlegendlayersdialogbase.h"
+#include "qgsmaplayer.h"
+
+/** \ingroup MapComposer
+ * A dialog to add new layers to the legend.
+ * */
+class QgsComposerLegendLayersDialog: private Ui::QgsComposerLegendLayersDialogBase, public QDialog
+{
+ public:
+ QgsComposerLegendLayersDialog( QList<QgsMapLayer*> layers, QWidget* parent = 0 );
+ ~QgsComposerLegendLayersDialog();
+ QgsMapLayer* selectedLayer();
+
+ private:
+ QgsComposerLegendLayersDialog(); //forbidden
+
+ /**Stores the relation between items and map layer pointers. */
+ QMap<QListWidgetItem*, QgsMapLayer*> mItemLayerMap;
+};
+
+#endif //QGSCOMPOSERLEGENDITEMDIALOG_H
Modified: trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp 2010-12-21 01:27:05 UTC (rev 14950)
+++ trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp 2010-12-21 01:27:40 UTC (rev 14951)
@@ -18,6 +18,7 @@
#include "qgscomposerlegendwidget.h"
#include "qgscomposerlegend.h"
#include "qgscomposerlegenditemdialog.h"
+#include "qgscomposerlegendlayersdialog.h"
#include "qgscomposeritemwidget.h"
#include <QFontDialog>
@@ -25,11 +26,21 @@
#include "qgisapp.h"
#include "qgsmapcanvas.h"
#include "qgsmaprenderer.h"
+#include "qgsapplication.h"
+#include <QMessageBox>
+
QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): mLegend( legend )
{
setupUi( this );
+ // setup icons
+ mAddToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) );
+ mEditPushButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
+ mRemoveToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );
+ mMoveUpToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyUp.png" ) ) );
+ mMoveDownToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.png" ) ) );
+
//add widget for item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, legend );
toolBox->addItem( itemPropertiesWidget, tr( "Item Options" ) );
@@ -77,7 +88,6 @@
blockSignals( false );
}
-
void QgsComposerLegendWidget::on_mTitleLineEdit_textChanged( const QString& text )
{
if ( mLegend )
@@ -360,6 +370,56 @@
mLegend->endCommand();
}
+void QgsComposerLegendWidget::on_mCheckBoxAutoUpdate_stateChanged ( int state )
+{
+ if ( state == Qt::Checked )
+ {
+ mLegend->model()->setAutoUpdate( true );
+ }
+ else
+ {
+ mLegend->model()->setAutoUpdate( false );
+ }
+}
+
+void QgsComposerLegendWidget::on_mAddToolButton_clicked()
+{
+ if ( !mLegend )
+ {
+ return;
+ }
+
+ QStandardItemModel* itemModel = qobject_cast<QStandardItemModel *>( mItemTreeView->model() );
+ if ( !itemModel )
+ {
+ return;
+ }
+
+ QgisApp* app = QgisApp::instance();
+ if ( !app )
+ {
+ return;
+ }
+
+ QgsMapCanvas* canvas = app->mapCanvas();
+ if ( canvas )
+ {
+ QList<QgsMapLayer*> layers = canvas->layers();
+
+ QgsComposerLegendLayersDialog addDialog( layers );
+ if ( addDialog.exec() == QDialog::Accepted )
+ {
+ QgsMapLayer* layer = addDialog.selectedLayer();
+ if ( layer )
+ {
+ mLegend->beginCommand( "Legend item added" );
+ mLegend->model()->addLayer( layer );
+ mLegend->endCommand();
+ }
+ }
+ }
+}
+
void QgsComposerLegendWidget::on_mRemoveToolButton_clicked()
{
if ( !mLegend )
Modified: trunk/qgis/src/app/composer/qgscomposerlegendwidget.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlegendwidget.h 2010-12-21 01:27:05 UTC (rev 14950)
+++ trunk/qgis/src/app/composer/qgscomposerlegendwidget.h 2010-12-21 01:27:40 UTC (rev 14951)
@@ -50,11 +50,13 @@
void on_mLayerFontButton_clicked();
void on_mItemFontButton_clicked();
void on_mBoxSpaceSpinBox_valueChanged( double d );
+ void on_mCheckBoxAutoUpdate_stateChanged (int state );
//item manipulation
void on_mMoveDownToolButton_clicked();
void on_mMoveUpToolButton_clicked();
void on_mRemoveToolButton_clicked();
+ void on_mAddToolButton_clicked();
void on_mEditPushButton_clicked();
void on_mUpdatePushButton_clicked();
void on_mUpdateAllPushButton_clicked();
Modified: trunk/qgis/src/core/composer/qgslegendmodel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.cpp 2010-12-21 01:27:05 UTC (rev 14950)
+++ trunk/qgis/src/core/composer/qgslegendmodel.cpp 2010-12-21 01:27:40 UTC (rev 14951)
@@ -32,6 +32,7 @@
#include <QDomElement>
#include <QMimeData>
#include <QSettings>
+#include <QMessageBox>
QgsLegendModel::QgsLegendModel(): QStandardItemModel()
{
@@ -40,6 +41,7 @@
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
}
+
setItemPrototype( new QgsComposerSymbolItem() );
QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
@@ -674,3 +676,24 @@
emit layersChanged();
return true;
}
+
+void QgsLegendModel::setAutoUpdate(bool autoUpdate)
+{
+ mAutoUpdate = autoUpdate;
+ if ( autoUpdate )
+ {
+ if ( QgsMapLayerRegistry::instance() )
+ {
+ connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
+ connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
+ }
+ }
+ else
+ {
+ if ( QgsMapLayerRegistry::instance() )
+ {
+ disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
+ disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/qgis/src/core/composer/qgslegendmodel.h
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.h 2010-12-21 01:27:05 UTC (rev 14950)
+++ trunk/qgis/src/core/composer/qgslegendmodel.h 2010-12-21 01:27:40 UTC (rev 14951)
@@ -84,6 +84,8 @@
/**Implements the drop operation*/
bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
+ void setAutoUpdate( bool autoUpdate );
+ bool AutoUpdaet() { return mAutoUpdate; }
public slots:
void removeLayer( const QString& layerId );
@@ -112,6 +114,9 @@
/**True if this application has toplevel windows (normally true). If this is false, this means that the application
might not have a running x-server on unix systems and so QPixmap and QIcon cannot be used*/
bool mHasTopLevelWindow;
+
+ /**True if the legend is auto updated when layers are added or removed from the map canvas */
+ bool mAutoUpdate;
};
#endif
Added: trunk/qgis/src/ui/qgscomposerlegendlayersdialogbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposerlegendlayersdialogbase.ui (rev 0)
+++ trunk/qgis/src/ui/qgscomposerlegendlayersdialogbase.ui 2010-12-21 01:27:40 UTC (rev 14951)
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QgsComposerLegendLayersDialogBase</class>
+ <widget class="QDialog" name="QgsComposerLegendLayersDialogBase">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>252</width>
+ <height>194</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Add layer to legend</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QListWidget" name="listMapLayers"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>QgsComposerLegendLayersDialogBase</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>QgsComposerLegendLayersDialogBase</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
Modified: trunk/qgis/src/ui/qgscomposerlegendwidgetbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposerlegendwidgetbase.ui 2010-12-21 01:27:05 UTC (rev 14950)
+++ trunk/qgis/src/ui/qgscomposerlegendwidgetbase.ui 2010-12-21 01:27:40 UTC (rev 14951)
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>369</width>
- <height>471</height>
+ <width>371</width>
+ <height>476</height>
</rect>
</property>
<property name="sizePolicy">
@@ -33,8 +33,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>367</width>
- <height>469</height>
+ <width>369</width>
+ <height>474</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
@@ -48,8 +48,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>349</width>
- <height>397</height>
+ <width>338</width>
+ <height>404</height>
</rect>
</property>
<attribute name="label">
@@ -183,15 +183,31 @@
<rect>
<x>0</x>
<y>0</y>
- <width>349</width>
- <height>397</height>
+ <width>351</width>
+ <height>394</height>
</rect>
</property>
<attribute name="label">
<string>Legend items</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
- <item row="0" column="0" colspan="7">
+ <item row="0" column="0" colspan="4">
+ <widget class="QCheckBox" name="mCheckBoxAutoUpdate">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Auto Update</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="8">
<widget class="QTreeView" name="mItemTreeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
@@ -199,54 +215,67 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="wordWrap">
+ <bool>false</bool>
+ </property>
<property name="headerHidden">
<bool>true</bool>
</property>
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
</widget>
</item>
- <item row="1" column="0">
+ <item row="2" column="0">
<widget class="QToolButton" name="mMoveDownToolButton">
<property name="text">
- <string>v</string>
+ <string/>
</property>
</widget>
</item>
- <item row="1" column="1">
+ <item row="2" column="1">
<widget class="QToolButton" name="mMoveUpToolButton">
<property name="text">
- <string>^</string>
+ <string/>
</property>
</widget>
</item>
- <item row="1" column="2">
+ <item row="2" column="2">
+ <widget class="QToolButton" name="mAddToolButton">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="3">
<widget class="QToolButton" name="mRemoveToolButton">
<property name="text">
- <string>X</string>
+ <string/>
</property>
</widget>
</item>
- <item row="1" column="3">
+ <item row="2" column="4">
<widget class="QToolButton" name="mEditPushButton">
<property name="text">
- <string>Edit</string>
+ <string/>
</property>
</widget>
</item>
- <item row="1" column="4">
+ <item row="2" column="5">
<widget class="QToolButton" name="mUpdatePushButton">
<property name="text">
<string>Update</string>
</property>
</widget>
</item>
- <item row="1" column="5">
+ <item row="2" column="6">
<widget class="QToolButton" name="mUpdateAllPushButton">
<property name="text">
<string>All</string>
</property>
</widget>
</item>
- <item row="1" column="6">
+ <item row="2" column="7">
<widget class="QToolButton" name="mAddGroupButton">
<property name="text">
<string>Add group</string>
More information about the QGIS-commit
mailing list