100521_labelpatch.diff
| src/plugins/labeling/labelingguibase.ui (Arbeitskopie) | ||
|---|---|---|
| 206 | 206 |
<item row="0" column="2"> |
| 207 | 207 |
<widget class="QLabel" name="label_9"> |
| 208 | 208 |
<property name="text"> |
| 209 |
<string>pixels</string>
|
|
| 209 |
<string>mm</string>
|
|
| 210 | 210 |
</property> |
| 211 | 211 |
</widget> |
| 212 | 212 |
</item> |
| ... | ... | |
| 312 | 312 |
<item> |
| 313 | 313 |
<widget class="QLabel" name="label_15"> |
| 314 | 314 |
<property name="text"> |
| 315 |
<string>pixels</string>
|
|
| 315 |
<string>mm</string>
|
|
| 316 | 316 |
</property> |
| 317 | 317 |
</widget> |
| 318 | 318 |
</item> |
| ... | ... | |
| 472 | 472 |
</widget> |
| 473 | 473 |
</item> |
| 474 | 474 |
<item> |
| 475 |
<widget class="QSpinBox" name="spinBufferSize"> |
|
| 476 |
<property name="minimum">
|
|
| 477 |
<number>1</number>
|
|
| 475 |
<widget class="QDoubleSpinBox" name="spinBufferSize">
|
|
| 476 |
<property name="suffix">
|
|
| 477 |
<string> mm</string>
|
|
| 478 | 478 |
</property> |
| 479 | 479 |
</widget> |
| 480 | 480 |
</item> |
| ... | ... | |
| 753 | 753 |
<tabstop>btnChangeFont</tabstop> |
| 754 | 754 |
<tabstop>btnTextColor</tabstop> |
| 755 | 755 |
<tabstop>chkBuffer</tabstop> |
| 756 |
<tabstop>spinBufferSize</tabstop> |
|
| 757 | 756 |
<tabstop>btnBufferColor</tabstop> |
| 758 | 757 |
<tabstop>sliderPriority</tabstop> |
| 759 | 758 |
<tabstop>chkScaleBasedVisibility</tabstop> |
| src/plugins/labeling/pallabeling.cpp (Arbeitskopie) | ||
|---|---|---|
| 72 | 72 |
for ( int i = 0; i < mText.count(); i++ ) |
| 73 | 73 |
{
|
| 74 | 74 |
mInfo->char_info[i].chr = mText[i].unicode(); |
| 75 |
ptSize = xform->toMapCoordinates( fm->width( mText[i] ), 0 ); |
|
| 75 |
ptSize = xform->toMapCoordinates( fm->width( mText[i] ) , 0 );
|
|
| 76 | 76 |
mInfo->char_info[i].width = ptSize.x() - ptZero.x(); |
| 77 | 77 |
} |
| 78 | 78 |
return mInfo; |
| ... | ... | |
| 105 | 105 |
bufferColor = Qt::white; |
| 106 | 106 |
labelPerPart = false; |
| 107 | 107 |
mergeLines = false; |
| 108 |
vectorScaleFactor = 1.0; |
|
| 109 |
rasterCompressFactor = 1.0; |
|
| 108 | 110 |
} |
| 109 | 111 | |
| 110 | 112 |
LayerSettings::LayerSettings( const LayerSettings& s ) |
| ... | ... | |
| 125 | 127 |
bufferColor = s.bufferColor; |
| 126 | 128 |
labelPerPart = s.labelPerPart; |
| 127 | 129 |
mergeLines = s.mergeLines; |
| 128 | ||
| 130 |
vectorScaleFactor = s.vectorScaleFactor; |
|
| 131 |
rasterCompressFactor = s.rasterCompressFactor; |
|
| 129 | 132 |
fontMetrics = NULL; |
| 130 | 133 |
ct = NULL; |
| 131 | 134 |
} |
| ... | ... | |
| 212 | 215 |
//QFontMetrics fontMetrics(textFont); |
| 213 | 216 |
QRect labelRect = /*QRect(0,0,20,20);*/ fontMetrics->boundingRect( text ); |
| 214 | 217 | |
| 215 |
// 2px border... |
|
| 216 |
QgsPoint ptSize = xform->toMapCoordinates( labelRect.width() + 2, labelRect.height() + 2 ); |
|
| 218 |
// 1mm border... |
|
| 219 | ||
| 220 |
QgsPoint ptSize; |
|
| 221 |
if ( placement == Curved ) |
|
| 222 |
{
|
|
| 223 |
ptSize = xform->toMapCoordinates( labelRect.width(), labelRect.height() ); |
|
| 224 |
} |
|
| 225 |
else |
|
| 226 |
{
|
|
| 227 |
double border = vectorScaleFactor; |
|
| 228 |
double buffer = bufferSize * vectorScaleFactor; |
|
| 229 |
ptSize = xform->toMapCoordinates( labelRect.width() + 2 * ( border + buffer ) , labelRect.height() + 2 * ( border + buffer ) ); |
|
| 230 |
} |
|
| 231 | ||
| 217 | 232 |
labelX = fabs( ptSize.x() - ptZero.x() ); |
| 218 | 233 |
labelY = fabs( ptSize.y() - ptZero.y() ); |
| 219 | 234 |
} |
| ... | ... | |
| 252 | 267 | |
| 253 | 268 |
// TODO: allow layer-wide feature dist in PAL...? |
| 254 | 269 |
if ( dist != 0 ) |
| 255 |
feat->setDistLabel( fabs( ptOne.x() - ptZero.x() )* dist ); |
|
| 270 |
feat->setDistLabel( fabs( ptOne.x() - ptZero.x() )* dist * vectorScaleFactor );
|
|
| 256 | 271 |
} |
| 257 | 272 | |
| 258 | 273 | |
| ... | ... | |
| 358 | 373 |
double size = 0.3527 * lyr.textFont.pointSizeF() * ctx.scaleFactor(); //* ctx.rasterScaleFactor(); |
| 359 | 374 |
lyr.textFont.setPixelSize(( int )size ); |
| 360 | 375 | |
| 376 |
//raster and vector scale factors |
|
| 377 |
lyr.vectorScaleFactor = ctx.scaleFactor(); |
|
| 378 |
lyr.rasterCompressFactor = ctx.rasterScaleFactor(); |
|
| 379 | ||
| 361 | 380 |
// save the pal layer to our layer context (with some additional info) |
| 362 | 381 |
lyr.palLayer = l; |
| 363 | 382 |
lyr.fieldIndex = fldIndex; |
| ... | ... | |
| 579 | 598 |
painter->save(); |
| 580 | 599 |
painter->translate( QPointF( outPt.x(), outPt.y() ) ); |
| 581 | 600 |
painter->rotate( -label->getAlpha() * 180 / M_PI ); |
| 582 |
painter->translate( QPointF( 1, -1 - lyr.fontBaseline ) ); |
|
| 601 |
if ( lyr.placement == LayerSettings::Curved ) |
|
| 602 |
{
|
|
| 603 |
painter->translate( QPointF( 0, -1 - lyr.fontBaseline ) ); |
|
| 604 |
} |
|
| 605 |
else |
|
| 606 |
{
|
|
| 607 |
painter->translate( QPointF( lyr.vectorScaleFactor *( 1 + lyr.bufferSize ), -lyr.vectorScaleFactor *( 1 + lyr.bufferSize ) - lyr.fontBaseline ) ); |
|
| 608 |
} |
|
| 583 | 609 | |
| 610 |
//request larger font and scale down painter (to avoid Qt font scale bug) |
|
| 611 |
QFont labelFont = lyr.textFont; |
|
| 612 |
labelFont.setPixelSize( labelFont.pixelSize() * lyr.rasterCompressFactor ); |
|
| 613 |
painter->scale( 1.0 / lyr.rasterCompressFactor, 1.0 / lyr.rasterCompressFactor ); |
|
| 614 | ||
| 584 | 615 |
if ( drawBuffer ) |
| 585 | 616 |
{
|
| 586 | 617 |
// we're drawing buffer |
| 587 |
drawLabelBuffer( painter, txt, lyr.textFont, lyr.bufferSize, lyr.bufferColor );
|
|
| 618 |
drawLabelBuffer( painter, txt, labelFont, lyr.bufferSize * lyr.vectorScaleFactor * lyr.rasterCompressFactor , lyr.bufferColor );
|
|
| 588 | 619 |
} |
| 589 | 620 |
else |
| 590 | 621 |
{
|
| ... | ... | |
| 594 | 625 |
painter->drawText((0,0, txt);*/ |
| 595 | 626 | |
| 596 | 627 |
QPainterPath path; |
| 597 |
path.addText( 0, 0, lyr.textFont, txt );
|
|
| 628 |
path.addText( 0, 0, labelFont, txt );
|
|
| 598 | 629 |
painter->setPen( Qt::NoPen ); |
| 599 | 630 |
painter->setBrush( lyr.textColor ); |
| 600 | 631 |
painter->drawPath( path ); |
| ... | ... | |
| 606 | 637 |
} |
| 607 | 638 | |
| 608 | 639 | |
| 609 |
void PalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& font, int size, QColor color )
|
|
| 640 |
void PalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color )
|
|
| 610 | 641 |
{
|
| 611 | 642 |
/* |
| 612 | 643 |
p->setFont( font ); |
| ... | ... | |
| 618 | 649 | |
| 619 | 650 |
QPainterPath path; |
| 620 | 651 |
path.addText( 0, 0, font, text ); |
| 621 |
p->setPen( QPen( color, size ) ); |
|
| 652 |
QPen pen( color ); |
|
| 653 |
pen.setWidthF( size ); |
|
| 654 |
p->setPen( pen ); |
|
| 622 | 655 |
p->setBrush( color ); |
| 623 | 656 |
p->drawPath( path ); |
| 624 | 657 |
} |
| src/plugins/labeling/pallabeling.h (Arbeitskopie) | ||
|---|---|---|
| 60 | 60 |
bool enabled; |
| 61 | 61 |
int priority; // 0 = low, 10 = high |
| 62 | 62 |
bool obstacle; // whether it's an obstacle |
| 63 |
double dist; // distance from the feature (in pixels) |
|
| 63 |
double dist; // distance from the feature (in mm) |
|
| 64 |
double vectorScaleFactor; //scale factor painter units->pixels |
|
| 65 |
double rasterCompressFactor; //pixel resolution scale factor |
|
| 64 | 66 |
int scaleMin, scaleMax; // disabled if both are zero |
| 65 |
int bufferSize;
|
|
| 67 |
double bufferSize; //buffer size (in mm)
|
|
| 66 | 68 |
QColor bufferColor; |
| 67 | 69 |
bool labelPerPart; // whether to label every feature's part or only the biggest one |
| 68 | 70 |
bool mergeLines; |
| ... | ... | |
| 139 | 141 | |
| 140 | 142 |
void drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform ); |
| 141 | 143 |
void drawLabel( pal::LabelPosition* label, QPainter* painter, const QgsMapToPixel* xform, bool drawBuffer = false ); |
| 142 |
static void drawLabelBuffer( QPainter* p, QString text, const QFont& font, int size, QColor color );
|
|
| 144 |
static void drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color );
|
|
| 143 | 145 | |
| 144 | 146 |
protected: |
| 145 | 147 | |
| src/plugins/labeling/labelpreview.cpp (Arbeitskopie) | ||
|---|---|---|
| 15 | 15 |
update(); |
| 16 | 16 |
} |
| 17 | 17 | |
| 18 |
void LabelPreview::setBuffer( int size, QColor color )
|
|
| 18 |
void LabelPreview::setBuffer( double size, QColor color )
|
|
| 19 | 19 |
{
|
| 20 |
mBufferSize = size;
|
|
| 20 |
mBufferSize = size * 88 / 25.4; //assume standard dpi for preview
|
|
| 21 | 21 |
mBufferColor = color; |
| 22 | 22 |
update(); |
| 23 | 23 |
} |
| src/plugins/labeling/labelinggui.cpp (Arbeitskopie) | ||
|---|---|---|
| 41 | 41 |
connect( btnChangeFont, SIGNAL( clicked() ), this, SLOT( changeTextFont() ) ); |
| 42 | 42 |
connect( chkBuffer, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) ); |
| 43 | 43 |
connect( btnBufferColor, SIGNAL( clicked() ), this, SLOT( changeBufferColor() ) ); |
| 44 |
connect( spinBufferSize, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
|
|
| 44 |
connect( spinBufferSize, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ) );
|
|
| 45 | 45 |
connect( btnEngineSettings, SIGNAL( clicked() ), this, SLOT( showEngineConfigDialog() ) ); |
| 46 | 46 | |
| 47 | 47 |
// set placement methods page based on geometry type |
| src/plugins/labeling/labelpreview.h (Arbeitskopie) | ||
|---|---|---|
| 10 | 10 | |
| 11 | 11 |
void setTextColor( QColor color ); |
| 12 | 12 | |
| 13 |
void setBuffer( int size, QColor color );
|
|
| 13 |
void setBuffer( double size, QColor color );
|
|
| 14 | 14 | |
| 15 | 15 |
void paintEvent( QPaintEvent* e ); |
| 16 | 16 | |