Skip to content

Commit 9152a82

Browse files
author
mhugent
committedApr 15, 2010
Refactor composer table to a base class that has vector attribute table and normal text table as subclasses
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13316 c8812cc2-4d05-0410-92ff-de0c093fc19c

13 files changed

+561
-325
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "qgscomposerscalebarwidget.h"
3636
#include "qgscomposershape.h"
3737
#include "qgscomposershapewidget.h"
38-
#include "qgscomposertable.h"
38+
#include "qgscomposerattributetable.h"
3939
#include "qgscomposertablewidget.h"
4040
#include "qgsexception.h"
4141
#include "qgsproject.h"
@@ -283,7 +283,7 @@ void QgsComposer::connectSlots()
283283
connect( mView, SIGNAL( composerPictureAdded( QgsComposerPicture* ) ), this, SLOT( addComposerPicture( QgsComposerPicture* ) ) );
284284
connect( mView, SIGNAL( composerShapeAdded( QgsComposerShape* ) ), this, SLOT( addComposerShape( QgsComposerShape* ) ) );
285285
connect( mView, SIGNAL( composerArrowAdded( QgsComposerArrow* ) ), this, SLOT( addComposerArrow( QgsComposerArrow* ) ) );
286-
connect( mView, SIGNAL( composerTableAdded( QgsComposerTable* ) ), this, SLOT( addComposerTable( QgsComposerTable* ) ) );
286+
connect( mView, SIGNAL( composerTableAdded( QgsComposerAttributeTable* ) ), this, SLOT( addComposerTable( QgsComposerAttributeTable* ) ) );
287287
connect( mView, SIGNAL( actionFinished() ), this, SLOT( setSelectionTool() ) );
288288
}
289289

@@ -1263,11 +1263,11 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
12631263
}
12641264

12651265
//composer tables
1266-
QDomNodeList composerTableList = composerElem.elementsByTagName( "ComposerTable" );
1266+
QDomNodeList composerTableList = composerElem.elementsByTagName( "ComposerAttributeTable" );
12671267
for ( int i = 0; i < composerTableList.size(); ++i )
12681268
{
12691269
QDomElement currentTableElem = composerTableList.at( i ).toElement();
1270-
QgsComposerTable* newTable = new QgsComposerTable( mComposition );
1270+
QgsComposerAttributeTable* newTable = new QgsComposerAttributeTable( mComposition );
12711271
newTable->readXML( currentTableElem, doc );
12721272
addComposerTable( newTable );
12731273
mComposition->addItem( newTable );
@@ -1373,7 +1373,7 @@ void QgsComposer::addComposerShape( QgsComposerShape* shape )
13731373
mItemWidgetMap.insert( shape, sWidget );
13741374
}
13751375

