Skip to content

Commit

Permalink
Optimize WMS raster information
Browse files Browse the repository at this point in the history
Fixes #32213
  • Loading branch information
elpaso authored and nyalldawson committed Oct 26, 2019
1 parent d003adb commit f0640ee
Show file tree
Hide file tree
Showing 9 changed files with 703 additions and 661 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -14206,7 +14206,7 @@ void QgisApp::showLayerProperties( QgsMapLayer *mapLayer )
// Cannot use exec here due to raster transparency map tool:
// in order to pass focus to the canvas, the dialog needs to
// be hidden and shown in non-modal mode.
rasterLayerPropertiesDialog->setModal( true );
rasterLayerPropertiesDialog->setModal( false );
rasterLayerPropertiesDialog->show();
// Delete (later, for safety) since dialog cannot be reused without
// updating code
Expand Down
61 changes: 47 additions & 14 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -57,6 +57,7 @@
#include "qgssettings.h"
#include "qgsmaplayerlegend.h"
#include "qgsfileutils.h"
#include "qgswebview.h"

#include <QDesktopServices>
#include <QTableWidgetItem>
Expand All @@ -74,6 +75,7 @@
#include <QMouseEvent>
#include <QVector>
#include <QUrl>
#include <QWebFrame>

QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent, Qt::WindowFlags fl )
: QgsOptionsDialogBase( QStringLiteral( "RasterLayerProperties" ), parent, fl )
Expand Down Expand Up @@ -108,7 +110,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
// 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, &QgsRasterLayerProperties::showHelp );

mBtnStyle = new QPushButton( tr( "Style" ) );
Expand Down Expand Up @@ -437,6 +438,29 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
}
}

#ifdef WITH_QTWEBKIT
// Setup information tab
const int horizontalDpi = qApp->desktop()->screen()->logicalDpiX();
// Adjust zoom: text is ok, but HTML seems rather big at least on Linux/KDE
if ( horizontalDpi > 96 )
{
mMetadataViewer->setZoomFactor( mMetadataViewer->zoomFactor() * 0.9 );
}
mMetadataViewer->page()->setLinkDelegationPolicy( QWebPage::DelegateExternalLinks );
connect( mMetadataViewer->page(), &QWebPage::linkClicked, this, &QgsRasterLayerProperties::urlClicked );
mMetadataViewer->page()->setViewportSize( QSize( 200, 200 ) );
connect( mMetadataViewer->page(), &QWebPage::loadFinished, this, [ = ]
{
const auto frame { mMetadataViewer->page()->mainFrame() };
mMetadataViewer->page()->setViewportSize( QSize( 200, 200 ) );
//mMetadataViewer->resize( frame->contentsSize() );
} );
mMetadataViewer->page()->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
mMetadataViewer->page()->settings()->setAttribute( QWebSettings::JavascriptEnabled, true );
mMetadataViewer->page()->settings()->setAttribute( QWebSettings::LocalStorageEnabled, true );

#endif

mRenderTypeComboBox_currentIndexChanged( widgetIndex );

// update based on lyr's current state
Expand Down Expand Up @@ -773,13 +797,7 @@ void QgsRasterLayerProperties::sync()
* Metadata Tab
*/
//populate the metadata tab's text browser widget with gdal metadata info
QString myStyle = QgsApplication::reportStyleSheet();
myStyle.append( QStringLiteral( "body { margin: 10px; }\n " ) );
teMetadataViewer->document()->setDefaultStyleSheet( myStyle );
teMetadataViewer->setHtml( mRasterLayer->htmlMetadata() );
teMetadataViewer->setOpenLinks( false );
connect( teMetadataViewer, &QTextBrowser::anchorClicked, this, &QgsRasterLayerProperties::urlClicked );
mMetadataFilled = true;
updateInformationContent();

// WMS Name as layer short name
mLayerShortNameLineEdit->setText( mRasterLayer->shortName() );
Expand Down Expand Up @@ -1192,9 +1210,7 @@ void QgsRasterLayerProperties::buttonBuildPyramids_clicked()
// pixmapLegend->repaint();

//populate the metadata tab's text browser widget with gdal metadata info
QString myStyle = QgsApplication::reportStyleSheet();
teMetadataViewer->setHtml( mRasterLayer->htmlMetadata() );
teMetadataViewer->document()->setDefaultStyleSheet( myStyle );
updateInformationContent();
}

