|
| 1 | +/*************************************************************************** |
| 2 | + qgscomposertablewidget.cpp |
| 3 | + -------------------------- |
| 4 | + begin : January 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 "qgscomposertablewidget.h" |
| 19 | +#include "qgscomposeritemwidget.h" |
| 20 | +#include "qgscomposertable.h" |
| 21 | +#include "qgscomposermap.h" |
| 22 | +#include "qgsmaplayerregistry.h" |
| 23 | +#include "qgsvectorlayer.h" |
| 24 | +#include <QFontDialog> |
| 25 | + |
| 26 | +QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerTable* table ): QWidget( 0 ), mComposerTable( table ) |
| 27 | +{ |
| 28 | + setupUi( this ); |
| 29 | + //add widget for general composer item properties |
| 30 | + QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, mComposerTable ); |
| 31 | + mToolBox->addItem( itemPropertiesWidget, tr( "General options" ) ); |
| 32 | + |
| 33 | + //insert vector layers into combo |
| 34 | + QMap<QString, QgsMapLayer*> layerMap = QgsMapLayerRegistry::instance()->mapLayers(); |
| 35 | + QMap<QString, QgsMapLayer*>::const_iterator mapIt = layerMap.constBegin(); |
| 36 | + |
| 37 | + for ( ; mapIt != layerMap.constEnd(); ++mapIt ) |
| 38 | + { |
| 39 | + QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mapIt.value() ); |
| 40 | + if ( vl ) |
| 41 | + { |
| 42 | + mLayerComboBox->addItem( vl->name(), mapIt.key() ); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + //insert composer maps into combo |
| 47 | + if ( mComposerTable ) |
| 48 | + { |
| 49 | + const QgsComposition* tableComposition = mComposerTable->composition(); |
| 50 | + if ( tableComposition ) |
| 51 | + { |
| 52 | + QList<const QgsComposerMap*> mapList = tableComposition->composerMapItems(); |
| 53 | + QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin(); |
| 54 | + for ( ; mapIt != mapList.constEnd(); ++mapIt ) |
| 55 | + { |
| 56 | + int mapId = ( *mapIt )->id(); |
| 57 | + mComposerMapComboBox->addItem( tr( "Map %1" ).arg( mapId ), mapId ); |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + updateGuiElements(); |
| 63 | +} |
| 64 | + |
| 65 | +QgsComposerTableWidget::~QgsComposerTableWidget() |
| 66 | +{ |
| 67 | + |
| 68 | +} |
| 69 | + |
| 70 | +void QgsComposerTableWidget::on_mLayerComboBox_currentIndexChanged( int index ) |
| 71 | +{ |
| 72 | + if ( !mComposerTable ) |
| 73 | + { |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + //set new layer to table item |
| 78 | + QVariant itemData = mLayerComboBox->itemData( index ); |
| 79 | + if ( itemData.type() == QVariant::Invalid ) |
| 80 | + { |
| 81 | + return; |
| 82 | + } |
| 83 | + |
| 84 | + QString layerId = itemData.toString(); |
| 85 | + QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerId ); |
| 86 | + if ( ml ) |
| 87 | + { |
| 88 | + QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( ml ); |
| 89 | + if ( vl ) |
| 90 | + { |
| 91 | + mComposerTable->setVectorLayer( vl ); |
| 92 | + mComposerTable->update(); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +void QgsComposerTableWidget::on_mComposerMapComboBox_currentIndexChanged( int index ) |
| 98 | +{ |
| 99 | + if ( !mComposerTable ) |
| 100 | + { |
| 101 | + return; |
| 102 | + } |
| 103 | + |
| 104 | + QVariant itemData = mComposerMapComboBox->itemData( index ); |
| 105 | + if ( itemData.type() == QVariant::Invalid ) |
| 106 | + { |
| 107 | + return; |
| 108 | + } |
| 109 | + |
| 110 | + int mapId = itemData.toInt(); |
| 111 | + const QgsComposition* tableComposition = mComposerTable->composition(); |
| 112 | + if ( tableComposition ) |
| 113 | + { |
| 114 | + mComposerTable->setComposerMap( tableComposition->getComposerMapById( mapId ) ); |
| 115 | + mComposerTable->update(); |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +void QgsComposerTableWidget::on_mMaximumColumnsSpinBox_valueChanged( int i ) |
| 120 | +{ |
| 121 | + if ( !mComposerTable ) |
| 122 | + { |
| 123 | + return; |
| 124 | + } |
| 125 | + |
| 126 | + mComposerTable->setMaximumNumberOfFeatures( i ); |
| 127 | + mComposerTable->update(); |
| 128 | +} |
| 129 | + |
| 130 | +void QgsComposerTableWidget::on_mMarginSpinBox_valueChanged( double d ) |
| 131 | +{ |
| 132 | + if ( !mComposerTable ) |
| 133 | + { |
| 134 | + return; |
| 135 | + } |
| 136 | + mComposerTable->setLineTextDistance( d ); |
| 137 | + mComposerTable->update(); |
| 138 | +} |
| 139 | + |
| 140 | +void QgsComposerTableWidget::on_mHeaderFontPushButton_clicked() |
| 141 | +{ |
| 142 | + if ( !mComposerTable ) |
| 143 | + { |
| 144 | + return; |
| 145 | + } |
| 146 | + |
| 147 | + bool ok; |
| 148 | + QFont newFont = QFontDialog::getFont( &ok, mComposerTable->headerFont(), 0, tr( "Select Font" ) ); |
| 149 | + if ( ok ) |
| 150 | + { |
| 151 | + mComposerTable->setHeaderFont( newFont ); |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | +void QgsComposerTableWidget::on_mContentFontPushButton_clicked() |
| 156 | +{ |
| 157 | + if ( !mComposerTable ) |
| 158 | + { |
| 159 | + return; |
| 160 | + } |
| 161 | + |
| 162 | + bool ok; |
| 163 | + QFont newFont = QFontDialog::getFont( &ok, mComposerTable->contentFont(), 0, tr( "Select Font" ) ); |
| 164 | + if ( ok ) |
| 165 | + { |
| 166 | + mComposerTable->setContentFont( newFont ); |
| 167 | + } |
| 168 | +} |
| 169 | + |
| 170 | +void QgsComposerTableWidget::updateGuiElements() |
| 171 | +{ |
| 172 | + if ( !mComposerTable ) |
| 173 | + { |
| 174 | + return; |
| 175 | + } |
| 176 | + |
| 177 | + blockAllSignals( true ); |
| 178 | + |
| 179 | + //layer combo box |
| 180 | + const QgsVectorLayer* vl = mComposerTable->vectorLayer(); |
| 181 | + if ( vl ) |
| 182 | + { |
| 183 | + int layerIndex = mLayerComboBox->findText( vl->name() ); |
| 184 | + if ( layerIndex != -1 ) |
| 185 | + { |
| 186 | + mLayerComboBox->setCurrentIndex( layerIndex ); |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + //map combo box |
| 191 | + const QgsComposerMap* cm = mComposerTable->composerMap(); |
| 192 | + if ( cm ) |
| 193 | + { |
| 194 | + int mapIndex = mComposerMapComboBox->findText( tr( "Map %1" ).arg( cm->id() ) ); |
| 195 | + if ( mapIndex != -1 ) |
| 196 | + { |
| 197 | + mComposerMapComboBox->setCurrentIndex( mapIndex ); |
| 198 | + } |
| 199 | + } |
| 200 | + mMaximumColumnsSpinBox->setValue( mComposerTable->maximumNumberOfFeatures() ); |
| 201 | + mMarginSpinBox->setValue( mComposerTable->lineTextDistance() ); |
| 202 | + blockAllSignals( false ); |
| 203 | +} |
| 204 | + |
| 205 | +void QgsComposerTableWidget::blockAllSignals( bool b ) |
| 206 | +{ |
| 207 | + mLayerComboBox->blockSignals( b ); |
| 208 | + mComposerMapComboBox->blockSignals( b ); |
| 209 | + mMaximumColumnsSpinBox->blockSignals( b ); |
| 210 | + mMarginSpinBox->blockSignals( b ); |
| 211 | +} |
| 212 | + |
| 213 | + |
| 214 | + |
0 commit comments