1376-
void QgsComposer::addComposerTable( QgsComposerTable* table )
1376+
void QgsComposer::addComposerTable( QgsComposerAttributeTable* table )
13771377
{
13781378
if ( !table )
13791379
{

‎src/app/composer/qgscomposer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class QgsComposerMap;
2929
class QgsComposerPicture;
3030
class QgsComposerScaleBar;
3131
class QgsComposerShape;
32-
class QgsComposerTable;
32+
class QgsComposerAttributeTable;
3333
class QgsComposerView;
3434
class QgsComposition;
3535
class QgsMapCanvas;
@@ -223,7 +223,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
223223
void addComposerShape( QgsComposerShape* shape );
224224

225225
/**Adds a composer table to the item/widget map and creates a configuration widget*/
226-
void addComposerTable( QgsComposerTable* table );
226+
void addComposerTable( QgsComposerAttributeTable* table );
227227

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

‎src/app/composer/qgscomposertablewidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
#include "qgscomposertablewidget.h"
1919
#include "qgsattributeselectiondialog.h"
2020
#include "qgscomposeritemwidget.h"
21-
#include "qgscomposertable.h"
21+
#include "qgscomposerattributetable.h"
2222
#include "qgscomposermap.h"
2323
#include "qgsmaplayerregistry.h"
2424
#include "qgsvectorlayer.h"
2525
#include <QColorDialog>
2626
#include <QFontDialog>
2727

28-
QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerTable* table ): QWidget( 0 ), mComposerTable( table )
28+
QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerAttributeTable* table ): QWidget( 0 ), mComposerTable( table )
2929
{
3030
setupUi( this );
3131
//add widget for general composer item properties

‎src/app/composer/qgscomposertablewidget.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020

2121
#include "ui_qgscomposertablewidgetbase.h"
2222

23-
class QgsComposerTable;
23+
class QgsComposerAttributeTable;
2424

2525
class QgsComposerTableWidget: public QWidget, private Ui::QgsComposerTableWidgetBase
2626
{
2727
Q_OBJECT
2828
public:
29-
QgsComposerTableWidget( QgsComposerTable* table );
29+
QgsComposerTableWidget( QgsComposerAttributeTable* table );
3030
~QgsComposerTableWidget();
3131

3232
private:
33-
QgsComposerTable* mComposerTable;
33+
QgsComposerAttributeTable* mComposerTable;
3434

3535
/**Sets the GUI elements to the values of mComposerTable*/
3636
void updateGuiElements();

‎src/core/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ SET(QGIS_CORE_SRCS
9595
composer/qgscomposerpicture.cpp
9696
composer/qgscomposermap.cpp
9797
composer/qgscomposertable.cpp
98+
composer/qgscomposerattributetable.cpp
99+
composer/qgscomposertexttable.cpp
98100
composer/qgscomposerscalebar.cpp
99101
composer/qgscomposershape.cpp
100102
composer/qgslegendmodel.cpp
@@ -238,7 +240,7 @@ SET(QGIS_CORE_MOC_HDRS
238240
composer/qgscomposeritem.h
239241
composer/qgscomposeritemgroup.h
240242
composer/qgscomposershape.h
241-
composer/qgscomposertable.h
243+
composer/qgscomposerattributetable.h
242244
composer/qgscomposition.h
243245

244246
composer/qgslegendmodel.h
Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
/***************************************************************************
2+
qgscomposerattributetable.cpp
3+
-----------------------------
4+
begin : April 2010
5+
copyright : (C) 2010 by Marco Hugentobler
6+
email : marco at hugis dot net
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgscomposerattributetable.h"
19+
#include "qgscomposermap.h"
20+
#include "qgsmaplayerregistry.h"
21+
#include "qgsvectorlayer.h"
22+
23+
QgsComposerAttributeTable::QgsComposerAttributeTable( QgsComposition* composition ): QgsComposerTable( composition ), mVectorLayer( 0 ), mComposerMap( 0 ), \
24+
mMaximumNumberOfFeatures( 5 ), mShowOnlyVisibleFeatures( true )
25+
{
26+
27+
}
28+
29+
QgsComposerAttributeTable::~QgsComposerAttributeTable()
30+
{
31+
32+
}
33+
34+
void QgsComposerAttributeTable::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
35+
{
36+
if ( mComposerMap && mComposerMap->isDrawing() )
37+
{
38+
return;
39+
}
40+
QgsComposerTable::paint( painter, itemStyle, pWidget );
41+
}
42+
43+
void QgsComposerAttributeTable::initializeAliasMap()
44+
{
45+
mFieldAliasMap.clear();
46+
if ( mVectorLayer )
47+
{
48+
QgsFieldMap fieldMap = mVectorLayer->pendingFields();
49+
QgsFieldMap::const_iterator it = fieldMap.constBegin();
50+
for ( ; it != fieldMap.constEnd(); ++it )
51+
{
52+
QString currentAlias = mVectorLayer->attributeAlias( it.key() );
53+
if ( !currentAlias.isEmpty() )
54+
{
55+
mFieldAliasMap.insert( it.key(), currentAlias );
56+
}
57+
}
58+
}
59+
}
60+
61+
void QgsComposerAttributeTable::setVectorLayer( QgsVectorLayer* vl )
62+
{
63+
if ( vl != mVectorLayer )
64+
{
65+
mDisplayAttributes.clear();
66+
mVectorLayer = vl;
67+
initializeAliasMap();
68+
}
69+
}
70+
71+
void QgsComposerAttributeTable::setComposerMap( const QgsComposerMap* map )
72+
{
73+
if ( mComposerMap )
74+
{
75+
QObject::disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) );
76+
}
77+
mComposerMap = map;
78+
if ( mComposerMap )
79+
{
80+
QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) );
81+
}
82+
}
83+
84+
bool QgsComposerAttributeTable::getFeatureAttributes( QList<QgsAttributeMap>& attributes )
85+
{
86+
if ( !mVectorLayer )
87+
{
88+
return false;
89+
}
90+
attributes.clear();
91+
92+
QgsRectangle selectionRect;
93+
if ( mComposerMap && mShowOnlyVisibleFeatures )
94+
{
95+
selectionRect = mComposerMap->extent();
96+
}
97+
98+
if ( mDisplayAttributes.size() < 1 )
99+
{
100+
mVectorLayer->select( mVectorLayer->pendingAllAttributesList(), selectionRect, false, true );
101+
}
102+
else
103+
{
104+
mVectorLayer->select( mDisplayAttributes.toList(), selectionRect, false, true );
105+
}
106+
QgsFeature f;
107+
int counter = 0;
108+
while ( mVectorLayer->nextFeature( f ) && counter < mMaximumNumberOfFeatures )
109+
{
110+
attributes.push_back( f.attributeMap() );
111+
++counter;
112+
}
113+
return true;
114+
}
115+
116+
QMap<int, QString> QgsComposerAttributeTable::getHeaderLabels() const
117+
{
118+
QMap<int, QString> header;
119+
if ( mVectorLayer )
120+
{
121+
QgsFieldMap vectorFields = mVectorLayer->pendingFields();
122+
QgsFieldMap::const_iterator fieldIt = vectorFields.constBegin();
123+
for ( ; fieldIt != vectorFields.constEnd(); ++fieldIt )
124+
{
125+
if ( mDisplayAttributes.size() > 0 && !mDisplayAttributes.contains( fieldIt.key() ) )
126+
{
127+
continue;
128+
}
129+
header.insert( fieldIt.key(), attributeDisplayName( fieldIt.key(), fieldIt.value().name() ) );
130+
}
131+
}
132+
return header;
133+
}
134+
135+
QString QgsComposerAttributeTable::attributeDisplayName( int attributeIndex, const QString& name ) const
136+
{
137+
QMap<int, QString>::const_iterator it = mFieldAliasMap.find( attributeIndex );
138+
if ( it != mFieldAliasMap.constEnd() )
139+
{
140+
return it.value();
141+
}
142+
else
143+
{
144+
return name;
145+
}
146+
}
147+
148+
void QgsComposerAttributeTable::setSceneRect( const QRectF& rectangle )
149+
{
150+
double titleHeight = 2 * mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mHeaderFont );
151+
double attributeHeight = mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mContentFont );
152+
if (( rectangle.height() - titleHeight ) > 0 )
153+
{
154+
mMaximumNumberOfFeatures = ( rectangle.height() - titleHeight ) / attributeHeight;
155+
}
156+
else
157+
{
158+
mMaximumNumberOfFeatures = 0;
159+
}
160+
QgsComposerItem::setSceneRect( rectangle );
161+
emit maximumNumerOfFeaturesChanged( mMaximumNumberOfFeatures );
162+
}
163+
164+
bool QgsComposerAttributeTable::writeXML( QDomElement& elem, QDomDocument & doc ) const
165+
{
166+
QDomElement composerTableElem = doc.createElement( "ComposerAttributeTable" );
167+
composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
168+
169+
if ( mComposerMap )
170+
{
171+
composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
172+
}
173+
else
174+
{
175+
composerTableElem.setAttribute( "composerMap", -1 );
176+
}
177+
if ( mVectorLayer )
178+
{
179+
composerTableElem.setAttribute( "vectorLayer", mVectorLayer->getLayerID() );
180+
}
181+
182+
//display attributes
183+
QDomElement displayAttributesElem = doc.createElement( "displayAttributes" );
184+
QSet<int>::const_iterator attIt = mDisplayAttributes.constBegin();
185+
for ( ; attIt != mDisplayAttributes.constEnd(); ++attIt )
186+
{
187+
QDomElement attributeIndexElem = doc.createElement( "attributeEntry" );
188+
attributeIndexElem.setAttribute( "index", *attIt );
189+
displayAttributesElem.appendChild( attributeIndexElem );
190+
}
191+
composerTableElem.appendChild( displayAttributesElem );
192+
193+
//alias map
194+
QDomElement aliasMapElem = doc.createElement( "attributeAliasMap" );
195+
QMap<int, QString>::const_iterator aliasIt = mFieldAliasMap.constBegin();
196+
for ( ; aliasIt != mFieldAliasMap.constEnd(); ++aliasIt )
197+
{
198+
QDomElement mapEntryElem = doc.createElement( "aliasEntry" );
199+
mapEntryElem.setAttribute( "key", aliasIt.key() );
200+
mapEntryElem.setAttribute( "value", aliasIt.value() );
201+
aliasMapElem.appendChild( mapEntryElem );
202+
}
203+
composerTableElem.appendChild( aliasMapElem );
204+
bool ok = tableWriteXML( composerTableElem, doc );
205+
elem.appendChild( composerTableElem );
206+
return ok;
207+
}
208+
209+
bool QgsComposerAttributeTable::readXML( const QDomElement& itemElem, const QDomDocument& doc )
210+
{
211+
if ( itemElem.isNull() )
212+
{
213+
return false;
214+
}
215+
216+
mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
217+
mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
218+
219+
//composer map
220+
int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
221+
if ( composerMapId == -1 )
222+
{
223+
mComposerMap = 0;
224+
}
225+
226+
if ( composition() )
227+
{
228+
mComposerMap = composition()->getComposerMapById( composerMapId );
229+
}
230+
else
231+
{
232+
mComposerMap = 0;
233+
}
234+
235+
//vector layer
236+
QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
237+
if ( layerId == "not_existing" )
238+
{
239+
mVectorLayer = 0;
240+
}
241+
else
242+
{
243+
QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
244+
if ( ml )
245+
{
246+
mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
247+
}
248+
}
249+
250+
//restore display attribute map
251+
mDisplayAttributes.clear();
252+
QDomNodeList displayAttributeList = itemElem.elementsByTagName( "displayAttributes" );
253+
if ( displayAttributeList.size() > 0 )
254+
{
255+
QDomElement displayAttributesElem = displayAttributeList.at( 0 ).toElement();
256+
QDomNodeList attributeEntryList = displayAttributesElem.elementsByTagName( "attributeEntry" );
257+
for ( int i = 0; i < attributeEntryList.size(); ++i )
258+
{
259+
QDomElement attributeEntryElem = attributeEntryList.at( i ).toElement();
260+
int index = attributeEntryElem.attribute( "index", "-1" ).toInt();
261+
if ( index != -1 )
262+
{
263+
mDisplayAttributes.insert( index );
264+
}
265+
}
266+
}
267+
268+
//restore alias map
269+
mFieldAliasMap.clear();
270+
QDomNodeList aliasMapNodeList = itemElem.elementsByTagName( "attributeAliasMap" );
271+
if ( aliasMapNodeList.size() > 0 )
272+
{
273+
QDomElement attributeAliasMapElem = aliasMapNodeList.at( 0 ).toElement();
274+
QDomNodeList aliasMepEntryList = attributeAliasMapElem.elementsByTagName( "aliasEntry" );
275+
for ( int i = 0; i < aliasMepEntryList.size(); ++i )
276+
{
277+
QDomElement aliasEntryElem = aliasMepEntryList.at( i ).toElement();
278+
int key = aliasEntryElem.attribute( "key", "-1" ).toInt();
279+
QString value = aliasEntryElem.attribute( "value", "" );
280+
mFieldAliasMap.insert( key, value );
281+
}
282+
}
283+
return tableReadXML( itemElem, doc );
284+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/***************************************************************************
2+
qgscomposerattributetable.h
3+
---------------------------
4+
begin : April 2010
5+
copyright : (C) 2010 by Marco Hugentobler
6+
email : marco at hugis dot net
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSCOMPOSERATTRIBUTETABLE_H
19+
#define QGSCOMPOSERATTRIBUTETABLE_H
20+
21+
#include "qgscomposertable.h"
22+
23+
class QgsComposerMap;
24+
class QgsVectorLayer;
25+
26+
/**A table class that displays a vector attribute table*/
27+
class CORE_EXPORT QgsComposerAttributeTable: public QgsComposerTable
28+
{
29+
Q_OBJECT
30+
public:
31+
QgsComposerAttributeTable( QgsComposition* composition );
32+
~QgsComposerAttributeTable();
33+
34+
/** \brief Reimplementation of QCanvasItem::paint*/
35+
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
36+
37+
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
38+
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
39+
40+
void setVectorLayer( QgsVectorLayer* vl );// { mVectorLayer = vl; }
41+
const QgsVectorLayer* vectorLayer() const { return mVectorLayer; }
42+
43+
void setComposerMap( const QgsComposerMap* map );
44+
const QgsComposerMap* composerMap() const { return mComposerMap; }
45+
46+
void setMaximumNumberOfFeatures( int nr ) { mMaximumNumberOfFeatures = nr; }
47+
int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
48+
49+
void setDisplayOnlyVisibleFeatures( bool b ) { mShowOnlyVisibleFeatures = b; }
50+
bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
51+
52+
QSet<int> displayAttributes() const { return mDisplayAttributes; }
53+
void setDisplayAttributes( const QSet<int>& attr ) { mDisplayAttributes = attr;}
54+
55+
QMap<int, QString> fieldAliasMap() const { return mFieldAliasMap; }
56+
void setFieldAliasMap( const QMap<int, QString>& map ) { mFieldAliasMap = map; }
57+
58+
/**Adapts mMaximumNumberOfFeatures depending on the rectangle height*/
59+
void setSceneRect( const QRectF& rectangle );
60+
61+
protected:
62+
/**Retrieves feature attributes*/
63+
bool getFeatureAttributes( QList<QgsAttributeMap>& attributes );
64+
QMap<int, QString> getHeaderLabels() const;
65+
66+
private:
67+
/**Associated vector layer*/
68+
QgsVectorLayer* mVectorLayer;
69+
/**Associated composer map (used to display the visible features)*/
70+
const QgsComposerMap* mComposerMap;
71+
/**Maximum number of features that is displayed*/
72+
int mMaximumNumberOfFeatures;
73+
74+
/**Shows only the features that are visible in the associated composer map (true by default)*/
75+
bool mShowOnlyVisibleFeatures;
76+
77+
/**List of attribute indices to display (or all attributes if list is empty)*/
78+
QSet<int> mDisplayAttributes;
79+
/**Map of attribute name aliases. The aliases might be different to those of QgsVectorLayer (but those from the vector layer are the default)*/
80+
QMap<int, QString> mFieldAliasMap;
81+
82+
/**Inserts aliases from vector layer as starting configuration to the alias map*/
83+
void initializeAliasMap();
84+
/**Returns the attribute name to display in the item (attribute name or an alias if present)*/
85+
QString attributeDisplayName( int attributeIndex, const QString& name ) const;
86+
87+
signals:
88+
/**This signal is emitted if the maximum number of feature changes (interactively)*/
89+
void maximumNumerOfFeaturesChanged( int n );
90+
};
91+
92+
#endif // QGSCOMPOSERATTRIBUTETABLE_H

‎src/core/composer/qgscomposertable.cpp

Lines changed: 28 additions & 254 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@
1616
***************************************************************************/
1717

1818
#include "qgscomposertable.h"
19-
#include "qgscomposermap.h"
2019
#include "qgslogger.h"
21-
#include "qgsmaplayerregistry.h"
22-
#include "qgsvectorlayer.h"
2320
#include <QPainter>
2421

25-
QgsComposerTable::QgsComposerTable( QgsComposition* composition ): QgsComposerItem( composition ), mVectorLayer( 0 ), mComposerMap( 0 ), \
26-
mMaximumNumberOfFeatures( 5 ), mLineTextDistance( 1.0 ), mShowGrid( true ), mGridStrokeWidth( 0.5 ), mGridColor( QColor( 0, 0, 0 ) ), mShowOnlyVisibleFeatures( true )
22+
QgsComposerTable::QgsComposerTable( QgsComposition* composition ): QgsComposerItem( composition ), mLineTextDistance( 1.0 ), mShowGrid( true ), mGridStrokeWidth( 0.5 ), mGridColor( QColor( 0, 0, 0 ) )
2723
{
2824

2925
}
@@ -33,59 +29,13 @@ QgsComposerTable::~QgsComposerTable()
3329

3430
}
3531

36-
void QgsComposerTable::initializeAliasMap()
37-
{
38-
mFieldAliasMap.clear();
39-
if ( mVectorLayer )
40-
{
41-
QgsFieldMap fieldMap = mVectorLayer->pendingFields();
42-
QgsFieldMap::const_iterator it = fieldMap.constBegin();
43-
for ( ; it != fieldMap.constEnd(); ++it )
44-
{
45-
QString currentAlias = mVectorLayer->attributeAlias( it.key() );
46-
if ( !currentAlias.isEmpty() )
47-
{
48-
mFieldAliasMap.insert( it.key(), currentAlias );
49-
}
50-
}
51-
}
52-
}
53-
54-
void QgsComposerTable::setComposerMap( const QgsComposerMap* map )
55-
{
56-
if ( mComposerMap )
57-
{
58-
QObject::disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) );
59-
}
60-
mComposerMap = map;
61-
if ( mComposerMap )
62-
{
63-
QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) );
64-
}
65-
}
66-
67-
void QgsComposerTable::setVectorLayer( QgsVectorLayer* vl )
68-
{
69-
if ( vl != mVectorLayer )
70-
{
71-
mDisplayAttributes.clear();
72-
mVectorLayer = vl;
73-
initializeAliasMap();
74-
}
75-
}
76-
7732
void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
7833
{
7934
if ( !painter )
8035
{
8136
return;
8237
}
8338

84-
if ( mComposerMap && mComposerMap->isDrawing() )
85-
{
86-
return;
87-
}
88-
8939
//getFeatureAttributes
9040
QList<QgsAttributeMap> attributeList;
9141
if ( !getFeatureAttributes( attributeList ) )
@@ -96,7 +46,7 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
9646
QMap<int, double> maxColumnWidthMap;
9747
//check how much space each column needs
9848
calculateMaxColumnWidths( maxColumnWidthMap, attributeList );
99-
//adapt item fram to max width / height
49+
//adapt item frame to max width / height
10050
adaptItemFrame( maxColumnWidthMap, attributeList );
10151

10252
drawBackground( painter );
@@ -105,19 +55,16 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
10555
double currentX = mGridStrokeWidth;
10656
double currentY;
10757

108-
QgsFieldMap vectorFields = mVectorLayer->pendingFields();
109-
QgsFieldMap::const_iterator fieldIt = vectorFields.constBegin();
110-
for ( ; fieldIt != vectorFields.constEnd(); ++fieldIt )
58+
QMap<int, QString> headerMap = getHeaderLabels();
59+
QMap<int, QString>::const_iterator columnIt = headerMap.constBegin();
60+
61+
for ( ; columnIt != headerMap.constEnd(); ++columnIt )
11162
{
112-
if ( mDisplayAttributes.size() > 0 && !mDisplayAttributes.contains( fieldIt.key() ) )
113-
{
114-
continue;
115-
}
11663
currentY = mGridStrokeWidth;
11764
currentY += mLineTextDistance;
11865
currentY += fontAscentMillimeters( mHeaderFont );
11966
currentX += mLineTextDistance;
120-
drawText( painter, currentX, currentY, attributeDisplayName( fieldIt.key(), fieldIt.value().name() ), mHeaderFont );
67+
drawText( painter, currentX, currentY, columnIt.value(), mHeaderFont );
12168

12269
currentY += mLineTextDistance;
12370
currentY += mGridStrokeWidth;
@@ -130,7 +77,7 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
13077
currentY += mLineTextDistance;
13178

13279
QgsAttributeMap currentAttributeMap = *attIt;
133-
QgsAttributeMap::const_iterator attMapIt = currentAttributeMap.find( fieldIt.key() );
80+
QgsAttributeMap::const_iterator attMapIt = currentAttributeMap.find( columnIt.key() );
13481
if ( attMapIt != currentAttributeMap.constEnd() )
13582
{
13683
drawText( painter, currentX, currentY, attMapIt.value().toString(), mContentFont );
@@ -139,7 +86,7 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
13986
currentY += mGridStrokeWidth;
14087
}
14188

142-
currentX += maxColumnWidthMap[fieldIt.key()];
89+
currentX += maxColumnWidthMap[columnIt.key()];
14390
currentX += mLineTextDistance;
14491
currentX += mGridStrokeWidth;
14592
}
@@ -163,146 +110,38 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
163110
}
164111
}
165112