void QgsRasterLayerProperties::urlClicked( const QUrl &url )
Expand Down Expand Up @@ -1545,10 +1561,10 @@ void QgsRasterLayerProperties::optionsStackedWidget_CurrentChanged( int index )
}

if ( index == mOptStackedWidget->indexOf( mOptsPage_Information ) || !mMetadataFilled )
{
//set the metadata contents (which can be expensive)
teMetadataViewer->clear();
teMetadataViewer->setHtml( mRasterLayer->htmlMetadata() );
mMetadataFilled = true;
updateInformationContent();
}
}

void QgsRasterLayerProperties::pbnImportTransparentPixelValues_clicked()
Expand Down Expand Up @@ -2051,6 +2067,23 @@ bool QgsRasterLayerProperties::rasterIsMultiBandColor()
return mRasterLayer && nullptr != dynamic_cast<QgsMultiBandColorRenderer *>( mRasterLayer->renderer() );
}

void QgsRasterLayerProperties::updateInformationContent()
{
QString myStyle = QgsApplication::reportStyleSheet();
myStyle.append( QStringLiteral( "body { margin: 10px; } "
"table { border-collapse: collapse; } "
"td { word-wrap: break-word; } "
"table.list-view { table-layout:fixed; width: 95%; } "
"table.tabular-view { width: 100%; } "
".tabular-view th:first-child, .tabular-view td:first-child { width: 30%; } "
".tabular-view th, .tabular-view td { "
" border: none;"
"} \n " ) );
const QString html { mRasterLayer->htmlMetadata().replace( QStringLiteral( "<head>" ), QStringLiteral( R"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
mMetadataViewer->setHtml( html );
mMetadataFilled = true;
}

void QgsRasterLayerProperties::onCancel()
{
if ( mOldStyle.xmlData() != mRasterLayer->styleManager()->style( mRasterLayer->styleManager()->currentStyle() ).xmlData() )
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsrasterlayerproperties.h
Expand Up @@ -37,6 +37,7 @@ class QgsMetadataWidget;
class QgsRasterRenderer;
class QgsRasterRendererWidget;
class QgsRasterHistogramWidget;
class QgsWebView;

/**
* Property sheet for a raster map layer
Expand Down Expand Up @@ -188,6 +189,11 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private

bool rasterIsMultiBandColor();

/**
* Updates the information tab by reloading metadata
*/
void updateInformationContent();

void setupTransparencyTable( int nBands );

//! \brief Clear the current transparency table and populate the table with the correct types for current drawing mode and data type
Expand Down
8 changes: 4 additions & 4 deletions src/core/metadata/qgslayermetadataformatter.cpp
Expand Up @@ -37,14 +37,14 @@ QString QgsLayerMetadataFormatter::accessSectionHtml() const
{
if ( notFirstRow )
{
myMetadata += QLatin1String( "<br />" );
myMetadata += QStringLiteral( "<br />" );
}
myMetadata += QStringLiteral( "<strong>" ) + constraint.type + QStringLiteral( ": </strong>" ) + constraint.constraint;
notFirstRow = true;
}
myMetadata += QLatin1String( "</td></tr>\n" );
mMetadata.rights().join( QStringLiteral( "<br />" ) ) + QStringLiteral( "</td></tr>\n" );
myMetadata += QLatin1String( "</table>\n" );
mMetadata.rights().join( QStringLiteral( "<br />" ) );
myMetadata += QStringLiteral( "</td></tr>\n" );
myMetadata += QStringLiteral( "</table>\n" );
return myMetadata;
}

Expand Down
172 changes: 86 additions & 86 deletions src/core/qgsapplication.cpp
Expand Up @@ -1320,92 +1320,92 @@ QString QgsApplication::reportStyleSheet()
QColor myColor2 = myColor1;
myColor2 = myColor2.lighter( 110 ); //10% lighter
QString myStyle;
myStyle = ".overview{"
" font: 1.82em;"
" font-weight: bold;"
"}"
"body{"
" background: white;"
" color: black;"
" font-family: 'Lato', 'Ubuntu', 'Lucida Grande', 'Segoe UI', 'Arial', sans-serif;"
" width: 100%;"
"}"
"h1{ background-color: #F6F6F6;"
" color: #589632; " // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-size: x-large; "
" font-weight: normal;"
" background: none;"
" padding: 0.75em 0 0;"
" margin: 0;"
" line-height: 3em;"
"}"
"h2{ background-color: #F6F6F6;"
" color: #589632; " // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-size: medium; "
" font-weight: normal;"
" background: none;"
" padding: 0.75em 0 0;"
" margin: 0;"
" line-height: 1.1em;"
"}"
"h3{ background-color: #F6F6F6;"
" color: #93b023;" // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-weight: bold;"
" font-size: large;"
" text-align: right;"
" border-bottom: 5px solid #DCEB5C;"
"}"
"h4{ background-color: #F6F6F6;"
" color: #93b023;" // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-weight: bold;"
" font-size: medium;"
" text-align: right;"
"}"
"h5{ background-color: #F6F6F6;"
" color: #93b023;" // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-weight: bold;"
" font-size: small;"
" text-align: right;"
"}"
"a{ color: #729FCF;"
" font-family: arial,sans-serif;"
"}"
"label{ background-color: #FFFFCC;"
" border: 1px solid black;"
" margin: 1px;"
" padding: 0px 3px; "
" font-size: small;"
"}"
".section {"
" font-weight: bold;"
" padding-top:25px;"
"}"
".list-view .highlight {"
" text-align: right;"
" border: 0px;"
" width: 20%;"
" padding-right: 15px;"
" padding-left: 20px;"
" font-weight: bold;"
"}"
"th .strong {"
" font-weight: bold;"
"}"
".tabular-view{ "
" border-collapse: collapse;"
" width: 95%;"
"}"
".tabular-view th, .tabular-view td { "
" border:10px solid black;"
"}"
".tabular-view .odd-row{"
" background-color: #f9f9f9;"
"}"
"hr {"
" border: 0;"
" height: 0;"
" border-top: 1px solid black;"
"}";
myStyle = QStringLiteral( ".overview{"
" font: 1.82em;"
" font-weight: bold;"
"}"
"body{"
" background: white;"
" color: black;"
" font-family: 'Lato', 'Ubuntu', 'Lucida Grande', 'Segoe UI', 'Arial', sans-serif;"
" width: 100%;"
"}"
"h1{ background-color: #F6F6F6;"
" color: #589632; " // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-size: x-large; "
" font-weight: normal;"
" background: none;"
" padding: 0.75em 0 0;"
" margin: 0;"
" line-height: 3em;"
"}"
"h2{ background-color: #F6F6F6;"
" color: #589632; " // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-size: medium; "
" font-weight: normal;"
" background: none;"
" padding: 0.75em 0 0;"
" margin: 0;"
" line-height: 1.1em;"
"}"
"h3{ background-color: #F6F6F6;"
" color: #93b023;" // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-weight: bold;"
" font-size: large;"
" text-align: right;"
" border-bottom: 5px solid #DCEB5C;"
"}"
"h4{ background-color: #F6F6F6;"
" color: #93b023;" // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-weight: bold;"
" font-size: medium;"
" text-align: right;"
"}"
"h5{ background-color: #F6F6F6;"
" color: #93b023;" // from http://qgis.org/en/site/getinvolved/styleguide.html
" font-weight: bold;"
" font-size: small;"
" text-align: right;"
"}"
"a{ color: #729FCF;"
" font-family: arial,sans-serif;"
"}"
"label{ background-color: #FFFFCC;"
" border: 1px solid black;"
" margin: 1px;"
" padding: 0px 3px; "
" font-size: small;"
"}"
".section {"
" font-weight: bold;"
" padding-top:25px;"
"}"
".list-view .highlight {"
" text-align: right;"
" border: 0px;"
" width: 20%;"
" padding-right: 15px;"
" padding-left: 20px;"
" font-weight: bold;"
"}"
"th .strong {"
" font-weight: bold;"
"}"
".tabular-view{ "
" border-collapse: collapse;"
" width: 95%;"
"}"
".tabular-view th, .tabular-view td { "
" border:10px solid black;"
"}"
".tabular-view .odd-row{"
" background-color: #f9f9f9;"
"}"
"hr {"
" border: 0;"
" height: 0;"
" border-top: 1px solid black;"
"}" );
return myStyle;
}

Expand Down

0 comments on commit f0640ee

Please sign in to comment.