mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Code formatting changes only
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8744 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
b9726a2ddc
commit
14f861c2b7
@ -47,7 +47,7 @@ QgsMapToolIdentify::QgsMapToolIdentify(QgsMapCanvas* canvas)
|
||||
QPixmap myIdentifyQPixmap = QPixmap((const char **) identify_cursor);
|
||||
mCursor = QCursor(myIdentifyQPixmap, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
QgsMapToolIdentify::~QgsMapToolIdentify()
|
||||
{
|
||||
if (mResults)
|
||||
@ -61,7 +61,7 @@ QgsMapToolIdentify::~QgsMapToolIdentify()
|
||||
void QgsMapToolIdentify::canvasMoveEvent(QMouseEvent * e)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QgsMapToolIdentify::canvasPressEvent(QMouseEvent * e)
|
||||
{
|
||||
}
|
||||
@ -69,12 +69,12 @@ void QgsMapToolIdentify::canvasPressEvent(QMouseEvent * e)
|
||||
void QgsMapToolIdentify::canvasReleaseEvent(QMouseEvent * e)
|
||||
{
|
||||
if(!mCanvas || mCanvas->isDrawing())
|
||||
{
|
||||
return;
|
||||
}
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsMapLayer* layer = mCanvas->currentLayer();
|
||||
|
||||
|
||||
// delete rubber band if there was any
|
||||
delete mRubberBand;
|
||||
mRubberBand = 0;
|
||||
@ -119,11 +119,11 @@ void QgsMapToolIdentify::canvasReleaseEvent(QMouseEvent * e)
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(mCanvas,
|
||||
QObject::tr("No active layer"),
|
||||
QObject::tr("To identify features, you must choose an active layer by clicking on its name in the legend"));
|
||||
QObject::tr("No active layer"),
|
||||
QObject::tr("To identify features, you must choose an active layer by clicking on its name in the legend"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -131,10 +131,10 @@ void QgsMapToolIdentify::identifyRasterLayer(QgsRasterLayer* layer, const QgsPoi
|
||||
{
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
|
||||
QMap<QString, QString> attributes;
|
||||
layer->identify(point, attributes);
|
||||
|
||||
|
||||
if(!mResults)
|
||||
{
|
||||
QgsAttributeAction aa;
|
||||
@ -179,9 +179,9 @@ void QgsMapToolIdentify::identifyRasterWmsLayer(QgsRasterLayer* layer, const Qgs
|
||||
QgsRect viewExtent = mCanvas->extent();
|
||||
double mupp = mCanvas->mupp();
|
||||
if(mupp == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
{
|
||||
return;
|
||||
}
|
||||
double xMinView = viewExtent.xMin();
|
||||
double yMaxView = viewExtent.yMax();
|
||||
|
||||
@ -192,26 +192,26 @@ void QgsMapToolIdentify::identifyRasterWmsLayer(QgsRasterLayer* layer, const Qgs
|
||||
double i, j;
|
||||
|
||||
if(xMinView < xMinLayer)
|
||||
{
|
||||
i = (int)(point.x() - (xMinLayer - xMinView) / mupp);
|
||||
}
|
||||
{
|
||||
i = (int)(point.x() - (xMinLayer - xMinView) / mupp);
|
||||
}
|
||||
else
|
||||
{
|
||||
i = point.x();
|
||||
}
|
||||
{
|
||||
i = point.x();
|
||||
}
|
||||
|
||||
if(yMaxView > yMaxLayer)
|
||||
{
|
||||
j = (int)(point.y() - (yMaxView - yMaxLayer) / mupp);
|
||||
}
|
||||
{
|
||||
j = (int)(point.y() - (yMaxView - yMaxLayer) / mupp);
|
||||
}
|
||||
else
|
||||
{
|
||||
j = point.y();
|
||||
}
|
||||
|
||||
{
|
||||
j = point.y();
|
||||
}
|
||||
|
||||
|
||||
QString text = layer->identifyAsText(QgsPoint(i, j));
|
||||
|
||||
|
||||
if (text.isEmpty())
|
||||
{
|
||||
showError(layer);
|
||||
@ -229,7 +229,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
{
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
|
||||
// load identify radius from settings
|
||||
QSettings settings;
|
||||
double identifyValue = settings.value("/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS).toDouble();
|
||||
@ -237,13 +237,13 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
|
||||
// create the search rectangle
|
||||
double searchRadius = mCanvas->extent().width() * (identifyValue/100.0);
|
||||
|
||||
|
||||
QgsRect r;
|
||||
r.setXmin(point.x() - searchRadius);
|
||||
r.setXmax(point.x() + searchRadius);
|
||||
r.setYmin(point.y() - searchRadius);
|
||||
r.setYmax(point.y() + searchRadius);
|
||||
|
||||
|
||||
r = toLayerCoords(layer, r);
|
||||
|
||||
int featureCount = 0;
|
||||
@ -258,104 +258,104 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
calc.setProjectionsEnabled(mCanvas->projectionsEnabled()); // project?
|
||||
calc.setEllipsoid(ellipsoid);
|
||||
calc.setSourceSRS(layer->srs().srsid());
|
||||
|
||||
|
||||
// display features falling within the search radius
|
||||
if(!mResults)
|
||||
{
|
||||
mResults = new QgsIdentifyResults(actions, mCanvas->window());
|
||||
mResults->setAttribute(Qt::WA_DeleteOnClose);
|
||||
// Be informed when the dialog box is closed so that we can stop using it.
|
||||
connect(mResults, SIGNAL(accepted()), this, SLOT(resultsDialogGone()));
|
||||
connect(mResults, SIGNAL(rejected()), this, SLOT(resultsDialogGone()));
|
||||
connect(mResults, SIGNAL(selectedFeatureChanged(int)), this, SLOT(highlightFeature(int)));
|
||||
// restore the identify window position and show it
|
||||
mResults->restorePosition();
|
||||
}
|
||||
{
|
||||
mResults = new QgsIdentifyResults(actions, mCanvas->window());
|
||||
mResults->setAttribute(Qt::WA_DeleteOnClose);
|
||||
// Be informed when the dialog box is closed so that we can stop using it.
|
||||
connect(mResults, SIGNAL(accepted()), this, SLOT(resultsDialogGone()));
|
||||
connect(mResults, SIGNAL(rejected()), this, SLOT(resultsDialogGone()));
|
||||
connect(mResults, SIGNAL(selectedFeatureChanged(int)), this, SLOT(highlightFeature(int)));
|
||||
// restore the identify window position and show it
|
||||
mResults->restorePosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
mResults->raise();
|
||||
mResults->clear();
|
||||
mResults->setActions(actions);
|
||||
}
|
||||
|
||||
{
|
||||
mResults->raise();
|
||||
mResults->clear();
|
||||
mResults->setActions(actions);
|
||||
}
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
|
||||
int lastFeatureId = 0;
|
||||
|
||||
|
||||
QList<QgsFeature> featureList;
|
||||
layer->featuresInRectangle(r, featureList, true, true);
|
||||
QList<QgsFeature>::iterator f_it = featureList.begin();
|
||||
|
||||
|
||||
for(; f_it != featureList.end(); ++f_it)
|
||||
{
|
||||
featureCount++;
|
||||
|
||||
QTreeWidgetItem* featureNode = mResults->addNode("foo");
|
||||
featureNode->setData(0, Qt::UserRole, QVariant(f_it->featureId())); // save feature id
|
||||
lastFeatureId = f_it->featureId();
|
||||
featureNode->setText(0, fieldIndex);
|
||||
const QgsAttributeMap& attr = f_it->attributeMap();
|
||||
|
||||
for (QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it)
|
||||
{
|
||||
//QgsDebugMsg(it->fieldName() + " == " + fieldIndex);
|
||||
|
||||
if (fields[it.key()].name() == fieldIndex)
|
||||
{
|
||||
featureCount++;
|
||||
|
||||
QTreeWidgetItem* featureNode = mResults->addNode("foo");
|
||||
featureNode->setData(0, Qt::UserRole, QVariant(f_it->featureId())); // save feature id
|
||||
lastFeatureId = f_it->featureId();
|
||||
featureNode->setText(0, fieldIndex);
|
||||
const QgsAttributeMap& attr = f_it->attributeMap();
|
||||
|
||||
for (QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it)
|
||||
{
|
||||
//QgsDebugMsg(it->fieldName() + " == " + fieldIndex);
|
||||
|
||||
if (fields[it.key()].name() == fieldIndex)
|
||||
{
|
||||
featureNode->setText(1, it->toString());
|
||||
}
|
||||
mResults->addAttribute(featureNode, fields[it.key()].name(), it->isNull() ? "NULL" : it->toString());
|
||||
}
|
||||
|
||||
// Calculate derived attributes and insert:
|
||||
// measure distance or area depending on geometry type
|
||||
if (layer->vectorType() == QGis::Line)
|
||||
{
|
||||
double dist = calc.measure(f_it->geometry());
|
||||
QString str = calc.textUnit(dist, 3, mCanvas->mapUnits(), false);
|
||||
mResults->addDerivedAttribute(featureNode, QObject::tr("Length"), str);
|
||||
}
|
||||
else if (layer->vectorType() == QGis::Polygon)
|
||||
{
|
||||
double area = calc.measure(f_it->geometry());
|
||||
QString str = calc.textUnit(area, 3, mCanvas->mapUnits(), true);
|
||||
mResults->addDerivedAttribute(featureNode, QObject::tr("Area"), str);
|
||||
}
|
||||
|
||||
// Add actions
|
||||
QgsAttributeAction::aIter iter = actions.begin();
|
||||
for (register int i = 0; iter != actions.end(); ++iter, ++i)
|
||||
{
|
||||
mResults->addAction( featureNode, i, QObject::tr("action"), iter->name() );
|
||||
}
|
||||
|
||||
featureNode->setText(1, it->toString());
|
||||
}
|
||||
|
||||
QgsDebugMsg("Feature count on identify: " + QString::number(featureCount));
|
||||
|
||||
//also test the not commited features //todo: eliminate copy past code
|
||||
|
||||
mResults->setTitle(layer->name() + " - " + QString::number(featureCount) + QObject::tr(" features found"));
|
||||
if (featureCount == 1)
|
||||
{
|
||||
mResults->showAllAttributes();
|
||||
mResults->setTitle(layer->name() + " - " + QObject::tr(" 1 feature found") );
|
||||
highlightFeature(lastFeatureId);
|
||||
}
|
||||
else if (featureCount == 0)
|
||||
{
|
||||
mResults->setTitle(layer->name() + " - " + QObject::tr("No features found") );
|
||||
mResults->setMessage ( QObject::tr("No features found"), QObject::tr("No features were found in the active layer at the point you clicked") );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString title = layer->name();
|
||||
title += QString( tr("- %1 features found","Identify results window title",featureCount) ).arg(featureCount);
|
||||
mResults->setTitle(title);
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
mResults->show();
|
||||
mResults->addAttribute(featureNode, fields[it.key()].name(), it->isNull() ? "NULL" : it->toString());
|
||||
}
|
||||
|
||||
// Calculate derived attributes and insert:
|
||||
// measure distance or area depending on geometry type
|
||||
if (layer->vectorType() == QGis::Line)
|
||||
{
|
||||
double dist = calc.measure(f_it->geometry());
|
||||
QString str = calc.textUnit(dist, 3, mCanvas->mapUnits(), false);
|
||||
mResults->addDerivedAttribute(featureNode, QObject::tr("Length"), str);
|
||||
}
|
||||
else if (layer->vectorType() == QGis::Polygon)
|
||||
{
|
||||
double area = calc.measure(f_it->geometry());
|
||||
QString str = calc.textUnit(area, 3, mCanvas->mapUnits(), true);
|
||||
mResults->addDerivedAttribute(featureNode, QObject::tr("Area"), str);
|
||||
}
|
||||
|
||||
// Add actions
|
||||
QgsAttributeAction::aIter iter = actions.begin();
|
||||
for (register int i = 0; iter != actions.end(); ++iter, ++i)
|
||||
{
|
||||
mResults->addAction( featureNode, i, QObject::tr("action"), iter->name() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QgsDebugMsg("Feature count on identify: " + QString::number(featureCount));
|
||||
|
||||
//also test the not commited features //todo: eliminate copy past code
|
||||
|
||||
mResults->setTitle(layer->name() + " - " + QString::number(featureCount) + QObject::tr(" features found"));
|
||||
if (featureCount == 1)
|
||||
{
|
||||
mResults->showAllAttributes();
|
||||
mResults->setTitle(layer->name() + " - " + QObject::tr(" 1 feature found") );
|
||||
highlightFeature(lastFeatureId);
|
||||
}
|
||||
else if (featureCount == 0)
|
||||
{
|
||||
mResults->setTitle(layer->name() + " - " + QObject::tr("No features found") );
|
||||
mResults->setMessage ( QObject::tr("No features found"), QObject::tr("No features were found in the active layer at the point you clicked") );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString title = layer->name();
|
||||
title += QString( tr("- %1 features found","Identify results window title",featureCount) ).arg(featureCount);
|
||||
mResults->setTitle(title);
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
mResults->show();
|
||||
}
|
||||
|
||||
#if 0 //MH: old state of the function
|
||||
@ -363,7 +363,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
{
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
|
||||
// load identify radius from settings
|
||||
QSettings settings;
|
||||
double identifyValue = settings.value("/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS).toDouble();
|
||||
@ -371,13 +371,13 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
|
||||
// create the search rectangle
|
||||
double searchRadius = mCanvas->extent().width() * (identifyValue/100.0);
|
||||
|
||||
|
||||
QgsRect r;
|
||||
r.setXmin(point.x() - searchRadius);
|
||||
r.setXmax(point.x() + searchRadius);
|
||||
r.setYmin(point.y() - searchRadius);
|
||||
r.setYmax(point.y() + searchRadius);
|
||||
|
||||
|
||||
r = toLayerCoords(layer, r);
|
||||
|
||||
int featureCount = 0;
|
||||
@ -387,7 +387,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
QgsVectorDataProvider* dataProvider = layer->getDataProvider();
|
||||
QgsAttributeList allAttributes = dataProvider->allAttributesList();
|
||||
const QgsFieldMap& fields = dataProvider->fields();
|
||||
|
||||
|
||||
dataProvider->select(allAttributes, r, true, true);
|
||||
|
||||
// init distance/area calculator
|
||||
@ -395,7 +395,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
calc.setProjectionsEnabled(mCanvas->projectionsEnabled()); // project?
|
||||
calc.setEllipsoid(ellipsoid);
|
||||
calc.setSourceSRS(layer->srs().srsid());
|
||||
|
||||
|
||||
if ( !layer->isEditable() )
|
||||
{
|
||||
// display features falling within the search radius
|
||||
@ -418,7 +418,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
}
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
|
||||
int lastFeatureId = 0;
|
||||
|
||||
QTreeWidgetItem *click = mResults->addNode(tr("(clicked coordinate)"));
|
||||
@ -433,11 +433,11 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
lastFeatureId = feat.featureId();
|
||||
featureNode->setText(0, fieldIndex);
|
||||
const QgsAttributeMap& attr = feat.attributeMap();
|
||||
|
||||
|
||||
for (QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it)
|
||||
{
|
||||
//QgsDebugMsg(it->fieldName() + " == " + fieldIndex);
|
||||
|
||||
|
||||
if (fields[it.key()].name() == fieldIndex)
|
||||
{
|
||||
featureNode->setText(1, it->toString());
|
||||
@ -500,7 +500,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
// Edit attributes
|
||||
// TODO: what to do if more features were selected? - nearest?
|
||||
QgsChangedAttributesMap& changedAttributes = layer->changedAttributes();
|
||||
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
if (dataProvider->getNextFeature(feat))
|
||||
@ -563,9 +563,9 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
QMessageBox::information(0, tr("No features found"),
|
||||
tr("<p>No features were found within the search radius. "
|
||||
"Note that it is currently not possible to use the "
|
||||
"identify tool on unsaved features.</p>"));
|
||||
tr("<p>No features were found within the search radius. "
|
||||
"Note that it is currently not possible to use the "
|
||||
"identify tool on unsaved features.</p>"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -574,26 +574,26 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
||||
|
||||
void QgsMapToolIdentify::showError(QgsMapLayer * mapLayer)
|
||||
{
|
||||
// QMessageBox::warning(
|
||||
// this,
|
||||
// mapLayer->errorCaptionString(),
|
||||
// tr("Could not draw") + " " + mapLayer->name() + " " + tr("because") + ":\n" +
|
||||
// mapLayer->errorString()
|
||||
// );
|
||||
// QMessageBox::warning(
|
||||
// this,
|
||||
// mapLayer->errorCaptionString(),
|
||||
// tr("Could not draw") + " " + mapLayer->name() + " " + tr("because") + ":\n" +
|
||||
// mapLayer->errorString()
|
||||
// );
|
||||
|
||||
QgsMessageViewer * mv = new QgsMessageViewer();
|
||||
mv->setWindowTitle( mapLayer->errorCaptionString() );
|
||||
mv->setMessageAsPlainText(
|
||||
QObject::tr("Could not identify objects on") + " " + mapLayer->name() + " " + QObject::tr("because") + ":\n" +
|
||||
mapLayer->errorString()
|
||||
);
|
||||
QObject::tr("Could not identify objects on") + " " + mapLayer->name() + " " + QObject::tr("because") + ":\n" +
|
||||
mapLayer->errorString()
|
||||
);
|
||||
mv->exec(); // deletes itself on close
|
||||
}
|
||||
|
||||
void QgsMapToolIdentify::resultsDialogGone()
|
||||
{
|
||||
mResults = 0;
|
||||
|
||||
|
||||
delete mRubberBand;
|
||||
mRubberBand = 0;
|
||||
}
|
||||
@ -610,23 +610,23 @@ void QgsMapToolIdentify::highlightFeature(int featureId)
|
||||
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>(mCanvas->currentLayer());
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
|
||||
delete mRubberBand;
|
||||
mRubberBand = 0;
|
||||
|
||||
QgsFeature feat;
|
||||
if(layer->getFeatureAtId(featureId, feat, true, false) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!feat.geometry())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mRubberBand = new QgsRubberBand(mCanvas, feat.geometry()->vectorType() == QGis::Polygon);
|
||||
|
||||
|
||||
if (mRubberBand)
|
||||
{
|
||||
mRubberBand->setToGeometry(feat.geometry(), *layer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user