166-
bool QgsComposerTable::writeXML( QDomElement& elem, QDomDocument & doc ) const
113+
bool QgsComposerTable::tableWriteXML( QDomElement& elem, QDomDocument & doc ) const
167114
{
168-
QDomElement composerTableElem = doc.createElement( "ComposerTable" );
169-
composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
170-
composerTableElem.setAttribute( "lineTextDist", mLineTextDistance );
171-
composerTableElem.setAttribute( "headerFont", mHeaderFont.toString() );
172-
composerTableElem.setAttribute( "contentFont", mContentFont.toString() );
173-
composerTableElem.setAttribute( "gridStrokeWidth", mGridStrokeWidth );
174-
composerTableElem.setAttribute( "gridColorRed", mGridColor.red() );
175-
composerTableElem.setAttribute( "gridColorGreen", mGridColor.green() );
176-
composerTableElem.setAttribute( "gridColorBlue", mGridColor.blue() );
177-
composerTableElem.setAttribute( "showGrid", mShowGrid );
178-
composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
179-
180-
if ( mComposerMap )
181-
{
182-
composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
183-
}
184-
else
185-
{
186-
composerTableElem.setAttribute( "composerMap", -1 );
187-
}
188-
if ( mVectorLayer )
189-
{
190-
composerTableElem.setAttribute( "vectorLayer", mVectorLayer->getLayerID() );
191-
}
192-
193-
//display attributes
194-
QDomElement displayAttributesElem = doc.createElement( "displayAttributes" );
195-
QSet<int>::const_iterator attIt = mDisplayAttributes.constBegin();
196-
for ( ; attIt != mDisplayAttributes.constEnd(); ++attIt )
197-
{
198-
QDomElement attributeIndexElem = doc.createElement( "attributeEntry" );
199-
attributeIndexElem.setAttribute( "index", *attIt );
200-
displayAttributesElem.appendChild( attributeIndexElem );
201-
}
202-
composerTableElem.appendChild( displayAttributesElem );
203-
204-
//alias map
205-
QDomElement aliasMapElem = doc.createElement( "attributeAliasMap" );
206-
QMap<int, QString>::const_iterator aliasIt = mFieldAliasMap.constBegin();
207-
for ( ; aliasIt != mFieldAliasMap.constEnd(); ++aliasIt )
208-
{
209-
QDomElement mapEntryElem = doc.createElement( "aliasEntry" );
210-
mapEntryElem.setAttribute( "key", aliasIt.key() );
211-
mapEntryElem.setAttribute( "value", aliasIt.value() );
212-
aliasMapElem.appendChild( mapEntryElem );
213-
}
214-
composerTableElem.appendChild( aliasMapElem );
215-
216-
elem.appendChild( composerTableElem );
217-
return _writeXML( composerTableElem, doc );
115+
elem.setAttribute( "lineTextDist", mLineTextDistance );
116+
elem.setAttribute( "headerFont", mHeaderFont.toString() );
117+
elem.setAttribute( "contentFont", mContentFont.toString() );
118+
elem.setAttribute( "gridStrokeWidth", mGridStrokeWidth );
119+
elem.setAttribute( "gridColorRed", mGridColor.red() );
120+
elem.setAttribute( "gridColorGreen", mGridColor.green() );
121+
elem.setAttribute( "gridColorBlue", mGridColor.blue() );
122+
elem.setAttribute( "showGrid", mShowGrid );
123+
return _writeXML( elem, doc );
218124
}
219125

