Skip to content
Permalink
Browse files
[FEATURE]: A table widget to display feature attributes in the compos…
…er (but it still needs a bit more settings...)

git-svn-id: http://svn.osgeo.org/qgis/trunk@12682 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 6, 2010
1 parent 9268092 commit 80f3eb7f0a2dd1757f02566b97ab6fa74bebf84f
@@ -83,6 +83,7 @@ SET(QGIS_APP_SRCS
composer/qgscomposermapwidget.cpp
composer/qgscomposerscalebarwidget.cpp
composer/qgscomposershapewidget.cpp
composer/qgscomposertablewidget.cpp
composer/qgscomposerlegenditemdialog.cpp
composer/qgscomposerlegendwidget.cpp
composer/qgscompositionwidget.cpp
@@ -184,6 +185,7 @@ SET (QGIS_APP_MOC_HDRS
composer/qgscomposermapwidget.h
composer/qgscomposerpicturewidget.h
composer/qgscomposerscalebarwidget.h
composer/qgscomposertablewidget.h
composer/qgscomposershapewidget.h
composer/qgscompositionwidget.h
composer/qgsitempositiondialog.h
@@ -35,6 +35,8 @@
#include "qgscomposerscalebarwidget.h"
#include "qgscomposershape.h"
#include "qgscomposershapewidget.h"
#include "qgscomposertable.h"
#include "qgscomposertablewidget.h"
#include "qgsexception.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"
@@ -112,6 +114,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
toggleActionGroup->addAction( mActionSelectMoveItem );
toggleActionGroup->addAction( mActionAddBasicShape );
toggleActionGroup->addAction( mActionAddArrow );
toggleActionGroup->addAction( mActionAddTable );
toggleActionGroup->setExclusive( true );

mActionAddNewMap->setCheckable( true );
@@ -160,6 +163,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
layoutMenu->addAction( mActionMoveItemContent );
layoutMenu->addAction( mActionAddBasicShape );
layoutMenu->addAction( mActionAddArrow );
layoutMenu->addAction( mActionAddTable );
layoutMenu->addSeparator();
layoutMenu->addAction( mActionGroupItems );
layoutMenu->addAction( mActionUngroupItems );
@@ -255,6 +259,7 @@ void QgsComposer::setupTheme()
mActionAddNewScalebar->setIcon( QgisApp::getThemeIcon( "/mActionScaleBar.png" ) );
mActionAddBasicShape->setIcon( QgisApp::getThemeIcon( "/mActionAddBasicShape.png" ) );
mActionAddArrow->setIcon( QgisApp::getThemeIcon( "/mActionAddArrow.png" ) );
mActionAddTable->setIcon( QgisApp::getThemeIcon( "/mActionOpenTable.png" ) );
mActionSelectMoveItem->setIcon( QgisApp::getThemeIcon( "/mActionSelectPan.png" ) );
mActionMoveItemContent->setIcon( QgisApp::getThemeIcon( "/mActionMoveItemContent.png" ) );
mActionGroupItems->setIcon( QgisApp::getThemeIcon( "/mActionGroupItems.png" ) );
@@ -282,6 +287,7 @@ void QgsComposer::connectSlots()
connect( mView, SIGNAL( composerPictureAdded( QgsComposerPicture* ) ), this, SLOT( addComposerPicture( QgsComposerPicture* ) ) );
connect( mView, SIGNAL( composerShapeAdded( QgsComposerShape* ) ), this, SLOT( addComposerShape( QgsComposerShape* ) ) );
connect( mView, SIGNAL( composerArrowAdded( QgsComposerArrow* ) ), this, SLOT( addComposerArrow( QgsComposerArrow* ) ) );
connect( mView, SIGNAL( composerTableAdded( QgsComposerTable* ) ), this, SLOT( addComposerTable( QgsComposerTable* ) ) );
connect( mView, SIGNAL( actionFinished() ), this, SLOT( setSelectionTool() ) );
}

@@ -826,6 +832,14 @@ void QgsComposer::on_mActionAddBasicShape_triggered()
}
}

void QgsComposer::on_mActionAddTable_triggered()
{
if ( mView )
{
mView->setCurrentTool( QgsComposerView::AddTable );
}
}

void QgsComposer::on_mActionAddArrow_triggered()
{
if ( mView )
@@ -1260,6 +1274,21 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
showItemOptions( newArrow );
}

//composer tables
QDomNodeList composerTableList = composerElem.elementsByTagName( "ComposerTable" );
for ( int i = 0; i < composerTableList.size(); ++i )
{
QDomElement currentTableElem = composerTableList.at( i ).toElement();
QgsComposerTable* newTable = new QgsComposerTable( mComposition );
newTable->readXML( currentTableElem, doc );
addComposerTable( newTable );
mComposition->addItem( newTable );
mComposition->update();
mComposition->clearSelection();
newTable->setSelected( true );
showItemOptions( newTable );
}

mComposition->sortZList();
mView->setComposition( mComposition );

@@ -1355,6 +1384,16 @@ void QgsComposer::addComposerShape( QgsComposerShape* shape )
mItemWidgetMap.insert( shape, sWidget );
}

void QgsComposer::addComposerTable( QgsComposerTable* table )
{
if ( !table )
{
return;
}
QgsComposerTableWidget* tWidget = new QgsComposerTableWidget( table );
mItemWidgetMap.insert( table, tWidget );
}

