Skip to content
Permalink
Browse files

regroup 'Identify Layers' and 'Data Sources' in the same tab (project…

… properties)
  • Loading branch information
3nids committed Sep 3, 2018
1 parent b5aa65c commit 0ef33d805e021315fe187904dc5d0d6976922d84
@@ -24,6 +24,7 @@ QgsLayerCapabilitiesModel::QgsLayerCapabilitiesModel( QgsProject *project, QObje
: QSortFilterProxyModel( parent )
{
mNonIdentifiableLayers = project->nonIdentifiableLayers();
mRequiredLayers = project->requiredLayers();

const QMap<QString, QgsMapLayer *> &mapLayers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer *>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
@@ -71,6 +72,11 @@ QStringList QgsLayerCapabilitiesModel::nonIdentifiableLayers() const
return mNonIdentifiableLayers;
}

QSet<QgsMapLayer *> QgsLayerCapabilitiesModel::requiredLayers() const
{
return mRequiredLayers;
}

bool QgsLayerCapabilitiesModel::readOnly( QgsMapLayer *layer ) const
{
return mReadOnlyLayers.value( layer, true );
@@ -84,7 +90,7 @@ bool QgsLayerCapabilitiesModel::searchable( QgsMapLayer *layer ) const
int QgsLayerCapabilitiesModel::columnCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent );
return 4;
return 5;
}

QVariant QgsLayerCapabilitiesModel::headerData( int section, Qt::Orientation orientation, int role ) const
@@ -95,14 +101,31 @@ QVariant QgsLayerCapabilitiesModel::headerData( int section, Qt::Orientation ori
{
switch ( section )
{
case 0:
case LayerColumn:
return tr( "Layer" );
case 1:
case IdentifiableColumn:
return tr( "Identifiable" );
case 2:
case ReadOnlyColumn:
return tr( "Read-only" );
case 3:
case SearchableColumn:
return tr( "Searchable" );
case RequiredColumn:
return tr( "Required" );
default:
return QVariant();
}
}
if ( role == Qt::ToolTipRole )
{
switch ( section )
{
case LayerColumn:
case IdentifiableColumn:
case ReadOnlyColumn:
case SearchableColumn:
return QVariant();
case RequiredColumn:
return tr( "Layers which are protected from inadvertent removal from the project." );
default:
return QVariant();
}
@@ -158,6 +181,10 @@ Qt::ItemFlags QgsLayerCapabilitiesModel::flags( const QModelIndex &idx ) const
return nullptr;
}
}
else if ( idx.column() == RequiredColumn )
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable;
}
}
return nullptr;
}
@@ -243,6 +270,10 @@ QVariant QgsLayerCapabilitiesModel::data( const QModelIndex &idx, int role ) con
if ( layer->type() == QgsMapLayer::VectorLayer )
return mSearchableLayers.value( layer, true ) ? trueValue : falseValue;
}
else if ( idx.column() == RequiredColumn )
{
return mRequiredLayers.contains( layer ) ? trueValue : falseValue;
}
}
}

@@ -288,6 +319,17 @@ bool QgsLayerCapabilitiesModel::setData( const QModelIndex &index, const QVarian
return true;
}
}
else if ( index.column() == RequiredColumn )
{
bool required = value == Qt::Checked;
bool containsLayer = mRequiredLayers.contains( layer );
if ( containsLayer && !required )
mRequiredLayers.remove( layer );
if ( !containsLayer && required )
mRequiredLayers.insert( layer );
emit dataChanged( index, index );
return true;
}
}
}
return false;
@@ -35,14 +35,16 @@ class APP_EXPORT QgsLayerCapabilitiesModel : public QSortFilterProxyModel
LayerColumn = 0,
IdentifiableColumn,
ReadOnlyColumn,
SearchableColumn
SearchableColumn,
RequiredColumn,
};

QgsLayerCapabilitiesModel( QgsProject *project, QObject *parent = nullptr );

