Skip to content

Commit

Permalink
[FEATURE] add american paper format to composer and allow custom form…
Browse files Browse the repository at this point in the history
…ats in inch (fixed #1538 and #1858)

git-svn-id: http://svn.osgeo.org/qgis/trunk@11235 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jul 31, 2009
1 parent 39f5f2d commit 897886a
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 60 deletions.
181 changes: 121 additions & 60 deletions src/app/composer/qgscompositionwidget.cpp
Expand Up @@ -25,9 +25,9 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
setupUi( this ); setupUi( this );
createPaperEntries(); createPaperEntries();


//unit (only mm at the moment, therefore disabled) //unit
mPaperUnitsComboBox->addItem( "mm" ); mPaperUnitsComboBox->addItem( tr( "mm" ) );
mPaperUnitsComboBox->setEnabled( false ); mPaperUnitsComboBox->addItem( tr( "inch" ) );


//orientation //orientation
mPaperOrientationComboBox->blockSignals( true ); mPaperOrientationComboBox->blockSignals( true );
Expand Down Expand Up @@ -112,36 +112,44 @@ QgsCompositionWidget::~QgsCompositionWidget()


void QgsCompositionWidget::createPaperEntries() void QgsCompositionWidget::createPaperEntries()
{ {
QList<QgsCompositionPaper> formats;

formats
<< QgsCompositionPaper( tr( "A5 (148x210 mm)" ), 148, 210 )
<< QgsCompositionPaper( tr( "A4 (210x297 mm)" ), 210, 297 )
<< QgsCompositionPaper( tr( "A3 (297x420 mm)" ), 297, 420 )
<< QgsCompositionPaper( tr( "A2 (420x594 mm)" ), 420, 594 )
<< QgsCompositionPaper( tr( "A1 (594x841 mm)" ), 594, 841 )
<< QgsCompositionPaper( tr( "A0 (841x1189 mm)" ), 841, 1189 )
<< QgsCompositionPaper( tr( "B5 (176 x 250 mm)" ), 176, 250 )
<< QgsCompositionPaper( tr( "B4 (250 x 353 mm)" ), 250, 353 )
<< QgsCompositionPaper( tr( "B3 (353 x 500 mm)" ), 353, 500 )
<< QgsCompositionPaper( tr( "B2 (500 x 707 mm)" ), 500, 707 )
<< QgsCompositionPaper( tr( "B1 (707 x 1000 mm)" ), 707, 1000 )
<< QgsCompositionPaper( tr( "B0 (1000 x 1414 mm)" ), 1000, 1414 )
<< QgsCompositionPaper( tr( "Legal (8.5x14 inches)" ), 216, 356 )
<< QgsCompositionPaper( tr( "ANSI A (Letter; 8.5x11 inches)" ), 216, 279 )
<< QgsCompositionPaper( tr( "ANSI B (Tabloid; 11x17 inches)" ), 279, 432 )
<< QgsCompositionPaper( tr( "ANSI C (17x22 inches)" ), 432, 559 )
<< QgsCompositionPaper( tr( "ANSI D (22x34 inches)" ), 559, 864 )
<< QgsCompositionPaper( tr( "ANSI E (34x44 inches)" ), 864, 1118 )
<< QgsCompositionPaper( tr( "Arch A (9x12 inches)" ), 229, 305 )
<< QgsCompositionPaper( tr( "Arch B (12x18 inches)" ), 305, 457 )
<< QgsCompositionPaper( tr( "Arch C (18x24 inches)" ), 457, 610 )
<< QgsCompositionPaper( tr( "Arch D (24x36 inches)" ), 610, 914 )
<< QgsCompositionPaper( tr( "Arch E (36x48 inches)" ), 914, 1219 )
<< QgsCompositionPaper( tr( "Arch E1 (30x42 inches)" ), 762, 1067 )
;

mPaperSizeComboBox->blockSignals( true ); mPaperSizeComboBox->blockSignals( true );
mPaperSizeComboBox->insertItem( 0, tr( "Custom" ) ); mPaperSizeComboBox->addItem( tr( "Custom" ) );
mPaperMap.insert( tr( "A5 (148x210 mm)" ), QgsCompositionPaper( tr( "A5 (148x210 mm)" ), 148, 210 ) );
mPaperSizeComboBox->insertItem( 1, tr( "A5 (148x210 mm)" ) ); for ( QList<QgsCompositionPaper>::const_iterator it = formats.begin(); it != formats.end(); it++ )
mPaperMap.insert( tr( "A4 (210x297 mm)" ), QgsCompositionPaper( tr( "A4 (210x297 mm)" ), 210, 297 ) ); {
mPaperSizeComboBox->insertItem( 2, tr( "A4 (210x297 mm)" ) ); mPaperSizeComboBox->addItem( it->mName );
mPaperMap.insert( tr( "A3 (297x420 mm)" ), QgsCompositionPaper( tr( "A3 (297x420 mm)" ), 297, 420 ) ); mPaperMap.insert( it->mName, *it );
mPaperSizeComboBox->insertItem( 3, tr( "A3 (297x420 mm)" ) ); }
mPaperMap.insert( tr( "A2 (420x594 mm)" ), QgsCompositionPaper( tr( "A2 (420x594 mm)" ), 420, 594 ) );
mPaperSizeComboBox->insertItem( 4, tr( "A2 (420x594 mm)" ) );
mPaperMap.insert( tr( "A1 (594x841 mm)" ), QgsCompositionPaper( tr( "A1 (594x841 mm)" ), 594, 841 ) );
mPaperSizeComboBox->insertItem( 5, tr( "A1 (594x841 mm)" ) );
mPaperMap.insert( tr( "A0 (841x1189 mm)" ), QgsCompositionPaper( tr( "A0 (841x1189 mm)" ), 841, 1189 ) );
mPaperSizeComboBox->insertItem( 6, tr( "A0 (841x1189 mm)" ) );
mPaperMap.insert( tr( "B5 (176 x 250 mm)" ), QgsCompositionPaper( tr( "B5 (176 x 250 mm)" ), 176, 250 ) );
mPaperSizeComboBox->insertItem( 7, tr( "B5 (176 x 250 mm)" ) );
mPaperMap.insert( tr( "B4 (250 x 353 mm)" ), QgsCompositionPaper( tr( "B4 (250 x 353 mm)" ), 250, 353 ) );
mPaperSizeComboBox->insertItem( 8, tr( "B4 (250 x 353 mm)" ) );
mPaperMap.insert( tr( "B3 (353 x 500 mm)" ), QgsCompositionPaper( tr( "B3 (353 x 500 mm)" ), 353, 500 ) );
mPaperSizeComboBox->insertItem( 9, tr( "B3 (353 x 500 mm)" ) );
mPaperMap.insert( tr( "B2 (500 x 707 mm)" ), QgsCompositionPaper( tr( "B2 (500 x 707 mm)" ), 500, 707 ) );
mPaperSizeComboBox->insertItem( 10, tr( "B2 (500 x 707 mm)" ) );
mPaperMap.insert( tr( "B1 (707 x 1000 mm)" ), QgsCompositionPaper( tr( "B1 (707 x 1000 mm)" ), 707, 1000 ) );
mPaperSizeComboBox->insertItem( 11, tr( "B1 (707 x 1000 mm)" ) );
mPaperMap.insert( tr( "B0 (1000 x 1414 mm)" ), QgsCompositionPaper( tr( "B0 (1000 x 1414 mm)" ), 1000, 1414 ) );
mPaperSizeComboBox->insertItem( 12, tr( "B0 (1000 x 1414 mm)" ) );
mPaperMap.insert( tr( "Letter (8.5x11 inches)" ), QgsCompositionPaper( tr( "Letter (8.5x11 inches)" ), 216, 279 ) );
mPaperSizeComboBox->insertItem( 13, tr( "Letter (8.5x11 inches)" ) );
mPaperMap.insert( tr( "Legal (8.5x14 inches)" ), QgsCompositionPaper( tr( "Legal (8.5x14 inches)" ), 216, 356 ) );
mPaperSizeComboBox->insertItem( 14, tr( "Legal (8.5x14 inches)" ) );
mPaperSizeComboBox->blockSignals( false ); mPaperSizeComboBox->blockSignals( false );
} }


Expand All @@ -151,11 +159,13 @@ void QgsCompositionWidget::on_mPaperSizeComboBox_currentIndexChanged( const QStr
{ {
mPaperWidthLineEdit->setEnabled( true ); mPaperWidthLineEdit->setEnabled( true );
mPaperHeightLineEdit->setEnabled( true ); mPaperHeightLineEdit->setEnabled( true );
mPaperUnitsComboBox->setEnabled( true );
} }
else else
{ {
mPaperWidthLineEdit->setEnabled( false ); mPaperWidthLineEdit->setEnabled( false );
mPaperHeightLineEdit->setEnabled( false ); mPaperHeightLineEdit->setEnabled( false );
mPaperUnitsComboBox->setEnabled( false );
} }
applyCurrentPaperSettings(); applyCurrentPaperSettings();
} }
Expand All @@ -174,19 +184,45 @@ void QgsCompositionWidget::on_mPaperOrientationComboBox_currentIndexChanged( con
} }
} }