220-
bool QgsComposerTable::readXML( const QDomElement& itemElem, const QDomDocument& doc )
126+
bool QgsComposerTable::tableReadXML( const QDomElement& itemElem, const QDomDocument& doc )
221127
{
222128
if ( itemElem.isNull() )
223129
{
224130
return false;
225131
}
226132

227-
mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
228133
mHeaderFont.fromString( itemElem.attribute( "headerFont", "" ) );
229134
mContentFont.fromString( itemElem.attribute( "contentFont", "" ) );
230135
mLineTextDistance = itemElem.attribute( "lineTextDist", "1.0" ).toDouble();
231136
mGridStrokeWidth = itemElem.attribute( "gridStrokeWidth", "0.5" ).toDouble();
232137
mShowGrid = itemElem.attribute( "showGrid", "1" ).toInt();
233-
mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
234138

235139
//grid color
236140
int gridRed = itemElem.attribute( "gridColorRed", "0" ).toInt();
237141
int gridGreen = itemElem.attribute( "gridColorGreen", "0" ).toInt();
238142
int gridBlue = itemElem.attribute( "gridColorBlue", "0" ).toInt();
239143
mGridColor = QColor( gridRed, gridGreen, gridBlue );
240144

241-
//composer map
242-
int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
243-
if ( composerMapId == -1 )
244-
{
245-
mComposerMap = 0;
246-
}
247-
248-
if ( composition() )
249-
{
250-
mComposerMap = composition()->getComposerMapById( composerMapId );
251-
}
252-
else
253-
{
254-
mComposerMap = 0;
255-
}
256-
257-
//vector layer
258-
QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
259-
if ( layerId == "not_existing" )
260-
{
261-
mVectorLayer = 0;
262-
}
263-
else
264-
{
265-
QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
266-
if ( ml )
267-
{
268-
mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
269-
}
270-
}
271-
272-
//restore display attribute map
273-
mDisplayAttributes.clear();
274-
QDomNodeList displayAttributeList = itemElem.elementsByTagName( "displayAttributes" );
275-
if ( displayAttributeList.size() > 0 )
276-
{
277-
QDomElement displayAttributesElem = displayAttributeList.at( 0 ).toElement();
278-
QDomNodeList attributeEntryList = displayAttributesElem.elementsByTagName( "attributeEntry" );
279-
for ( int i = 0; i < attributeEntryList.size(); ++i )
280-
{
281-
QDomElement attributeEntryElem = attributeEntryList.at( i ).toElement();
282-
int index = attributeEntryElem.attribute( "index", "-1" ).toInt();
283-
if ( index != -1 )
284-
{
285-
mDisplayAttributes.insert( index );
286-
}
287-
}
288-
}
289-
290-
//restore alias map
291-
mFieldAliasMap.clear();
292-
QDomNodeList aliasMapNodeList = itemElem.elementsByTagName( "attributeAliasMap" );
293-
if ( aliasMapNodeList.size() > 0 )
294-
{
295-
QDomElement attributeAliasMapElem = aliasMapNodeList.at( 0 ).toElement();
296-
QDomNodeList aliasMepEntryList = attributeAliasMapElem.elementsByTagName( "aliasEntry" );
297-
for ( int i = 0; i < aliasMepEntryList.size(); ++i )
298-
{
299-
QDomElement aliasEntryElem = aliasMepEntryList.at( i ).toElement();
300-
int key = aliasEntryElem.attribute( "key", "-1" ).toInt();
301-
QString value = aliasEntryElem.attribute( "value", "" );
302-
mFieldAliasMap.insert( key, value );
303-
}
304-
}
305-
306145
//restore general composer item properties
307146
QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
308147
if ( composerItemList.size() > 0 )
@@ -313,56 +152,14 @@ bool QgsComposerTable::readXML( const QDomElement& itemElem, const QDomDocument&
313152
return true;
314153
}
315154

316-
bool QgsComposerTable::getFeatureAttributes( QList<QgsAttributeMap>& attributes )
317-
{
318-
if ( !mVectorLayer )
319-
{
320-
return false;
321-
}
322-
attributes.clear();
323-
324-
QgsRectangle selectionRect;
325-
if ( mComposerMap && mShowOnlyVisibleFeatures )
326-
{
327-
selectionRect = mComposerMap->extent();
328-
}
329-
330-
if ( mDisplayAttributes.size() < 1 )
331-
{
332-
mVectorLayer->select( mVectorLayer->pendingAllAttributesList(), selectionRect, false, true );
333-
}
334-
else
335-
{
336-
mVectorLayer->select( mDisplayAttributes.toList(), selectionRect, false, true );
337-
}
338-
QgsFeature f;
339-
int counter = 0;
340-
while ( mVectorLayer->nextFeature( f ) && counter < mMaximumNumberOfFeatures )
341-
{
342-
attributes.push_back( f.attributeMap() );
343-
++counter;
344-
}
345-
return true;
346-
}
347-
348155
bool QgsComposerTable::calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList ) const
349156
{
350157
maxWidthMap.clear();
351-
if ( !mVectorLayer )
352-
{
353-
return false;
354-
}
355-
356-
QgsFieldMap vectorFields = mVectorLayer->pendingFields();
357-
358-
//initialize max width map with attribute names
359-
QgsFieldMap::const_iterator fieldIt = vectorFields.constBegin();
360-
for ( ; fieldIt != vectorFields.constEnd(); ++fieldIt )
158+
QMap<int, QString> headerMap = getHeaderLabels();
159+
QMap<int, QString>::const_iterator headerIt = headerMap.constBegin();
160+
for ( ; headerIt != headerMap.constEnd(); ++headerIt )
361161
{
362-
if ( mDisplayAttributes.size() < 1 || mDisplayAttributes.contains( fieldIt.key() ) )
363-
{
364-
maxWidthMap.insert( fieldIt.key(), textWidthMillimeters( mHeaderFont, attributeDisplayName( fieldIt.key(), fieldIt.value().name() ) ) );
365-
}
162+
maxWidthMap.insert( headerIt.key(), textWidthMillimeters( mHeaderFont, headerIt.value() ) );
366163
}
367164

368165
//go through all the attributes and adapt the max width values
@@ -387,6 +184,10 @@ bool QgsComposerTable::calculateMaxColumnWidths( QMap<int, double>& maxWidthMap,
387184
return true;
388185
}
389186

187+
188+
189+
190+
390191
void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList )
391192
{
392193
//calculate height
@@ -439,32 +240,5 @@ void QgsComposerTable::drawVerticalGridLines( QPainter* p, const QMap<int, doubl
439240
}
440241
}
441242

