forked from qgis/QGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mesh gui #13
Closed
Closed
Mesh gui #13
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
104e059
[mesh] Style contours/scalars in GUI
PeterPetrik 0b17970
[mesh] Select active dataset in GUI
PeterPetrik 24d9e7b
[mesh] Style mesh frame in GUI
PeterPetrik 709cb51
[mesh] Style vector arrows in GUI
PeterPetrik b960ba0
[mesh] basic mesh layer properties dialog
PeterPetrik a4bf276
add docs and cleanup includes
PeterPetrik 1a40476
move mesh files to app
PeterPetrik ff670e0
various code cleaning
PeterPetrik 17e2434
replace treewidget with treeview
PeterPetrik ec52aff
remember last used folder for adding datasets
PeterPetrik eebf9a1
update mesh renderer widgets when datasets are added
PeterPetrik cd78fbd
fix issues from review
PeterPetrik c94865d
fix coredump when opening properties panel
PeterPetrik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
/*************************************************************************** | ||
qgsmeshlayerproperties.cpp | ||
-------------------------- | ||
begin : Jun 2018 | ||
copyright : (C) 2018 by Peter Petrik | ||
email : zilolv at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include <limits> | ||
#include <typeinfo> | ||
|
||
#include "qgisapp.h" | ||
#include "qgsapplication.h" | ||
#include "qgscoordinatetransform.h" | ||
#include "qgshelp.h" | ||
#include "qgslogger.h" | ||
#include "qgsmapcanvas.h" | ||
#include "qgsmaplayerstylemanager.h" | ||
#include "qgsmeshlayer.h" | ||
#include "qgsmeshlayerproperties.h" | ||
#include "qgsproject.h" | ||
#include "qgsprojectionselectiondialog.h" | ||
#include "qgsrenderermeshpropertieswidget.h" | ||
#include "qgssettings.h" | ||
|
||
#include <QFileDialog> | ||
|
||
QgsMeshLayerProperties::QgsMeshLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent, Qt::WindowFlags fl ) | ||
: QgsOptionsDialogBase( QStringLiteral( "MeshLayerProperties" ), parent, fl ) | ||
, mMeshLayer( qobject_cast<QgsMeshLayer *>( lyr ) ) | ||
{ | ||
setupUi( this ); | ||
mRendererMeshPropertiesWidget = new QgsRendererMeshPropertiesWidget( lyr, canvas, this ); | ||
mOptsPage_StyleContent->layout()->addWidget( mRendererMeshPropertiesWidget ); | ||
|
||
connect( mLayerOrigNameLineEd, &QLineEdit::textEdited, this, &QgsMeshLayerProperties::updateLayerName ); | ||
connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsMeshLayerProperties::changeCrs ); | ||
connect( mAddDatasetButton, &QPushButton::clicked, this, &QgsMeshLayerProperties::addDataset ); | ||
|
||
// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states, | ||
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left), | ||
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots | ||
initOptionsBase( false ); | ||
|
||
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsMeshLayerProperties::showHelp ); | ||
connect( lyr->styleManager(), &QgsMapLayerStyleManager::currentStyleChanged, this, &QgsMeshLayerProperties::syncAndRepaint ); | ||
|
||
connect( this, &QDialog::accepted, this, &QgsMeshLayerProperties::apply ); | ||
connect( this, &QDialog::rejected, this, &QgsMeshLayerProperties::onCancel ); | ||
|
||
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsMeshLayerProperties::apply ); | ||
|
||
if ( !mMeshLayer ) | ||
{ | ||
return; | ||
} | ||
|
||
// update based on lyr's current state | ||
syncToLayer(); | ||
|
||
QgsSettings settings; | ||
// if dialog hasn't been opened/closed yet, default to Styles tab, which is used most often | ||
// this will be read by restoreOptionsBaseUi() | ||
if ( !settings.contains( QStringLiteral( "/Windows/MeshLayerProperties/tab" ) ) ) | ||
{ | ||
settings.setValue( QStringLiteral( "Windows/MeshLayerProperties/tab" ), | ||
mOptStackedWidget->indexOf( mOptsPage_Style ) ); | ||
} | ||
|
||
QString title = QString( tr( "Layer Properties - %1" ) ).arg( lyr->name() ); | ||
|
||
if ( !mMeshLayer->styleManager()->isDefault( mMeshLayer->styleManager()->currentStyle() ) ) | ||
title += QStringLiteral( " (%1)" ).arg( mMeshLayer->styleManager()->currentStyle() ); | ||
restoreOptionsBaseUi( title ); | ||
} | ||
|
||
void QgsMeshLayerProperties::syncToLayer() | ||
{ | ||
Q_ASSERT( mRendererMeshPropertiesWidget ); | ||
|
||
QgsDebugMsg( "populate general information tab" ); | ||
/* | ||
* Information Tab | ||
*/ | ||
QString info; | ||
if ( mMeshLayer && mMeshLayer->dataProvider() ) | ||
{ | ||
info += QStringLiteral( "<table>" ); | ||
info += QStringLiteral( "<tr><td>%1</td><td>%2</td><tr>" ).arg( tr( "Uri" ) ).arg( mMeshLayer->dataProvider()->dataSourceUri() ); | ||
info += QStringLiteral( "<tr><td>%1</td><td>%2</td><tr>" ).arg( tr( "Vertex count" ) ).arg( mMeshLayer->dataProvider()->vertexCount() ); | ||
info += QStringLiteral( "<tr><td>%1</td><td>%2</td><tr>" ).arg( tr( "Face count" ) ).arg( mMeshLayer->dataProvider()->faceCount() ); | ||
info += QStringLiteral( "<tr><td>%1</td><td>%2</td><tr>" ).arg( tr( "Dataset count" ) ).arg( mMeshLayer->dataProvider()->datasetCount() ); | ||
info += QStringLiteral( "</table>" ); | ||
} | ||
else | ||
{ | ||
info += tr( "Invalid data provider" ); | ||
} | ||
mInformationTextBrowser->setText( info ); | ||
|
||
QgsDebugMsg( "populate source tab" ); | ||
/* | ||
* Source Tab | ||
*/ | ||
mLayerOrigNameLineEd->setText( mMeshLayer->name() ); | ||
leDisplayName->setText( mMeshLayer->name() ); | ||
|
||
if ( mMeshLayer && mMeshLayer->dataProvider() ) | ||
{ | ||
mUriLabel->setText( mMeshLayer->dataProvider()->dataSourceUri() ); | ||
} | ||
else | ||
{ | ||
mUriLabel->setText( tr( "Not assigned" ) ); | ||
} | ||
|
||
QgsDebugMsg( "populate styling tab" ); | ||
/* | ||
* Styling Tab | ||
*/ | ||
mRendererMeshPropertiesWidget->syncToLayer(); | ||
|
||
} | ||
|
||
void QgsMeshLayerProperties::addDataset() | ||
{ | ||
if ( !mMeshLayer || !mMeshLayer->dataProvider() ) | ||
return; | ||
|
||
QString fileName = QFileDialog::getOpenFileName( this ); | ||
if ( !fileName.isEmpty() ) | ||
{ | ||
bool ok = mMeshLayer->dataProvider()->addDataset( fileName ); | ||
QgsDebugMsg( QStringLiteral( "Dataset added %1, %2" ).arg( fileName ).arg( ok ) ); | ||
if ( ok ) | ||
syncToLayer(); | ||
} | ||
} | ||
|
||
void QgsMeshLayerProperties::apply() | ||
{ | ||
Q_ASSERT( mRendererMeshPropertiesWidget ); | ||
|
||
QgsDebugMsg( "processing general tab" ); | ||
/* | ||
* General Tab | ||
*/ | ||
mMeshLayer->setName( mLayerOrigNameLineEd->text() ); | ||
|
||
QgsDebugMsg( "processing style tab" ); | ||
/* | ||
* Style Tab | ||
*/ | ||
mRendererMeshPropertiesWidget->apply(); | ||
|
||
//make sure the layer is redrawn | ||
mMeshLayer->triggerRepaint(); | ||
|
||
// notify the project we've made a change | ||
QgsProject::instance()->setDirty( true ); | ||
} | ||
|
||
void QgsMeshLayerProperties::onCancel() | ||
{ | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove? |
||
|
||
void QgsMeshLayerProperties::changeCrs( const QgsCoordinateReferenceSystem &crs ) | ||
{ | ||
if ( mMeshLayer ) | ||
mMeshLayer->setCrs( crs ); | ||
} | ||
|
||
void QgsMeshLayerProperties::updateLayerName( const QString &text ) | ||
{ | ||
leDisplayName->setText( mMeshLayer->formatLayerName( text ) ); | ||
} | ||
|
||
void QgsMeshLayerProperties::syncAndRepaint() | ||
{ | ||
syncToLayer(); | ||
mMeshLayer->triggerRepaint(); | ||
} | ||
|
||
void QgsMeshLayerProperties::showHelp() | ||
{ | ||
QgsHelp::openHelp( QStringLiteral( "working_with_mesh/mesh_properties.html" ) ); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better not to implement this (yet) if the page does not exist |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about we only expect QgsMeshLayer in constructor? should be safer and we would not need to test "if ( mMeshLayer )" in various places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( mMeshLayer )
is in the code because of pointer in the constuctor, not because of type cast to mesh layer. Do we want to replace it with reference?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until now probably everywhere in qgis code we use pointers to map layers, so i would keep that for consistency. Maybe just add Q_ASSERT( mMeshLayer ) to the constructor?