void QgsCompositionWidget::adjustOrientation() void QgsCompositionWidget::on_mPaperUnitsComboBox_currentIndexChanged( const QString& text )
{ {
double width, height; double width = size( mPaperWidthLineEdit );
bool conversionSuccess; double height = size( mPaperHeightLineEdit );


width = mPaperWidthLineEdit->text().toDouble( &conversionSuccess ); if ( mPaperUnitsComboBox->currentIndex() == 0 )
if ( !conversionSuccess )
{ {
return; // mm, value was inch
width *= 25.4;
height *= 25.4;
}
else
{
// inch, values was mm,
width /= 25.4;
height /= 25.4;
} }


height = mPaperHeightLineEdit->text().toDouble( &conversionSuccess ); setSize( mPaperWidthLineEdit, width );
if ( !conversionSuccess ) setSize( mPaperHeightLineEdit, height );

if ( mPaperSizeComboBox->currentText() == tr( "Custom" ) )
{
adjustOrientation();
applyWidthHeight();
}
else
{
adjustOrientation();
applyCurrentPaperSettings();
}
}

void QgsCompositionWidget::adjustOrientation()
{
double width = size( mPaperWidthLineEdit );
double height = size( mPaperHeightLineEdit );

if ( width < 0 || height < 0 )
{ {
return; return;
} }
Expand All @@ -204,18 +240,52 @@ void QgsCompositionWidget::adjustOrientation()
mPaperHeightLineEdit->setEnabled( true ); mPaperHeightLineEdit->setEnabled( true );
if ( mPaperOrientationComboBox->currentText() == tr( "Landscape" ) ) if ( mPaperOrientationComboBox->currentText() == tr( "Landscape" ) )
{ {
mPaperWidthLineEdit->setText( QString::number( width ) ); setSize( mPaperWidthLineEdit, width );
mPaperHeightLineEdit->setText( QString::number( height ) ); setSize( mPaperHeightLineEdit, height );
} }
else else
{ {
mPaperWidthLineEdit->setText( QString::number( height ) ); setSize( mPaperWidthLineEdit, height );
mPaperHeightLineEdit->setText( QString::number( width ) ); setSize( mPaperHeightLineEdit, width );
} }
mPaperWidthLineEdit->setEnabled( lineEditsEnabled ); mPaperWidthLineEdit->setEnabled( lineEditsEnabled );
mPaperHeightLineEdit->setEnabled( lineEditsEnabled ); mPaperHeightLineEdit->setEnabled( lineEditsEnabled );
} }


