68
69
#ifdef HAVE_POSTGRESQL
69
70
#include "qgspgquerybuilder.h"
72
QgsDlgVectorLayerProperties::QgsDlgVectorLayerProperties(QgsVectorLayer * lyr, QWidget * parent, const char *name, bool modal):QgsDlgVectorLayerPropertiesBase(parent, name, modal), layer(lyr), rendererDirty(false), bufferDialog(layer->rendererDialog()),
73
bufferRenderer(layer->
72
#include "qgslayerprojectionselector.h"
73
#include <qapplication.h>
76
QgsDlgVectorLayerProperties::QgsDlgVectorLayerProperties(QgsVectorLayer * lyr,
80
: QgsDlgVectorLayerPropertiesBase(parent, name, modal),
83
bufferDialog(layer->rendererDialog()),
84
bufferRenderer(layer->renderer())
77
// populate the general information
78
QString source = layer->source();
79
source = source.left(source.find("password"));
80
lblSource->setText(source);
81
txtDisplayName->setText(layer->name());
82
// set whats this stuff
83
QWhatsThis::add(lblSource, tr("The source of the data (path name or database connection information)"));
84
QWhatsThis::add(pbnQueryBuilder, tr("This button opens the PostgreSQL query builder and allows you to create a subset of features to display on the map canvas rather than displaying all features in the layer"));
85
QWhatsThis::add(txtSubsetSQL, tr("The query used to limit the features in the layer is shown here. This is currently only supported for PostgreSQL layers. To enter or modify the query, click on the Query Builder button"));
86
QWhatsThis::add(lblGeometryType, tr("Geometry type of the features in this layer"));
87
QWhatsThis::add(lblFeatureCount, tr("The number of features in this layer"));
88
// display type and feature count
89
lblGeometryType->setText(QGis::qgisVectorGeometryType[layer->vectorType()]);
90
//we are dealing with a pg layer here so that we can enable the sql box
91
QgsVectorDataProvider *dp = dynamic_cast<QgsVectorDataProvider *>(layer->getDataProvider());
92
//see if we are dealing with a pg layer here
93
if(layer->providerType() == "postgres")
95
grpSubset->setEnabled(true);
96
txtSubsetSQL->setText(layer->subsetString());
97
// if the user is allowed to type an adhoc query, the app will crash if the query
98
// is bad. For this reason, the sql box is disabled and the query must be built
99
// using the query builder, either by typing it in by hand or using the buttons, etc
100
// on the builder. If the ability to enter a query directly into the box is required,
101
// a mechanism to check it must be implemented.
102
txtSubsetSQL->setEnabled(false);
103
pbnQueryBuilder->setEnabled(true);
107
grpSubset->setEnabled(false);
110
numFeatures = numFeatures.setNum(layer->featureCount());
111
lblFeatureCount->setText(numFeatures);
112
QgsRect *extent = dp->extent();
114
//QTextOStream (&ll) << extent->xMin() << ", " << extent->yMin();
115
lblLowerLeft->setText(ll.sprintf("%16f, %16f", extent->xMin(), extent->yMin()));
117
// QTextOStream (&ur) << extent->xMax() << ", " << extent->yMax();
118
lblUpperRight->setText(ur.sprintf("%16f, %16f", extent->xMax(), extent->yMax()));
119
std::vector<QgsField> fields = dp->fields();
120
// populate the table and the display field drop-down with the field
123
for (int i = 0; i < fields.size(); i++)
125
QgsField fld = fields[i];
126
QListViewItem *lvi = new QListViewItem(listViewFields, fld.name(),
127
fld.type(), QString("%1").arg(fld.length()),
128
QString("%1").arg(fld.precision()));
129
displayFieldComboBox->insertItem( fld.name() );
132
// set up the scale based layer visibility stuff....
133
chkUseScaleDependentRendering->setChecked(lyr->scaleBasedVisibility());
134
spinMinimumScale->setValue(lyr->minScale());
135
spinMaximumScale->setValue(lyr->maxScale());
137
// symbology initialization
138
legendtypecombobox->insertItem(tr("Single Symbol"));
139
legendtypecombobox->insertItem(tr("Graduated Symbol"));
140
legendtypecombobox->insertItem(tr("Continuous Color"));
141
legendtypecombobox->insertItem(tr("Unique Value"));
142
if( layer->vectorType()==QGis::Point )
144
legendtypecombobox->insertItem(tr("Single Marker"));
145
legendtypecombobox->insertItem(tr("Graduated Marker"));
146
legendtypecombobox->insertItem(tr("Unique Value Marker"));
86
// Create the Label dialog tab
149
87
QVBoxLayout *layout = new QVBoxLayout( labelOptionsFrame );
150
labelDialog = new QgsLabelDialog ( layer->label(),labelOptionsFrame);
88
labelDialog = new QgsLabelDialog ( layer->label(), labelOptionsFrame);
151
89
layout->addWidget( labelDialog );
153
QGridLayout *actionLayout = new QGridLayout( actionOptionsFrame );
154
actionDialog = new QgsAttributeActionDialog ( layer->actions(), fields,
91
// Create the Actions dialog tab
92
QgsVectorDataProvider *dp = dynamic_cast<QgsVectorDataProvider *>(layer->getDataProvider());
93
QVBoxLayout *actionLayout = new QVBoxLayout( actionOptionsFrame );
94
std::vector<QgsField> fields = dp->fields();
95
actionDialog = new QgsAttributeActionDialog ( layer->actions(), fields,
155
96
actionOptionsFrame );
156
actionLayout->addWidget( actionDialog,0,0 );
158
QObject::connect(legendtypecombobox, SIGNAL(activated(const QString &)), this, SLOT(alterLayerDialog(const QString &)));
160
//insert the renderer dialog of the vector layer into the widget stack
161
widgetStackRenderers->addWidget(bufferDialog);
162
widgetStackRenderers->raiseWidget(bufferDialog);
97
actionLayout->addWidget( actionDialog );
101
if(layer->getDataProvider())//enable spatial index button group if supported by provider
103
int capabilities=layer->getDataProvider()->capabilities();
104
if(capabilities&QgsVectorDataProvider::CreateSpatialIndex)
106
indexGroupBox->setEnabled(true);
110
if ( layer->coordinateTransform() )
112
leSpatialRefSys->setText(layer->coordinateTransform()->sourceSRS().proj4String());
115
} // QgsDlgVectorLayerProperties ctor
166
117
QgsDlgVectorLayerProperties::~QgsDlgVectorLayerProperties()
272
223
displayFieldComboBox->setCurrentText(name);
226
//! @note in raster props, this metho d is called sync()
275
227
void QgsDlgVectorLayerProperties::reset( void )
277
actionDialog->init();
279
labelCheckBox->setChecked(layer->labelOn());
229
// populate the general information
230
QString source = layer->source();
231
source = source.left(source.find("password"));
232
lblSource->setText(source);
233
txtDisplayName->setText(layer->name());
234
// set whats this stuff
235
QWhatsThis::add(lblSource, tr("The source of the data (path name or database connection information)"));
236
QWhatsThis::add(pbnQueryBuilder, tr("This button opens the PostgreSQL query builder and allows you to create a subset of features to display on the map canvas rather than displaying all features in the layer"));
237
QWhatsThis::add(txtSubsetSQL, tr("The query used to limit the features in the layer is shown here. This is currently only supported for PostgreSQL layers. To enter or modify the query, click on the Query Builder button"));
239
//we are dealing with a pg layer here so that we can enable the sql box
240
QgsVectorDataProvider *dp = dynamic_cast<QgsVectorDataProvider *>(layer->getDataProvider());
241
//see if we are dealing with a pg layer here
242
if(layer->providerType() == "postgres")
244
grpSubset->setEnabled(true);
245
txtSubsetSQL->setText(layer->subsetString());
246
// if the user is allowed to type an adhoc query, the app will crash if the query
247
// is bad. For this reason, the sql box is disabled and the query must be built
248
// using the query builder, either by typing it in by hand or using the buttons, etc
249
// on the builder. If the ability to enter a query directly into the box is required,
250
// a mechanism to check it must be implemented.
251
txtSubsetSQL->setEnabled(false);
252
pbnQueryBuilder->setEnabled(true);
256
grpSubset->setEnabled(false);
259
//get field list for display field combo
260
std::vector<QgsField> myFields = dp->fields();
261
for (int i = 0; i < myFields.size(); i++)
263
QgsField myField = myFields[i];
264
displayFieldComboBox->insertItem( myField.name() );
267
// set up the scale based layer visibility stuff....
268
chkUseScaleDependentRendering->setChecked(layer->scaleBasedVisibility());
269
spinMinimumScale->setValue((int)layer->minScale());
270
spinMaximumScale->setValue((int)layer->maxScale());
272
// symbology initialization
273
if(legendtypecombobox->count()==0)
275
legendtypecombobox->insertItem(tr("Single Symbol"));
276
if(myFields.size()>0)
278
legendtypecombobox->insertItem(tr("Graduated Symbol"));
279
legendtypecombobox->insertItem(tr("Continuous Color"));
280
legendtypecombobox->insertItem(tr("Unique Value"));
282
if( layer->vectorType()==QGis::Point )
284
legendtypecombobox->insertItem(tr("Single Marker"));
285
if(myFields.size()>0)
287
legendtypecombobox->insertItem(tr("Graduated Marker"));
288
legendtypecombobox->insertItem(tr("Unique Value Marker"));
293
QObject::connect(legendtypecombobox, SIGNAL(activated(const QString &)), this, SLOT(alterLayerDialog(const QString &)));
295
//insert the renderer dialog of the vector layer into the widget stack
296
widgetStackRenderers->addWidget(bufferDialog);
297
widgetStackRenderers->raiseWidget(bufferDialog);
299
//set the metadata contents
300
teMetadata->setText(getMetadata());
301
actionDialog->init();
303
labelCheckBox->setChecked(layer->labelOn());
282
309
// methods reimplemented from qt designer base class
414
442
// if the sql is changed, update it in the prop subset text box
415
443
txtSubsetSQL->setText(pqb->sql());
416
444
//TODO If the sql is changed in the prop dialog, the layer extent should be recalculated
446
// The datasource for the layer needs to be updated with the new sql since this gets
447
// saved to the project file. This should happen at the map layer level...
418
450
// delete the query builder object
455
void QgsDlgVectorLayerProperties::pbnIndex_clicked()
457
QgsVectorDataProvider* pr=layer->getDataProvider();
460
setCursor(Qt::WaitCursor);
461
bool errval=pr->createSpatialIndex();
462
setCursor(Qt::ArrowCursor);
465
QMessageBox::information(this, tr("Spatial Index"), tr("Creation of spatial index successfull"),QMessageBox::Ok);
469
QMessageBox::information(this, tr("Spatial Index"), tr("Creation of spatial index failed"),QMessageBox::Ok);
474
QString QgsDlgVectorLayerProperties::getMetadata()
476
QString myMetadataQString = "<html><body>";
477
myMetadataQString += "<table width=\"100%\">";
481
myMetadataQString += "<tr><td bgcolor=\"gray\">";
482
myMetadataQString += tr("General:");
483
myMetadataQString += "</td></tr>";
485
myMetadataQString += "<tr><td bgcolor=\"white\">";
487
QGis::VectorType vectorType = layer->vectorType();
489
if ( vectorType < 0 || vectorType > QGis::Polygon )
491
QgsDebug( "Invalid vector type" );
495
QString vectorTypeString( QGis::qgisVectorGeometryType[layer->vectorType()] );
498
const char* vectorTypeProbe = vectorTypeString.ascii(); // debugger probe point
501
myMetadataQString += tr("Geometry type of the features in this layer : ") +
503
myMetadataQString += "</td></tr>";
507
myMetadataQString += "<tr><td bgcolor=\"white\">";
508
myMetadataQString += tr("The number of features in this layer : ") +
509
QString::number(layer->featureCount());
510
myMetadataQString += "</td></tr>";
514
QgsRect myExtent = layer->extent();
515
myMetadataQString += "<tr><td bgcolor=\"gray\">";
516
myMetadataQString += tr("Extents:");
517
myMetadataQString += "</td></tr>";
518
//extents in layer cs TODO...maybe make a little nested table to improve layout...
519
myMetadataQString += "<tr><td bgcolor=\"white\">";
520
myMetadataQString += tr("In layer spatial reference system units : ") +
522
QString::number(myExtent.xMin()) +
524
QString::number( myExtent.yMin()) +
525
tr(" : xMax,yMax ") +
526
QString::number(myExtent.xMax()) +
528
QString::number(myExtent.yMax());
529
myMetadataQString += "</td></tr>";
531
//extents in project cs
535
QgsCoordinateTransform * coordinateTransform = layer->coordinateTransform();
537
if ( ! coordinateTransform )
539
throw QgsCsException( string("unable to get layer coordinate transform object") );
542
QgsRect myProjectedExtent = coordinateTransform->transformBoundingBox(layer->extent());
543
myMetadataQString += "<tr><td bgcolor=\"white\">";
544
myMetadataQString += tr("In project spatial reference system units : ") +
546
QString::number(myProjectedExtent.xMin()) +
548
QString::number( myProjectedExtent.yMin()) +
549
tr(" : xMax,yMax ") +
550
QString::number(myProjectedExtent.xMax()) +
552
QString::number(myProjectedExtent.yMax());
553
myMetadataQString += "</td></tr>";
558
// Display layer spatial ref system
560
myMetadataQString += "<tr><td bgcolor=\"gray\">";
561
myMetadataQString += tr("Layer Spatial Reference System:");
562
myMetadataQString += "</td></tr>";
563
myMetadataQString += "<tr><td bgcolor=\"white\">";
564
myMetadataQString += coordinateTransform->sourceSRS().proj4String().replace(QRegExp("\"")," \"");
565
myMetadataQString += "</td></tr>";
568
// Display project (output) spatial ref system
570
myMetadataQString += "<tr><td bgcolor=\"gray\">";
571
myMetadataQString += tr("Project (Output) Spatial Reference System:");
572
myMetadataQString += "</td></tr>";
573
myMetadataQString += "<tr><td bgcolor=\"white\">";
574
myMetadataQString += coordinateTransform->destSRS().proj4String().replace(QRegExp("\"")," \"");
575
myMetadataQString += "</td></tr>";
578
catch(QgsCsException &cse)
580
QgsDebug( cse.what() );
582
myMetadataQString += "<tr><td bgcolor=\"white\">";
583
myMetadataQString += tr("In project spatial reference system units : ");
584
myMetadataQString += " (Invalid transformation of layer extents) ";
585
myMetadataQString += "</td></tr>";
591
// Add the info about each field in the attribute table
593
myMetadataQString += "<tr><td bgcolor=\"gray\">";
594
myMetadataQString += tr("Attribute field info:");
595
myMetadataQString += "</td></tr>";
596
myMetadataQString += "<tr><td bgcolor=\"white\">";
598
// Start a nested table in this trow
599
myMetadataQString += "<table width=\"100%\">";
600
myMetadataQString += "<tr><th bgcolor=\"black\">";
601
myMetadataQString += "<font color=\"white\">" + tr("Field") + "</font>";
602
myMetadataQString += "</th>";
603
myMetadataQString += "<th bgcolor=\"black\">";
604
myMetadataQString += "<font color=\"white\">" + tr("Type") + "</font>";
605
myMetadataQString += "</th>";
606
myMetadataQString += "<th bgcolor=\"black\">";
607
myMetadataQString += "<font color=\"white\">" + tr("Length") + "</font>";
608
myMetadataQString += "</th>";
609
myMetadataQString += "<th bgcolor=\"black\">";
610
myMetadataQString += "<font color=\"white\">" + tr("Precision") + "</font>";
611
myMetadataQString += "</th>";
612
myMetadataQString += "<tr>";
614
//get info for each field by looping through them
615
QgsVectorDataProvider *myDataProvider = dynamic_cast<QgsVectorDataProvider *>(layer->getDataProvider());
616
std::vector<QgsField> myFields = myDataProvider->fields();
617
for (int i = 0; i < myFields.size(); i++)
620
QgsField myField = myFields[i];
622
myMetadataQString += "<tr><td bgcolor=\"white\">";
623
myMetadataQString += myField.name();
624
myMetadataQString += "</td>";
625
myMetadataQString += "<td bgcolor=\"white\">";
626
myMetadataQString += myField.type();
627
myMetadataQString += "</td>";
628
myMetadataQString += "<td bgcolor=\"white\">";
629
myMetadataQString += QString("%1").arg(myField.length());
630
myMetadataQString += "</td>";
631
myMetadataQString += "<td bgcolor=\"white\">";
632
myMetadataQString += QString("%1").arg(myField.precision());
633
myMetadataQString += "</td></tr>";
637
myMetadataQString += "</table>"; //end of nested table
638
myMetadataQString += "</td></tr>"; //end of stats container table row
643
myMetadataQString += "</table>";
644
myMetadataQString += "</body></html>";
645
return myMetadataQString;
651
void QgsDlgVectorLayerProperties::pbnChangeSpatialRefSys_clicked()
655
QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector(this);
656
long myDefaultSRS =layer->coordinateTransform()->sourceSRS().srsid();
659
myDefaultSRS=QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectSRSID",GEOSRS_ID);
661
mySelector->setSelectedSRSID(myDefaultSRS);
662
if(mySelector->exec())
664
layer->coordinateTransform()->sourceSRS().createFromSrsId(mySelector->getCurrentSRSID());
665
layer->coordinateTransform()->initialise();
669
QApplication::restoreOverrideCursor();
672
leSpatialRefSys->setText(layer->coordinateTransform()->sourceSRS().proj4String());