Skip to content
Permalink
Browse files

Added scale-based visibility and buffer (mask) around the label

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11025 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 5, 2009
1 parent a557c23 commit 5aa616d1ad2429d0846a70c0de4aec2edc6508d9
@@ -7,6 +7,7 @@ SET (labeling_SRCS
labelinggui.cpp
pallabeling.cpp
engineconfigdialog.cpp
labelpreview.cpp
)

SET (labeling_UIS labelingguibase.ui engineconfigdialog.ui)
@@ -35,6 +36,7 @@ INCLUDE_DIRECTORIES(
../../core ../../core/raster ../../core/renderer ../../core/symbology
../../gui
..
.
)

TARGET_LINK_LIBRARIES(labelingplugin
@@ -30,13 +30,18 @@
#include <iostream>
#include <QApplication>



LabelingGui::LabelingGui( PalLabeling* lbl, QString layerId, QWidget* parent )
: QDialog( parent ), mLBL( lbl ), mLayerId( layerId )
{
setupUi( this );

connect(btnTextColor, SIGNAL(clicked()), this, SLOT(changeTextColor()) );
connect(btnChangeFont, SIGNAL(clicked()), this, SLOT(changeTextFont()) );
connect(chkBuffer, SIGNAL(toggled(bool)), this, SLOT(updatePreview()) );
connect(btnBufferColor, SIGNAL(clicked()), this, SLOT(changeBufferColor()) );
connect(spinBufferSize, SIGNAL(valueChanged(int)), this, SLOT(updatePreview()) );
connect(btnEngineSettings, SIGNAL(clicked()), this, SLOT(showEngineConfigDialog()) );

populatePlacementMethods();
@@ -52,11 +57,25 @@ LabelingGui::LabelingGui( PalLabeling* lbl, QString layerId, QWidget* parent )
sliderPriority->setValue( lyr.priority );
chkNoObstacle->setChecked( !lyr.obstacle );
spinDist->setValue( lyr.dist );

bool scaleBased = (lyr.scaleMin != 0 && lyr.scaleMax != 0);
chkScaleBasedVisibility->setChecked(scaleBased);
if (scaleBased)
{
spinScaleMin->setValue(lyr.scaleMin);
spinScaleMax->setValue(lyr.scaleMax);
}

bool buffer = (lyr.bufferSize != 0);
chkBuffer->setChecked(buffer);
if (buffer)
spinBufferSize->setValue(lyr.bufferSize);
}
else
{
// set enabled by default
chkEnableLabeling->setChecked( true );

}

// feature distance available only for points and lines
@@ -66,7 +85,12 @@ LabelingGui::LabelingGui( PalLabeling* lbl, QString layerId, QWidget* parent )
}

btnTextColor->setColor( lyr.textColor );
updateFontPreview( lyr.textFont );
btnBufferColor->setColor( lyr.bufferColor );
updateFont( lyr.textFont );
updateUi();

connect(chkBuffer, SIGNAL(toggled(bool)), this, SLOT(updateUi()) );
connect(chkScaleBasedVisibility, SIGNAL(toggled(bool)), this, SLOT(updateUi()) );
}

LabelingGui::~LabelingGui()
@@ -93,6 +117,24 @@ LayerSettings LabelingGui::layerSettings()
lyr.priority = sliderPriority->value();
lyr.obstacle = !chkNoObstacle->isChecked();
lyr.dist = spinDist->value();
if (chkScaleBasedVisibility->isChecked())
{
lyr.scaleMin = spinScaleMin->value();
lyr.scaleMax = spinScaleMax->value();
}
else
{
lyr.scaleMin = lyr.scaleMax = 0;
}
if (chkBuffer->isChecked())
{
lyr.bufferSize = spinBufferSize->value();
lyr.bufferColor = btnBufferColor->color();
}
else
{
lyr.bufferSize = 0;
}

return lyr;
}
@@ -134,31 +176,58 @@ void LabelingGui::changeTextColor()
return;

btnTextColor->setColor(color);
updateFontPreview( lblFontPreview->font() );
updatePreview();
}

void LabelingGui::changeTextFont()
{
bool ok;
QFont font = QFontDialog::getFont(&ok, lblFontPreview->font(), this);
if (ok)
updateFontPreview( font );
updateFont( font );
}

void LabelingGui::updateFontPreview(QFont font)
void LabelingGui::updateFont(QFont font)
{
lblFontName->setText( QString("%1, %2").arg(font.family()).arg(font.pointSize()) );
lblFontPreview->setFont(font);

QPalette palette = lblFontPreview->palette();
QBrush brush(btnTextColor->color());
palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
palette.setBrush(QPalette::Inactive, QPalette::WindowText, brush);
lblFontPreview->setPalette(palette);
updatePreview();
}

void LabelingGui::updatePreview()
{
lblFontPreview->setTextColor(btnTextColor->color());
if (chkBuffer->isChecked())
lblFontPreview->setBuffer(spinBufferSize->value(), btnBufferColor->color());
else
lblFontPreview->setBuffer(0, Qt::white);
}

void LabelingGui::showEngineConfigDialog()
{
EngineConfigDialog dlg(mLBL, this);
dlg.exec();
}

void LabelingGui::updateUi()
{
// enable/disable scale-based, buffer
bool buf = chkBuffer->isChecked();
spinBufferSize->setEnabled(buf);
btnBufferColor->setEnabled(buf);

bool scale = chkScaleBasedVisibility->isChecked();
spinScaleMin->setEnabled(scale);
spinScaleMax->setEnabled(scale);
}

void LabelingGui::changeBufferColor()
{
QColor color = QColorDialog::getColor( btnBufferColor->color(), this);
if (!color.isValid())
return;

btnBufferColor->setColor(color);
updatePreview();
}
@@ -41,11 +41,15 @@ class LabelingGui : public QDialog, private Ui::LabelingGuiBase
void changeTextColor();
void changeTextFont();
void showEngineConfigDialog();
void changeBufferColor();

void updateUi();
void updatePreview();

protected:
void populatePlacementMethods();
void populateFieldNames();
void updateFontPreview(QFont font);
void updateFont(QFont font);

QgsVectorLayer* layer();

0 comments on commit 5aa616d

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