442-
QString QgsComposerTable::attributeDisplayName( int attributeIndex, const QString& name ) const
443-
{
444-
QMap<int, QString>::const_iterator it = mFieldAliasMap.find( attributeIndex );
445-
if ( it != mFieldAliasMap.constEnd() )
446-
{
447-
return it.value();
448-
}
449-
else
450-
{
451-
return name;
452-
}
453-
}
454243

455-
void QgsComposerTable::setSceneRect( const QRectF& rectangle )
456-
{
457-
double titleHeight = 2 * mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mHeaderFont );
458-
double attributeHeight = mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mContentFont );
459-
if (( rectangle.height() - titleHeight ) > 0 )
460-
{
461-
mMaximumNumberOfFeatures = ( rectangle.height() - titleHeight ) / attributeHeight;
462-
}
463-
else
464-
{
465-
mMaximumNumberOfFeatures = 0;
466-
}
467-
QgsComposerItem::setSceneRect( rectangle );
468-
emit maximumNumerOfFeaturesChanged( mMaximumNumberOfFeatures );
469-
}
470244

‎src/core/composer/qgscomposertable.h

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,20 @@
2222
#include "qgsfeature.h"
2323
#include <QSet>
2424

25-
class QgsComposerMap;
26-
class QgsVectorLayer;
25+
2726

