Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] add new labeling to vector layer properties
- add 'deprecated' label to old labeling in vector layer properties
  • Loading branch information
jef-n committed Aug 7, 2012
1 parent 511e89c commit a033d47
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 75 deletions.
36 changes: 33 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -1884,6 +1884,12 @@ QgsMapCanvas *QgisApp::mapCanvas()
return mMapCanvas;
}

QgsPalLabeling *QgisApp::palLabeling()
{
Q_ASSERT( mLBL );
return mLBL;
}

void QgisApp::initLegend()
{
mMapLegend->setWhatsThis( tr( "Map legend that displays all the layers currently on the map canvas. Click on the check box to turn a layer on or off. Double click on a layer in the legend to customize its appearance and set other properties." ) );
Expand Down Expand Up @@ -3842,14 +3848,36 @@ void QgisApp::labeling()
QMessageBox::warning( this, tr( "Labeling" ), tr( "Please select a vector layer first." ) );
return;
}

QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( layer );

QgsLabelingGui labelGui( mLBL, vlayer, mMapCanvas, this );
QDialog *dlg = new QDialog( this );
dlg->setWindowTitle( tr( "Layer labeling settings" ) );
QgsLabelingGui *labelingGui = new QgsLabelingGui( mLBL, vlayer, mMapCanvas, dlg );

QVBoxLayout *layout = new QVBoxLayout( dlg );
layout->addWidget( labelingGui );

QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply, Qt::Horizontal, dlg );
layout->addWidget( buttonBox );

dlg->setLayout( layout );

if ( labelGui.exec() )
QSettings settings;
dlg->restoreGeometry( settings.value( "/Windows/Labeling/geometry" ).toByteArray() );

connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL( clicked() ), dlg, SLOT( accept() ) );
connect( buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL( clicked() ), dlg, SLOT( reject() ) );
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), labelingGui, SLOT( apply() ) );

if ( dlg->exec() )
{
labelingGui->apply();

settings.setValue( "/Windows/Labeling/geometry", dlg->saveGeometry() );

// alter labeling - save the changes
labelGui.layerSettings().writeToLayer( vlayer );
labelingGui->layerSettings().writeToLayer( vlayer );

// trigger refresh
if ( mMapCanvas )
Expand All @@ -3858,6 +3886,8 @@ void QgisApp::labeling()
}
}

delete dlg;

activateDeactivateLayerRelatedActions( layer );
}

Expand Down
6 changes: 5 additions & 1 deletion src/app/qgisapp.h
Expand Up @@ -161,8 +161,12 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void openFile( const QString & fileName );
//!Overloaded version of the private function with same name that takes the imagename as a parameter
void saveMapAsImage( QString, QPixmap * );

/** Get the mapcanvas object from the app */
QgsMapCanvas *mapCanvas();

/** Get the mapcanvas object from the app */
QgsMapCanvas * mapCanvas();
QgsPalLabeling *palLabeling();

//! Set theme (icons)
void setTheme( QString themeName = "default" );
Expand Down
11 changes: 3 additions & 8 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -22,10 +22,10 @@
#include <qgsvectordataprovider.h>
#include <qgsmaplayerregistry.h>

#include "qgspallabeling.h"
#include "qgslabelengineconfigdialog.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsexpression.h"
#include "qgsmapcanvas.h"

#include <QColorDialog>
#include <QFontDialog>
Expand All @@ -34,16 +34,14 @@
#include <QMessageBox>
#include <QSettings>


QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QWidget* parent )
: QDialog( parent ), mLBL( lbl ), mLayer( layer ), mMapCanvas( mapCanvas )
: QWidget( parent ), mLBL( lbl ), mLayer( layer ), mMapCanvas( mapCanvas )
{
if ( !layer ) return;

setupUi( this );

QSettings settings;
restoreGeometry( settings.value( "/Windows/Labeling/geometry" ).toByteArray() );

connect( btnTextColor, SIGNAL( clicked() ), this, SLOT( changeTextColor() ) );
connect( btnChangeFont, SIGNAL( clicked() ), this, SLOT( changeTextFont() ) );
connect( chkBuffer, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
Expand Down Expand Up @@ -206,13 +204,10 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
{
connect( placementRadios[i], SIGNAL( toggled( bool ) ), this, SLOT( updateOptions() ) );
}
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
}

QgsLabelingGui::~QgsLabelingGui()
{
QSettings settings;
settings.setValue( "/Windows/Labeling/geometry", saveGeometry() );
}

void QgsLabelingGui::apply()
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgslabelinggui.h
Expand Up @@ -26,12 +26,12 @@ class QgsMapCanvas;

#include "qgspallabeling.h"

class QgsLabelingGui : public QDialog, private Ui::QgsLabelingGuiBase
class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
{
Q_OBJECT

public:
QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QWidget* parent );
QgsLabelingGui( QgsPalLabeling *lbl, QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QWidget* parent );
~QgsLabelingGui();

QgsPalLayerSettings layerSettings();
Expand Down
12 changes: 10 additions & 2 deletions src/app/qgsvectorlayerproperties.cpp 100644 → 100755
Expand Up @@ -32,6 +32,7 @@
#include "qgsfieldcalculator.h"
#include "qgsgraduatedsymboldialog.h"
#include "qgslabeldialog.h"
#include "qgslabelinggui.h"
#include "qgslabel.h"
#include "qgsgenericprojectionselector.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -98,16 +99,21 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
connect( insertFieldButton, SIGNAL( clicked() ), this, SLOT( insertField() ) );
connect( insertExpressionButton, SIGNAL( clicked() ), this, SLOT( insertExpression() ) );


mAddAttributeButton->setIcon( QgsApplication::getThemeIcon( "/mActionNewAttribute.png" ) );
mDeleteAttributeButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) );
mToggleEditingButton->setIcon( QgsApplication::getThemeIcon( "/mActionToggleEditing.png" ) );
mCalculateFieldButton->setIcon( QgsApplication::getThemeIcon( "/mActionCalculateField.png" ) );

connect( btnUseNewSymbology, SIGNAL( clicked() ), this, SLOT( useNewSymbology() ) );

QVBoxLayout *layout = new QVBoxLayout( labelingFrame );
layout->setMargin( 0 );
labelingDialog = new QgsLabelingGui( QgisApp::instance()->palLabeling(), layer, QgisApp::instance()->mapCanvas(), labelingFrame );
layout->addWidget( labelingDialog );
labelingFrame->setLayout( layout );

// Create the Label dialog tab
QVBoxLayout *layout = new QVBoxLayout( labelOptionsFrame );
layout = new QVBoxLayout( labelOptionsFrame );
layout->setMargin( 0 );
labelDialog = new QgsLabelDialog( layer->label(), labelOptionsFrame );
layout->addWidget( labelDialog );
Expand Down Expand Up @@ -657,6 +663,8 @@ QgsVectorLayer::EditType QgsVectorLayerProperties::editTypeFromButtonText( QStri

void QgsVectorLayerProperties::apply()
{
labelingDialog->apply();

//
// Set up sql subset query if applicable
//
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -37,6 +37,7 @@ class QgsApplyDialog;
class QgsLabelDialog;
class QgsVectorLayer;
class QgsVectorOverlayPlugin;
class QgsLabelingGui;

class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPropertiesBase
{
Expand Down Expand Up @@ -185,6 +186,8 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
QDialog* mRendererDialog;
/**Buffer renderer, which is assigned to the vector layer when apply is pressed*/
//QgsRenderer* bufferRenderer;
/**Labeling dialog. If apply is pressed, options are applied to vector's QgsLabel */
QgsLabelingGui *labelingDialog;
/**Label dialog. If apply is pressed, options are applied to vector's QgsLabel */
QgsLabelDialog* labelDialog;
/**Actions dialog. If apply is pressed, the actions are stored for later use */
Expand Down
55 changes: 5 additions & 50 deletions src/ui/qgslabelingguibase.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsLabelingGuiBase</class>
<widget class="QDialog" name="QgsLabelingGuiBase">
<widget class="QWidget" name="QgsLabelingGuiBase">
<property name="geometry">
<rect>
<x>0</x>
Expand Down Expand Up @@ -63,16 +63,6 @@
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
Expand Down Expand Up @@ -473,8 +463,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>658</width>
<height>451</height>
<width>647</width>
<height>435</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
Expand Down Expand Up @@ -935,8 +925,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>658</width>
<height>567</height>
<width>647</width>
<height>507</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_11">
Expand Down Expand Up @@ -1146,45 +1136,10 @@
<header>qgslabelpreview.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="../../images/images.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsLabelingGuiBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>353</x>
<y>459</y>
</hint>
<hint type="destinationlabel">
<x>309</x>
<y>430</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsLabelingGuiBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>353</x>
<y>459</y>
</hint>
<hint type="destinationlabel">
<x>353</x>
<y>430</y>
</hint>
</hints>
</connection>
<connection>
<sender>chkEnableLabeling</sender>
<signal>clicked(bool)</signal>
Expand Down
39 changes: 30 additions & 9 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -66,7 +66,7 @@
<item row="1" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>3</number>
<number>2</number>
</property>
<property name="iconSize">
<size>
Expand Down Expand Up @@ -184,14 +184,35 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabWidgetPage2">
<widget class="QWidget" name="labelingTab">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labels.png</normaloff>:/images/themes/default/propertyicons/labels.png</iconset>
</attribute>
<attribute name="title">
<string>Labels</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_47">
<item row="0" column="0">
<widget class="QFrame" name="labelingFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabWidgetPage2">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labels.png</normaloff>:/images/themes/default/propertyicons/labels.png</iconset>
</attribute>
<attribute name="title">
<string>Labels (deprecated)</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QCheckBox" name="labelCheckBox">
Expand Down Expand Up @@ -371,7 +392,7 @@
<x>0</x>
<y>0</y>
<width>740</width>
<height>548</height>
<height>558</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
Expand Down Expand Up @@ -739,8 +760,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>98</width>
<height>231</height>
<width>722</width>
<height>540</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -851,8 +872,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>106</width>
<height>129</height>
<width>722</width>
<height>540</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
Expand Down Expand Up @@ -944,8 +965,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>590</width>
<height>626</height>
<width>706</width>
<height>574</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_16">
Expand Down

0 comments on commit a033d47

Please sign in to comment.