-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dialog for data defined symbology
- Loading branch information
Showing
9 changed files
with
321 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#include "qgsdatadefinedsymboldialog.h" | ||
#include "qgsexpressionbuilderdialog.h" | ||
#include "qgsvectorlayer.h" | ||
#include <QCheckBox> | ||
#include <QComboBox> | ||
#include <QPushButton> | ||
|
||
QgsDataDefinedSymbolDialog::QgsDataDefinedSymbolDialog( const QMap< QString, QPair< QString, QString > >& properties, const QgsVectorLayer* vl, | ||
QWidget* parent, Qt::WindowFlags f ): QDialog( parent, f ), mVectorLayer( vl ) | ||
{ | ||
setupUi( this ); | ||
|
||
QgsFields attributeFields; | ||
if ( mVectorLayer ) | ||
{ | ||
attributeFields = mVectorLayer->pendingFields(); | ||
} | ||
|
||
mTableWidget->setRowCount( properties.size() ); | ||
int i = 0; | ||
QMap< QString, QPair< QString, QString > >::const_iterator it = properties.constBegin(); | ||
for ( ; it != properties.constEnd(); ++it ) | ||
{ | ||
//check box | ||
mTableWidget->setCellWidget( i, 0, new QCheckBox( this ) ); | ||
//property name | ||
QTableWidgetItem* propertyItem = new QTableWidgetItem( it.value().first ); | ||
propertyItem->setData( Qt::UserRole, it.key() ); | ||
mTableWidget->setItem( i, 1, propertyItem ); | ||
//attribute list | ||
QComboBox* attributeComboBox = new QComboBox( this ); | ||
attributeComboBox->addItem( it.value().second ); | ||
for ( int j = 0; j < attributeFields.count(); ++j ) | ||
{ | ||
attributeComboBox->addItem( attributeFields.at( j ).name() ); | ||
} | ||
|
||
mTableWidget->setCellWidget( i, 2, attributeComboBox ); | ||
|
||
//expression button | ||
QPushButton* expressionButton = new QPushButton( "...", this ); | ||
QObject::connect( expressionButton, SIGNAL( clicked() ), this, SLOT( expressionButtonClicked() ) ); | ||
mTableWidget->setCellWidget( i, 3, expressionButton ); | ||
++i; | ||
} | ||
|
||
//connect( this, SIGNAL( cellClicked( int, int ) ), this, SLOT( handleCellClick(int,int) ) ); | ||
} | ||
|
||
QgsDataDefinedSymbolDialog::~QgsDataDefinedSymbolDialog() | ||
{ | ||
|
||
} | ||
|
||
QMap< QString, QString > QgsDataDefinedSymbolDialog::dataDefinedProperties() const | ||
{ | ||
QMap< QString, QString > propertyMap; | ||
int rowCount = mTableWidget->rowCount(); | ||
for ( int i = 0; i < rowCount; ++i ) | ||
{ | ||
//property | ||
QString propertyKey = mTableWidget->item( i, 1 )->data( Qt::UserRole ).toString(); | ||
//checked? | ||
bool checked = false; | ||
QCheckBox* cb = qobject_cast<QCheckBox*>( mTableWidget->cellWidget( i, 0 ) ); | ||
if ( cb ) | ||
{ | ||
checked = cb->isChecked(); | ||
} | ||
QString expressionString; | ||
if ( checked ) | ||
{ | ||
QComboBox* comboBox = qobject_cast<QComboBox*>( mTableWidget->cellWidget( i, 2 ) ); | ||
expressionString = comboBox->currentText(); | ||
if ( comboBox->currentIndex() > 0 ) | ||
{ | ||
expressionString.prepend( "\"" ).append( "\"" ); | ||
} | ||
} | ||
propertyMap.insert( propertyKey, expressionString ); | ||
} | ||
return propertyMap; | ||
} | ||
|
||
void QgsDataDefinedSymbolDialog::expressionButtonClicked() | ||
{ | ||
qWarning( "Expression button clicked" ); | ||
|
||
//find out row | ||
QObject* senderObj = sender(); | ||
int row = 0; | ||
for ( ; row < mTableWidget->rowCount(); ++row ) | ||
{ | ||
if ( senderObj == mTableWidget->cellWidget( row, 3 ) ) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
QComboBox* attributeCombo = qobject_cast<QComboBox*>( mTableWidget->cellWidget( row, 2 ) ); | ||
if ( !attributeCombo ) | ||
{ | ||
return; | ||
} | ||
|
||
QString previousText = attributeCombo->itemText( attributeCombo->currentIndex() ); | ||
if ( attributeCombo->currentIndex() > 0 ) | ||
{ | ||
previousText.prepend( "\"" ).append( "\"" ); | ||
} | ||
|
||
QgsExpressionBuilderDialog d( const_cast<QgsVectorLayer*>( mVectorLayer ), previousText ); | ||
if ( d.exec() == QDialog::Accepted ) | ||
{ | ||
QString expressionString = d.expressionText(); | ||
QString attributeString = expressionString.trimmed(); | ||
attributeString.remove( 0, 1 ).chop( 1 ); | ||
int comboIndex = attributeCombo->findText( attributeString ); | ||
if ( attributeString.size() < 1 || comboIndex == -1 ) | ||
{ | ||
attributeCombo->setItemText( 0, d.expressionText() ); | ||
attributeCombo->setCurrentIndex( 0 ); | ||
} | ||
else | ||
{ | ||
attributeCombo->setItemText( 0, QString() ); | ||
attributeCombo->setCurrentIndex( comboIndex ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef QGSDATADEFINEDSYMBOLLAYERDIALOG_H | ||
#define QGSDATADEFINEDSYMBOLLAYERDIALOG_H | ||
|
||
#include "ui_qgsdatadefinedsymboldialogbase.h" | ||
#include <QDialog> | ||
|
||
class QgsVectorLayer; | ||
|
||
class QgsDataDefinedSymbolDialog: public QDialog, private Ui::QgsDataDefinedSymbolDialog | ||
{ | ||
Q_OBJECT | ||
public: | ||
QgsDataDefinedSymbolDialog( const QMap< QString, QPair< QString, QString > >& properties, const QgsVectorLayer* vl, QWidget * parent = 0, Qt::WindowFlags f = 0 ); | ||
~QgsDataDefinedSymbolDialog(); | ||
QMap< QString, QString > dataDefinedProperties() const; | ||
|
||
private slots: | ||
void expressionButtonClicked(); | ||
|
||
private: | ||
const QgsVectorLayer* mVectorLayer; | ||
}; | ||
|
||
#endif // QGSDATADEFINEDSYMBOLLAYERDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>QgsDataDefinedSymbolDialog</class> | ||
<widget class="QDialog" name="QgsDataDefinedSymbolDialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>300</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Data defined properties</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="1" column="0"> | ||
<widget class="QDialogButtonBox" name="mButtonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="0"> | ||
<widget class="QTableWidget" name="mTableWidget"> | ||
<column> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</column> | ||
<column> | ||
<property name="text"> | ||
<string>Property</string> | ||
</property> | ||
</column> | ||
<column> | ||
<property name="text"> | ||
<string>Field</string> | ||
</property> | ||
</column> | ||
<column> | ||
<property name="text"> | ||
<string>Expression</string> | ||
</property> | ||
</column> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>mButtonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>QgsDataDefinedSymbolDialog</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>mButtonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>QgsDataDefinedSymbolDialog</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters