Skip to content
Permalink
Browse files

[mesh] fix showing group for files with just 1 dataset

  • Loading branch information
PeterPetrik authored and wonder-sk committed Jul 19, 2018
1 parent 52aa849 commit 3732decfeaf6775b2bd431251b8ef40335e775c1
@@ -257,8 +257,6 @@ void QgsMeshDatasetGroupTreeView::extractGroups()

void QgsMeshDatasetGroupTreeView::syncToLayer()
{
mActiveGroup = 0;

extractGroups();

mModel.setupModelData( mGroups );
@@ -271,6 +269,7 @@ void QgsMeshDatasetGroupTreeView::syncToLayer()

int QgsMeshDatasetGroupTreeView::setActiveGroupFromActiveDataset()
{
int group = -1;
// find active dataset
QgsMeshDatasetIndex activeDataset;
if ( mMeshLayer )
@@ -283,12 +282,18 @@ int QgsMeshDatasetGroupTreeView::setActiveGroupFromActiveDataset()
// find group that contains active dataset
if ( activeDataset.isValid() && activeDataset.group() < mGroups.size() )
{
mActiveGroup = activeDataset.group();
group = activeDataset.group();
}
else
else if ( !mGroups.empty() )
{
// not found, select first item
mActiveGroup = 0;
group = 0;
}

if ( mActiveGroup != group )
{
mActiveGroup = group;
emit activeGroupChanged();
}

return mActiveGroup;
@@ -50,25 +50,41 @@ QgsMeshDatasetIndex QgsMeshRendererActiveDatasetWidget::activeVectorDataset() co
return mActiveVectorDataset;
}

void QgsMeshRendererActiveDatasetWidget::onActiveGroupChanged()
void QgsMeshRendererActiveDatasetWidget::setSliderRange()
{
int datasetCount = mMeshLayer->dataProvider()->datasetCount( mDatasetGroupTreeView->activeGroup() );
int datasetCount = 1;
if ( mMeshLayer &&
mMeshLayer->dataProvider() )
datasetCount = mMeshLayer->dataProvider()->datasetCount( mDatasetGroupTreeView->activeGroup() );

mDatasetSlider->setMinimum( 0 );
mDatasetSlider->setMaximum( datasetCount - 1 );
mDatasetSlider->setValue( 0 );
}

void QgsMeshRendererActiveDatasetWidget::onActiveGroupChanged()
{
setSliderRange();

// keep the same timestep if possible
int val = mDatasetSlider->value();
if ( ( val < 0 ) || ( val > mDatasetSlider->maximum() ) )
val = 0;

mDatasetSlider->setValue( val );
onActiveDatasetChanged( val );
}

void QgsMeshRendererActiveDatasetWidget::onActiveDatasetChanged( int value )
{
int groupIndex = mDatasetGroupTreeView->activeGroup();
int datasetCount = mMeshLayer->dataProvider()->datasetCount( groupIndex );

mActiveScalarDataset = QgsMeshDatasetIndex();
mActiveVectorDataset = QgsMeshDatasetIndex();
QgsMeshDatasetIndex datasetIndex( groupIndex, value );

if ( datasetCount > value && mMeshLayer && mMeshLayer->dataProvider() )
if ( mMeshLayer &&
mMeshLayer->dataProvider() &&
mMeshLayer->dataProvider()->datasetCount( groupIndex ) > value )
{
const QgsMeshDatasetGroupMetadata meta = mMeshLayer->dataProvider()->datasetGroupMetadata( datasetIndex );
mActiveScalarDataset = datasetIndex;
@@ -86,7 +102,9 @@ void QgsMeshRendererActiveDatasetWidget::onActiveDatasetChanged( int value )

void QgsMeshRendererActiveDatasetWidget::updateMetadata( QgsMeshDatasetIndex datasetIndex )
{
if ( !datasetIndex.isValid() )
if ( !mMeshLayer ||
!mMeshLayer->dataProvider() ||
!datasetIndex.isValid() )
{
mActiveDatasetMetadata->setText( tr( "No dataset selected" ) );
}
@@ -140,7 +158,7 @@ QgsMeshDatasetIndex QgsMeshRendererActiveDatasetWidget::datasetIndex() const

void QgsMeshRendererActiveDatasetWidget::syncToLayer()
{
mDatasetGroupTreeView->syncToLayer();
whileBlocking( mDatasetGroupTreeView )->syncToLayer();

if ( mMeshLayer )
{
@@ -153,6 +171,11 @@ void QgsMeshRendererActiveDatasetWidget::syncToLayer()
mActiveVectorDataset = QgsMeshDatasetIndex();
}

int val = 0;
if ( mActiveScalarDataset.isValid() )
whileBlocking( mDatasetSlider )->setValue( mActiveScalarDataset.dataset() );
val = mActiveScalarDataset.dataset();
mDatasetSlider->setValue( val );

setSliderRange();
onActiveDatasetChanged( val );
}
@@ -74,6 +74,7 @@ class APP_EXPORT QgsMeshRendererActiveDatasetWidget : public QWidget, private Ui

private:
QgsMeshDatasetIndex datasetIndex() const;
void setSliderRange();

QgsMeshLayer *mMeshLayer = nullptr; // not owned
QgsMeshDatasetIndex mActiveScalarDataset;
@@ -222,10 +222,10 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
QgsMeshRendererScalarSettings mRendererScalarSettings;
QgsMeshRendererVectorSettings mRendererVectorSettings;

//! index of active scalar dataset; -1 if none
//! index of active scalar dataset
QgsMeshDatasetIndex mActiveScalarDataset;

//! index of active vector dataset; -1 if none
//! index of active vector dataset
QgsMeshDatasetIndex mActiveVectorDataset;
};

0 comments on commit 3732dec

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