2005-01-23 09:49:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
qgsdelattrdialog.cpp - description
|
|
|
|
-------------------
|
|
|
|
begin : January 2005
|
|
|
|
copyright : (C) 2005 by Marco Hugentobler
|
|
|
|
email : marco.hugentobler@autoform.ch
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2014-09-25 22:48:26 +02:00
|
|
|
#include "qgsapplication.h"
|
2005-01-23 09:49:30 +00:00
|
|
|
#include "qgsdelattrdialog.h"
|
2016-09-22 07:57:13 +02:00
|
|
|
#include "qgsfields.h"
|
2014-09-25 22:48:26 +02:00
|
|
|
#include "qgsvectordataprovider.h"
|
2009-10-28 13:27:15 +00:00
|
|
|
#include "qgsvectorlayer.h"
|
2017-03-03 20:39:17 +01:00
|
|
|
#include "qgssettings.h"
|
2014-05-25 22:15:34 +10:00
|
|
|
|
2017-03-03 08:42:00 +01:00
|
|
|
QgsDelAttrDialog::QgsDelAttrDialog( const QgsVectorLayer *vl )
|
2005-01-23 09:49:30 +00:00
|
|
|
{
|
2008-08-23 21:37:31 +00:00
|
|
|
setupUi( this );
|
2009-10-28 13:27:15 +00:00
|
|
|
if ( vl )
|
2008-08-23 21:37:31 +00:00
|
|
|
{
|
2014-09-25 22:48:26 +02:00
|
|
|
bool canDeleteAttributes = vl->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteAttributes;
|
2008-08-23 21:37:31 +00:00
|
|
|
listBox2->clear();
|
2017-03-03 08:42:00 +01:00
|
|
|
const QgsFields &layerAttributes = vl->fields();
|
2012-10-20 22:19:55 +02:00
|
|
|
for ( int idx = 0; idx < layerAttributes.count(); ++idx )
|
2005-01-23 09:49:30 +00:00
|
|
|
{
|
2017-03-03 08:42:00 +01:00
|
|
|
QListWidgetItem *item = new QListWidgetItem( layerAttributes.at( idx ).name(), listBox2 );
|
2015-08-01 23:15:09 +02:00
|
|
|
switch ( vl->fields().fieldOrigin( idx ) )
|
2014-09-25 22:48:26 +02:00
|
|
|
{
|
|
|
|
case QgsFields::OriginExpression:
|
2016-10-23 08:30:26 +10:00
|
|
|
item->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconExpression.svg" ) ) );
|
2014-09-25 22:48:26 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QgsFields::OriginJoin:
|
2016-10-23 08:30:26 +10:00
|
|
|
item->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/join.png" ) ) );
|
2014-09-25 22:48:26 +02:00
|
|
|
item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-10-23 08:30:26 +10:00
|
|
|
item->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/attributes.png" ) ) );
|
2014-09-25 22:48:26 +02:00
|
|
|
if ( !vl->isEditable() || !canDeleteAttributes )
|
|
|
|
item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-20 22:19:55 +02:00
|
|
|
item->setData( Qt::UserRole, idx );
|
2005-01-23 09:49:30 +00:00
|
|
|
}
|
2014-09-25 22:48:26 +02:00
|
|
|
|
|
|
|
mEditModeInfo->setVisible( !vl->isEditable() );
|
|
|
|
mCanDeleteAttributesInfo->setVisible( !canDeleteAttributes );
|
2008-08-23 21:37:31 +00:00
|
|
|
}
|
2014-05-25 22:15:34 +10:00
|
|
|
|
2017-03-03 20:39:17 +01:00
|
|
|
QgsSettings settings;
|
2017-03-08 11:11:47 +01:00
|
|
|
restoreGeometry( settings.value( QStringLiteral( "Windows/QgsDelAttrDialog/geometry" ) ).toByteArray() );
|
2014-05-25 22:15:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
QgsDelAttrDialog::~QgsDelAttrDialog()
|
|
|
|
{
|
2017-03-03 20:39:17 +01:00
|
|
|
QgsSettings settings;
|
2017-03-08 11:11:47 +01:00
|
|
|
settings.setValue( QStringLiteral( "Windows/QgsDelAttrDialog/geometry" ), saveGeometry() );
|
2005-01-23 09:49:30 +00:00
|
|
|
}
|
|
|
|
|
2009-10-28 13:27:15 +00:00
|
|
|
QList<int> QgsDelAttrDialog::selectedAttributes()
|
2005-01-23 09:49:30 +00:00
|
|
|
{
|
2009-10-28 13:27:15 +00:00
|
|
|
QList<int> selectionList;
|
|
|
|
QList<QListWidgetItem *> selection = listBox2->selectedItems();
|
|
|
|
QList<QListWidgetItem *>::const_iterator itemIter = selection.constBegin();
|
|
|
|
for ( ; itemIter != selection.constEnd(); ++itemIter )
|
2008-08-23 21:37:31 +00:00
|
|
|
{
|
2017-03-03 08:42:00 +01:00
|
|
|
selectionList.push_back( ( *itemIter )->data( Qt::UserRole ).toInt() );
|
2008-08-23 21:37:31 +00:00
|
|
|
}
|
2009-10-28 13:27:15 +00:00
|
|
|
return selectionList;
|
2005-01-23 09:49:30 +00:00
|
|
|
}
|