void QgsCompositionWidget::setSize( QLineEdit *le, double v )
{
if ( mPaperUnitsComboBox->currentIndex() == 0 )
{
// mm
le->setText( QString::number( v ) );
}
else
{
// inch (show width in inch)
le->setText( QString::number( v / 25.4 ) );
}
}

double QgsCompositionWidget::size( QLineEdit *le )
{
bool conversionSuccess;

double size = le->text().toDouble( &conversionSuccess );
if ( !conversionSuccess )
return -1.0;

if ( mPaperUnitsComboBox->currentIndex() == 0 )
{
// mm
return size;
}
else
{
// inch return in mm
return size * 25.4;
}
}

void QgsCompositionWidget::applyCurrentPaperSettings() void QgsCompositionWidget::applyCurrentPaperSettings()
{ {
if ( mComposition ) if ( mComposition )
Expand All @@ -229,8 +299,8 @@ void QgsCompositionWidget::applyCurrentPaperSettings()


mPaperWidthLineEdit->setEnabled( true ); mPaperWidthLineEdit->setEnabled( true );
mPaperHeightLineEdit->setEnabled( true ); mPaperHeightLineEdit->setEnabled( true );
mPaperWidthLineEdit->setText( QString::number( it->mWidth ) ); setSize( mPaperWidthLineEdit, it->mWidth );
mPaperHeightLineEdit->setText( QString::number( it->mHeight ) ); setSize( mPaperHeightLineEdit, it->mHeight );
mPaperWidthLineEdit->setEnabled( false ); mPaperWidthLineEdit->setEnabled( false );
mPaperHeightLineEdit->setEnabled( false ); mPaperHeightLineEdit->setEnabled( false );


Expand All @@ -241,20 +311,11 @@ void QgsCompositionWidget::applyCurrentPaperSettings()


void QgsCompositionWidget::applyWidthHeight() void QgsCompositionWidget::applyWidthHeight()
{ {
double width, height; double width = size( mPaperWidthLineEdit );
bool conversionSuccess; double height = size( mPaperHeightLineEdit );

width = mPaperWidthLineEdit->text().toDouble( &conversionSuccess );
if ( !conversionSuccess )
{
return;
}


height = mPaperHeightLineEdit->text().toDouble( &conversionSuccess ); if ( width < 0 || height < 0 )
if ( !conversionSuccess )
{
return; return;
}


mComposition->setPaperSize( width, height ); mComposition->setPaperSize( width, height );
} }
Expand Down Expand Up @@ -285,10 +346,10 @@ void QgsCompositionWidget::displayCompositionWidthHeight()
mResolutionLineEdit->blockSignals( true ); mResolutionLineEdit->blockSignals( true );


double paperWidth = mComposition->paperWidth(); double paperWidth = mComposition->paperWidth();
mPaperWidthLineEdit->setText( QString::number( paperWidth ) ); setSize( mPaperWidthLineEdit, paperWidth );


double paperHeight = mComposition->paperHeight(); double paperHeight = mComposition->paperHeight();
mPaperHeightLineEdit->setText( QString::number( paperHeight ) ); setSize( mPaperHeightLineEdit, paperHeight );


//set orientation //set orientation
if ( paperWidth > paperHeight ) if ( paperWidth > paperHeight )
Expand Down
4 changes: 4 additions & 0 deletions src/app/composer/qgscompositionwidget.h
Expand Up @@ -41,6 +41,7 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase


public slots: public slots:
void on_mPaperSizeComboBox_currentIndexChanged( const QString& text ); void on_mPaperSizeComboBox_currentIndexChanged( const QString& text );
void on_mPaperUnitsComboBox_currentIndexChanged( const QString& text );
void on_mPaperOrientationComboBox_currentIndexChanged( const QString& text ); void on_mPaperOrientationComboBox_currentIndexChanged( const QString& text );
void on_mPaperWidthLineEdit_editingFinished(); void on_mPaperWidthLineEdit_editingFinished();
void on_mPaperHeightLineEdit_editingFinished(); void on_mPaperHeightLineEdit_editingFinished();
Expand Down Expand Up @@ -73,4 +74,7 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase


void createPaperEntries(); void createPaperEntries();
void insertPaperEntries(); void insertPaperEntries();

double size( QLineEdit *le );
void setSize( QLineEdit *le, double v );
}; };

0 comments on commit 897886a

Please sign in to comment.