2827
/**A class to display feature attributes in the print composer*/
2928
class CORE_EXPORT QgsComposerTable: public QgsComposerItem
3029
{
31-
Q_OBJECT
3230
public:
3331
QgsComposerTable( QgsComposition* composition );
34-
~QgsComposerTable();
32+
virtual ~QgsComposerTable();
3533

3634
/** \brief Reimplementation of QCanvasItem::paint*/
37-
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
38-
39-
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
40-
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
41-
42-
void setVectorLayer( QgsVectorLayer* vl );// { mVectorLayer = vl; }
43-
const QgsVectorLayer* vectorLayer() const { return mVectorLayer; }
35+
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
4436

45-
void setComposerMap( const QgsComposerMap* map );
46-
const QgsComposerMap* composerMap() const { return mComposerMap; }
47-
48-
void setMaximumNumberOfFeatures( int nr ) { mMaximumNumberOfFeatures = nr; }
49-
int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
37+
virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0;
38+
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) = 0;
5039

5140
void setLineTextDistance( double d ) { mLineTextDistance = d; }
5241
double lineTextDistance() const { return mLineTextDistance; }
@@ -66,25 +55,7 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem
6655
void setGridColor( const QColor& c ) { mGridColor = c; }
6756
QColor gridColor() const { return mGridColor; }
6857