QgsLayerTreeModel *layerTreeModel() const;
void setLayerTreeModel( QgsLayerTreeModel *layerTreeModel );
QStringList nonIdentifiableLayers() const;
QSet<QgsMapLayer *> requiredLayers() const;
bool readOnly( QgsMapLayer *layer ) const;
bool searchable( QgsMapLayer *layer ) const;
QgsMapLayer *mapLayer( const QModelIndex &idx ) const;
@@ -70,6 +72,7 @@ class APP_EXPORT QgsLayerCapabilitiesModel : public QSortFilterProxyModel
QString mFilterText;
bool mShowSpatialLayersOnly = false;
QStringList mNonIdentifiableLayers;
QSet<QgsMapLayer *> mRequiredLayers;
QHash<QgsMapLayer *, bool> mReadOnlyLayers;
QHash<QgsMapLayer *, bool> mSearchableLayers;
QgsLayerTreeModel *mLayerTreeModel = nullptr;
@@ -875,7 +875,6 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::onGenerateTsFileButton );

projectionSelectorInitialized();
populateRequiredLayers();
restoreOptionsBaseUi();
restoreState();
}
@@ -1038,6 +1037,7 @@ void QgsProjectProperties::apply()
}

QgsProject::instance()->setNonIdentifiableLayers( mLayerCapabilitiesModel->nonIdentifiableLayers() );
QgsProject::instance()->setRequiredLayers( mLayerCapabilitiesModel->requiredLayers() );
const QMap<QString, QgsMapLayer *> &mapLayers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer *>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
{
@@ -1375,8 +1375,6 @@ void QgsProjectProperties::apply()
canvas->refresh();
}
QgisApp::instance()->mapOverviewCanvas()->refresh();

applyRequiredLayers();
}

void QgsProjectProperties::showProjectionsTab()
@@ -2287,40 +2285,6 @@ void QgsProjectProperties::showHelp()
QgsHelp::openHelp( link );
}

void QgsProjectProperties::populateRequiredLayers()
{
const QSet<QgsMapLayer *> requiredLayers = QgsProject::instance()->requiredLayers();
QStandardItemModel *model = new QStandardItemModel( mViewRequiredLayers );
QList<QgsLayerTreeLayer *> layers = QgsProject::instance()->layerTreeRoot()->findLayers();
std::sort( layers.begin(), layers.end(), []( QgsLayerTreeLayer * layer1, QgsLayerTreeLayer * layer2 ) { return layer1->name() < layer2->name(); } );
for ( const QgsLayerTreeLayer *l : layers )
{
QStandardItem *item = new QStandardItem( l->name() );
item->setCheckable( true );
item->setCheckState( requiredLayers.contains( l->layer() ) ? Qt::Checked : Qt::Unchecked );
item->setData( l->layerId() );
model->appendRow( item );
}

mViewRequiredLayers->setModel( model );
}

void QgsProjectProperties::applyRequiredLayers()
{
QSet<QgsMapLayer *> requiredLayers;
QAbstractItemModel *model = mViewRequiredLayers->model();
for ( int i = 0; i < model->rowCount(); ++i )
{
if ( model->data( model->index( i, 0 ), Qt::CheckStateRole ).toInt() == Qt::Checked )
{
QString layerId = model->data( model->index( i, 0 ), Qt::UserRole + 1 ).toString();
if ( QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId ) )
requiredLayers << layer;
}
}
QgsProject::instance()->setRequiredLayers( requiredLayers );
}

QMap< QString, QString > QgsProjectProperties::pageWidgetNameMap()
{
QMap< QString, QString > pageNames;
@@ -240,7 +240,4 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
void updateGuiForMapUnits();

void showHelp();

void populateRequiredLayers();
void applyRequiredLayers();
};

0 comments on commit 0ef33d8

Please sign in to comment.
You can’t perform that action at this time.