void QgsComposer::deleteItem( QgsComposerItem* item )
{
QMap<QgsComposerItem*, QWidget*>::iterator it = mItemWidgetMap.find( item );
@@ -29,6 +29,7 @@ class QgsComposerMap;
class QgsComposerPicture;
class QgsComposerScaleBar;
class QgsComposerShape;
class QgsComposerTable;
class QgsComposerView;
class QgsComposition;
class QgsMapCanvas;
@@ -150,6 +151,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Add ellipse shape item
void on_mActionAddBasicShape_triggered();

//! Add attribute table
void on_mActionAddTable_triggered();

//! Save composer as template
void on_mActionSaveAsTemplate_triggered();

@@ -218,6 +222,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
/**Adds a composer shape to the item/widget map and creates a configuration widget*/
void addComposerShape( QgsComposerShape* shape );

/**Adds a composer table to the item/widget map and creates a configuration widget*/
void addComposerTable( QgsComposerTable* table );

/**Removes item from the item/widget map and deletes the configuration widget*/
void deleteItem( QgsComposerItem* item );

@@ -0,0 +1,214 @@
/***************************************************************************
qgscomposertablewidget.cpp
--------------------------
begin : January 2010
copyright : (C) 2010 by Marco Hugentobler
email : marco at hugis dot net
***************************************************************************/

/***************************************************************************
* *
* 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 "qgscomposertablewidget.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposertable.h"
#include "qgscomposermap.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
#include <QFontDialog>

QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerTable* table ): QWidget( 0 ), mComposerTable( table )
{
setupUi( this );
//add widget for general composer item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, mComposerTable );
mToolBox->addItem( itemPropertiesWidget, tr( "General options" ) );

//insert vector layers into combo
QMap<QString, QgsMapLayer*> layerMap = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::const_iterator mapIt = layerMap.constBegin();

for ( ; mapIt != layerMap.constEnd(); ++mapIt )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mapIt.value() );
if ( vl )
{
mLayerComboBox->addItem( vl->name(), mapIt.key() );
}
}

//insert composer maps into combo
if ( mComposerTable )
{
const QgsComposition* tableComposition = mComposerTable->composition();
if ( tableComposition )
{
QList<const QgsComposerMap*> mapList = tableComposition->composerMapItems();
QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
for ( ; mapIt != mapList.constEnd(); ++mapIt )
{
int mapId = ( *mapIt )->id();
mComposerMapComboBox->addItem( tr( "Map %1" ).arg( mapId ), mapId );
}
}
}

updateGuiElements();
}

QgsComposerTableWidget::~QgsComposerTableWidget()
{

}

void QgsComposerTableWidget::on_mLayerComboBox_currentIndexChanged( int index )
{
if ( !mComposerTable )
{
return;
}

//set new layer to table item
QVariant itemData = mLayerComboBox->itemData( index );
if ( itemData.type() == QVariant::Invalid )
{
return;
}

QString layerId = itemData.toString();
QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
if ( ml )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( ml );
if ( vl )
{
mComposerTable->setVectorLayer( vl );
mComposerTable->update();
}
}
}

void QgsComposerTableWidget::on_mComposerMapComboBox_currentIndexChanged( int index )
{
if ( !mComposerTable )
{
return;
}

QVariant itemData = mComposerMapComboBox->itemData( index );
if ( itemData.type() == QVariant::Invalid )
{
return;
}

int mapId = itemData.toInt();
const QgsComposition* tableComposition = mComposerTable->composition();
if ( tableComposition )
{
mComposerTable->setComposerMap( tableComposition->getComposerMapById( mapId ) );
mComposerTable->update();
}
}

void QgsComposerTableWidget::on_mMaximumColumnsSpinBox_valueChanged( int i )
{
if ( !mComposerTable )
{
return;
}

mComposerTable->setMaximumNumberOfFeatures( i );
mComposerTable->update();
}

void QgsComposerTableWidget::on_mMarginSpinBox_valueChanged( double d )
{
if ( !mComposerTable )
{
return;
}
mComposerTable->setLineTextDistance( d );
mComposerTable->update();
}

void QgsComposerTableWidget::on_mHeaderFontPushButton_clicked()
{
if ( !mComposerTable )
{
return;
}

bool ok;
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->headerFont(), 0, tr( "Select Font" ) );
if ( ok )
{
mComposerTable->setHeaderFont( newFont );
}
}

void QgsComposerTableWidget::on_mContentFontPushButton_clicked()
{
if ( !mComposerTable )
{
return;
}

bool ok;
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->contentFont(), 0, tr( "Select Font" ) );
if ( ok )
{
mComposerTable->setContentFont( newFont );
}
}

void QgsComposerTableWidget::updateGuiElements()
{
if ( !mComposerTable )
{
return;
}

blockAllSignals( true );

//layer combo box
const QgsVectorLayer* vl = mComposerTable->vectorLayer();
if ( vl )
{
int layerIndex = mLayerComboBox->findText( vl->name() );
if ( layerIndex != -1 )
{
mLayerComboBox->setCurrentIndex( layerIndex );
}
}

//map combo box
const QgsComposerMap* cm = mComposerTable->composerMap();
if ( cm )
{
int mapIndex = mComposerMapComboBox->findText( tr( "Map %1" ).arg( cm->id() ) );
if ( mapIndex != -1 )
{
mComposerMapComboBox->setCurrentIndex( mapIndex );
}
}
mMaximumColumnsSpinBox->setValue( mComposerTable->maximumNumberOfFeatures() );
mMarginSpinBox->setValue( mComposerTable->lineTextDistance() );
blockAllSignals( false );
}

void QgsComposerTableWidget::blockAllSignals( bool b )
{
mLayerComboBox->blockSignals( b );
mComposerMapComboBox->blockSignals( b );
mMaximumColumnsSpinBox->blockSignals( b );
mMarginSpinBox->blockSignals( b );
}



0 comments on commit 80f3eb7

Please sign in to comment.