69-
void setDisplayOnlyVisibleFeatures( bool b ) { mShowOnlyVisibleFeatures = b; }
70-
bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
71-
72-
QSet<int> displayAttributes() const { return mDisplayAttributes; }
73-
void setDisplayAttributes( const QSet<int>& attr ) { mDisplayAttributes = attr;}
74-
75-
QMap<int, QString> fieldAliasMap() const { return mFieldAliasMap; }
76-
void setFieldAliasMap( const QMap<int, QString>& map ) { mFieldAliasMap = map; }
77-
78-
/**Adapts mMaximumNumberOfFeatures depending on the rectangle height*/
79-
void setSceneRect( const QRectF& rectangle );
80-
81-
private:
82-
/**Associated vector layer*/
83-
QgsVectorLayer* mVectorLayer;
84-
/**Associated composer map (used to display the visible features)*/
85-
const QgsComposerMap* mComposerMap;
86-
/**Maximum number of features that is displayed*/
87-
int mMaximumNumberOfFeatures;
58+
protected:
8859
/**Distance between table lines and text*/
8960
double mLineTextDistance;
9061

@@ -94,30 +65,19 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem
9465
bool mShowGrid;
9566
double mGridStrokeWidth;
9667
QColor mGridColor;
97-
/**Shows only the features that are visible in the associated composer map (true by default)*/
98-
bool mShowOnlyVisibleFeatures;
99-
100-
/**List of attribute indices to display (or all attributes if list is empty)*/
101-
QSet<int> mDisplayAttributes;
102-
/**Map of attribute name aliases. The aliases might be different to those of QgsVectorLayer (but those from the vector layer are the default)*/
103-
QMap<int, QString> mFieldAliasMap;
10468

10569
/**Retrieves feature attributes*/
106-
bool getFeatureAttributes( QList<QgsAttributeMap>& attributes );
70+
virtual bool getFeatureAttributes( QList<QgsAttributeMap>& attributes ) = 0;
71+
virtual QMap<int, QString> getHeaderLabels() const = 0;
10772
/**Calculate the maximum width values of the vector attributes*/
108-
bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList ) const;
73+
virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList ) const;
10974
/**Adapts the size of the item frame to match the content*/
11075
void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList );
11176
void drawHorizontalGridLines( QPainter* p, int nAttributes );
11277
void drawVerticalGridLines( QPainter* p, const QMap<int, double>& maxWidthMap );
113-
/**Inserts aliases from vector layer as starting configuration to the alias map*/
114-
void initializeAliasMap();
115-
/**Returns the attribute name to display in the item (attribute name or an alias if present)*/
116-
QString attributeDisplayName( int attributeIndex, const QString& name ) const;
117-
118-
signals:
119-
/**This signal is emitted if the maximum number of feature changes (interactively)*/
120-
void maximumNumerOfFeaturesChanged( int n );
78+
79+
bool tableWriteXML( QDomElement& itemElem, QDomDocument& doc ) const;
80+
bool tableReadXML( const QDomElement& itemElem, const QDomDocument& doc );
12181
};
12282

