Skip to content
Permalink
Browse files

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 24, 2013
1 parent cb1090f commit 64885d9eca65cf686df9b74586722fd94f6d12f0
@@ -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" ) );
@@ -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 )
@@ -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 );
@@ -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 );
@@ -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();
}
@@ -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" )
{
@@ -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() );
@@ -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
@@ -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() ) );
@@ -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();
}
}
}
@@ -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>
@@ -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>
@@ -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>
@@ -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/>
@@ -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>

0 comments on commit 64885d9

Please sign in to comment.
You can’t perform that action at this time.