Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve visual appearance of composer grid by making sure it is alway…
…s drawn using a 1 pixel width cosmetic pen

Remove options for composer pen width
  • Loading branch information
nyalldawson committed Sep 25, 2013
1 parent cb1090f commit 64885d9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 64 deletions.
14 changes: 0 additions & 14 deletions src/app/composer/qgscompositionwidget.cpp
Expand Up @@ -84,9 +84,6 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
mOffsetYSpinBox->setValue( mComposition->snapGridOffsetY() );


//grid pen width
mPenWidthSpinBox->setValue( mComposition->gridPen().widthF() );

//grid pen color
mGridColorButton->setColor( mComposition->gridPen().color() );
mGridColorButton->setColorDialogTitle( tr( "Select grid color" ) );
Expand Down Expand Up @@ -564,16 +561,6 @@ void QgsCompositionWidget::on_mGridStyleComboBox_currentIndexChanged( const QStr
}
}

void QgsCompositionWidget::on_mPenWidthSpinBox_valueChanged( double d )
{
if ( mComposition )
{
QPen pen = mComposition->gridPen();
pen.setWidthF( d );
mComposition->setGridPen( pen );
}
}

void QgsCompositionWidget::on_mSelectionToleranceSpinBox_valueChanged( double d )
{
if ( mComposition )
Expand Down Expand Up @@ -612,7 +599,6 @@ void QgsCompositionWidget::blockSignals( bool block )
mGridResolutionSpinBox->blockSignals( block );
mOffsetXSpinBox->blockSignals( block );
mOffsetYSpinBox->blockSignals( block );
mPenWidthSpinBox->blockSignals( block );
mGridColorButton->blockSignals( block );
mGridStyleComboBox->blockSignals( block );
mSelectionToleranceSpinBox->blockSignals( block );
Expand Down
1 change: 0 additions & 1 deletion src/app/composer/qgscompositionwidget.h
Expand Up @@ -59,7 +59,6 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
void on_mOffsetYSpinBox_valueChanged( double d );
void on_mGridColorButton_colorChanged( const QColor &newColor );
void on_mGridStyleComboBox_currentIndexChanged( const QString& text );
void on_mPenWidthSpinBox_valueChanged( double d );
void on_mSelectionToleranceSpinBox_valueChanged( double d );
void on_mAlignmentSnapGroupCheckBox_toggled( bool state );
void on_mAlignmentToleranceSpinBox_valueChanged( double d );
Expand Down
7 changes: 3 additions & 4 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -1491,6 +1491,8 @@ void QgsComposition::setSnapGridOffsetY( double offset )
void QgsComposition::setGridPen( const QPen& p )
{
mGridPen = p;
//make sure grid is drawn using a zero-width cosmetic pen
mGridPen.setWidthF( 0 );
updatePaperItems();
saveSettings();
}
Expand All @@ -1515,16 +1517,14 @@ void QgsComposition::loadSettings()

QString gridStyleString;
int red, green, blue;
double penWidth;

gridStyleString = s.value( "/qgis/composerGridStyle", "Dots" ).toString();
penWidth = s.value( "/qgis/composerGridWidth", 0.5 ).toDouble();
red = s.value( "/qgis/composerGridRed", 0 ).toInt();
green = s.value( "/qgis/composerGridGreen", 0 ).toInt();
blue = s.value( "/qgis/composerGridBlue", 0 ).toInt();

mGridPen.setColor( QColor( red, green, blue ) );
mGridPen.setWidthF( penWidth );
mGridPen.setWidthF( 0 );

if ( gridStyleString == "Dots" )
{
Expand All @@ -1546,7 +1546,6 @@ void QgsComposition::saveSettings()
{
//store grid appearance settings
QSettings s;
s.setValue( "/qgis/composerGridWidth", mGridPen.widthF() );
s.setValue( "/qgis/composerGridRed", mGridPen.color().red() );
s.setValue( "/qgis/composerGridGreen", mGridPen.color().green() );
s.setValue( "/qgis/composerGridBlue", mGridPen.color().blue() );
Expand Down
44 changes: 30 additions & 14 deletions src/core/composer/qgspaperitem.cpp
Expand Up @@ -51,7 +51,6 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
drawBackground( painter );

//draw grid

if ( mComposition )
{
if ( mComposition->snapToGridEnabled() && mComposition->plotStyle() == QgsComposition::Preview
Expand All @@ -63,13 +62,15 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
double currentYCoord;
double minYCoord = mComposition->snapGridOffsetY() - gridMultiplyY * mComposition->snapGridResolution();

painter->save();
//turn of antialiasing so grid is nice and sharp
painter->setRenderHint( QPainter::Antialiasing, false );

if ( mComposition->gridStyle() == QgsComposition::Solid )
{
painter->setPen( mComposition->gridPen() );

//draw vertical lines


for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() )
{
painter->drawLine( QPointF( currentXCoord, 0 ), QPointF( currentXCoord, rect().height() ) );
Expand All @@ -87,26 +88,41 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
QPen gridPen = mComposition->gridPen();
painter->setPen( gridPen );
painter->setBrush( QBrush( gridPen.color() ) );
double halfCrossLength = mComposition->snapGridResolution() / 6;
double halfCrossLength = 1;
if ( mComposition->gridStyle() == QgsComposition::Dots )
{
//dots are actually drawn as tiny crosses a few pixels across
//check QGraphicsView to get current transform
if ( scene() )
{
QList<QGraphicsView*> viewList = scene()->views();
if ( viewList.size() > 0 )
{
QGraphicsView* currentView = viewList.at( 0 );
if ( currentView->isVisible() )
{
//set halfCrossLength to equivalent of 1 pixel
halfCrossLength = 1 / currentView->transform().m11();
}
}
}
}
else if ( mComposition->gridStyle() == QgsComposition::Crosses )
{
halfCrossLength = mComposition->snapGridResolution() / 6;
}

for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() )
{
currentYCoord = minYCoord;
for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() )
{
if ( mComposition->gridStyle() == QgsComposition::Dots )
{
QRectF pieRect( currentXCoord - gridPen.widthF() / 2, currentYCoord - gridPen.widthF() / 2, gridPen.widthF(), gridPen.widthF() );
painter->drawChord( pieRect, 0, 5760 );
}
else if ( mComposition->gridStyle() == QgsComposition::Crosses )
{
painter->drawLine( QPointF( currentXCoord - halfCrossLength, currentYCoord ), QPointF( currentXCoord + halfCrossLength, currentYCoord ) );
painter->drawLine( QPointF( currentXCoord, currentYCoord - halfCrossLength ), QPointF( currentXCoord, currentYCoord + halfCrossLength ) );
}
painter->drawLine( QPointF( currentXCoord - halfCrossLength, currentYCoord ), QPointF( currentXCoord + halfCrossLength, currentYCoord ) );
painter->drawLine( QPointF( currentXCoord, currentYCoord - halfCrossLength ), QPointF( currentXCoord, currentYCoord + halfCrossLength ) );
}
}
}
painter->restore();
}
}
}
Expand Down
51 changes: 20 additions & 31 deletions src/ui/qgscompositionwidgetbase.ui
Expand Up @@ -23,7 +23,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -361,26 +370,6 @@
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Pen width</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mPenWidthSpinBox">
<property name="prefix">
<string/>
</property>
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mGridStyleLabel">
<property name="text">
<string>Grid style</string>
Expand All @@ -393,10 +382,17 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="mGridStyleComboBox"/>
</item>
<item row="5" column="0">
<item row="3" column="1">
<widget class="QgsColorButton" name="mGridColorButton">
<property name="text">
<string>Color...</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Selection tolerance</string>
Expand All @@ -406,7 +402,7 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="mSelectionToleranceSpinBox">
<property name="prefix">
<string/>
Expand All @@ -416,13 +412,6 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QgsColorButton" name="mGridColorButton">
<property name="text">
<string>Color...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 64885d9

Please sign in to comment.