12383
#endif // QGSCOMPOSERTABLE_H
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/***************************************************************************
2+
qgscomposertexttable.h
3+
----------------------
4+
begin : April 2010
5+
copyright : (C) 2010 by Marco Hugentobler
6+
email : marco at hugis dot net
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgscomposertexttable.h"
19+
20+
QgsComposerTextTable::QgsComposerTextTable( QgsComposition* c ): QgsComposerTable( c )
21+
{
22+
23+
}
24+
25+
QgsComposerTextTable::~QgsComposerTextTable()
26+
{
27+
28+
}
29+
30+
bool QgsComposerTextTable::writeXML( QDomElement& elem, QDomDocument & doc ) const
31+
{
32+
QDomElement composerTableElem = doc.createElement( "ComposerTextTable" );
33+
//todo: write headers and text entries
34+
bool ok = _writeXML( composerTableElem , doc );
35+
elem.appendChild( composerTableElem );
36+
return ok;
37+
}
38+
39+
bool QgsComposerTextTable::readXML( const QDomElement& itemElem, const QDomDocument& doc )
40+
{
41+
//todo: read headers and text entries
42+
return tableReadXML( itemElem, doc );
43+
}
44+
45+
bool QgsComposerTextTable::getFeatureAttributes( QList<QgsAttributeMap>& attributes )
46+
{
47+
attributes.clear();
48+
49+
QList< QStringList >::const_iterator rowIt = mRowText.constBegin();
50+
QStringList currentStringList;
51+
for ( ; rowIt != mRowText.constEnd(); ++rowIt )
52+
{
53+
currentStringList = *rowIt;
54+
QgsAttributeMap map;
55+
for ( int i = 0; i < currentStringList.size(); ++i )
56+
{
57+
map.insert( i, QVariant( currentStringList.at( i ) ) );
58+
}
59+
attributes.append( map );
60+
}
61+
return true;
62+
}
63+
64+
QMap<int, QString> QgsComposerTextTable::getHeaderLabels() const
65+
{
66+
QMap<int, QString> header;
67+
QStringList::const_iterator it = mHeaderLabels.constBegin();
68+
int index = 0;
69+
for ( ; it != mHeaderLabels.constEnd(); ++it )
70+
{
71+
header.insert( index, *it );
72+
++index;
73+
}
74+
return header;
75+
}
76+
77+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/***************************************************************************
2+
qgscomposertexttable.h
3+
----------------------
4+
begin : April 2010
5+
copyright : (C) 2010 by Marco Hugentobler
6+
email : marco at hugis dot net
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSCOMPOSERTEXTTABLE_H
19+
#define QGSCOMPOSERTEXTTABLE_H
20+
21+
#include "qgscomposertable.h"
22+
23+
/**A text table item that reads text from string lists*/
24+
class CORE_EXPORT QgsComposerTextTable: public QgsComposerTable
25+
{
26+
public:
27+
QgsComposerTextTable( QgsComposition* c );
28+
~QgsComposerTextTable();
29+
30+
void setHeaderLabels( const QStringList& l ) { mHeaderLabels = l; }
31+
void addRow( const QStringList& row ) { mRowText.append( row ); }
32+
33+
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
34+
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
35+
36+
protected:
37+
bool getFeatureAttributes( QList<QgsAttributeMap>& attributes );
38+
QMap<int, QString> getHeaderLabels() const;
39+
40+
private:
41+
/**Column titles*/
42+
QStringList mHeaderLabels;
43+
/**One stringlist per row*/
44+
QList< QStringList > mRowText;
45+
};
46+
47+
#endif // QGSCOMPOSERTEXTTABLE_H

‎src/gui/qgscomposerview.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "qgscomposerpicture.h"
2929
#include "qgscomposerscalebar.h"
3030
#include "qgscomposershape.h"
31-
#include "qgscomposertable.h"
31+
#include "qgscomposerattributetable.h"
3232

3333
QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags f ) :
3434
QGraphicsView( parent ), mShiftKeyPressed( false ), mRubberBandItem( 0 ), mRubberBandLineItem( 0 ), mMoveContentItem( 0 )
@@ -162,7 +162,7 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
162162
}
163163
case AddTable:
164164
{
165-
QgsComposerTable* newTable = new QgsComposerTable( composition() );
165+
QgsComposerAttributeTable* newTable = new QgsComposerAttributeTable( composition() );
166166
addComposerTable( newTable );
167167
newTable->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 50, 50 ) );
168168
emit actionFinished();
@@ -541,7 +541,7 @@ void QgsComposerView::addComposerShape( QgsComposerShape* shape )
541541
emit selectedItemChanged( shape );
542542
}
543543

544-
void QgsComposerView::addComposerTable( QgsComposerTable* table )
544+
void QgsComposerView::addComposerTable( QgsComposerAttributeTable* table )
545545
{
546546
scene()->addItem( table );
547547
emit composerTableAdded( table );

‎src/gui/qgscomposerview.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QgsComposerMap;
3232
class QgsComposerPicture;
3333
class QgsComposerScaleBar;
3434
class QgsComposerShape;
35-
class QgsComposerTable;
35+
class QgsComposerAttributeTable;
3636

3737
/** \ingroup MapComposer
3838
* \ingroup gui
@@ -93,7 +93,7 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
9393
/**Adds a composer shape to the graphics scene and advices composer to create a widget for it (through signal)*/
9494
void addComposerShape( QgsComposerShape* shape );
9595
/**Adds a composer table to the graphics scene and advices composer to create a widget for it (through signal)*/
96-
void addComposerTable( QgsComposerTable* table );
96+
void addComposerTable( QgsComposerAttributeTable* table );
9797

9898
/**Returns the composer main window*/
9999
QMainWindow* composerWindow();
@@ -147,7 +147,7 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
147147
/**Is emitted when a new composer shape has been added*/
148148
void composerShapeAdded( QgsComposerShape* shape );
149149
/**Is emitted when a new composer table has been added*/
150-
void composerTableAdded( QgsComposerTable* table );
150+
void composerTableAdded( QgsComposerAttributeTable* table );
151151
/**Is emitted when a composer item has been removed from the scene*/
152152
void itemRemoved( QgsComposerItem* );
153153
/**Current action (e.g. adding composer map) has been finished. The purpose of this signal is that

0 commit comments

Comments
 (0)
Please sign in to comment.