mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-16 00:05:45 -04:00
Add styleSheetType to application reportStyleSheet
This commit is contained in:
parent
a57aff35b1
commit
1bc7ece06a
@ -76,6 +76,12 @@ to change due to centralization.
|
|||||||
%End
|
%End
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
enum StyleSheetType
|
||||||
|
{
|
||||||
|
Qt,
|
||||||
|
WebBrowser,
|
||||||
|
};
|
||||||
|
|
||||||
static const char *QGIS_ORGANIZATION_NAME;
|
static const char *QGIS_ORGANIZATION_NAME;
|
||||||
static const char *QGIS_ORGANIZATION_DOMAIN;
|
static const char *QGIS_ORGANIZATION_DOMAIN;
|
||||||
static const char *QGIS_APPLICATION_NAME;
|
static const char *QGIS_APPLICATION_NAME;
|
||||||
@ -503,20 +509,23 @@ Gets application icon
|
|||||||
Returns whether this machine uses big or little endian
|
Returns whether this machine uses big or little endian
|
||||||
%End
|
%End
|
||||||
|
|
||||||
static QString reportStyleSheet();
|
static QString reportStyleSheet( const StyleSheetType &styleSheetType = StyleSheetType::Qt );
|
||||||
%Docstring
|
%Docstring
|
||||||
Returns a standard css style sheet for reports.
|
Returns a css style sheet for reports, the ``styleSheetType`` argument
|
||||||
|
determines what type of stylesheet is supported by the widget.
|
||||||
|
|
||||||
Typically you will use this method by doing:
|
Typically you will use this method by doing:
|
||||||
QString myStyle = QgsApplication.reportStyleSheet();
|
QString myStyle = QgsApplication.reportStyleSheet();
|
||||||
textBrowserReport->document()->setDefaultStyleSheet(myStyle);
|
textBrowserReport->document()->setDefaultStyleSheet(myStyle);
|
||||||
|
if you are using a QgsWebView you will need to manually inject
|
||||||
|
the CSS into a <head><script> tag instead.
|
||||||
|
|
||||||
:return: QString containing the CSS 2.1 compliant stylesheet.
|
:return: the stylesheet CSS rules.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
you can use the special Qt extensions too, for example
|
if styleSheetType equals StyleSheetType.Qt you can use the special Qt extensions too,
|
||||||
the gradient fills for backgrounds.
|
for example the gradient fills for backgrounds.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
static QString showSettings();
|
static QString showSettings();
|
||||||
|
@ -2060,20 +2060,7 @@ bool QgsRasterLayerProperties::rasterIsMultiBandColor()
|
|||||||
|
|
||||||
void QgsRasterLayerProperties::updateInformationContent()
|
void QgsRasterLayerProperties::updateInformationContent()
|
||||||
{
|
{
|
||||||
// We are using QgsWebView and the renderer is completely different from QTextBrowser
|
const QString myStyle = QgsApplication::reportStyleSheet( QgsApplication::StyleSheetType::WebBrowser );
|
||||||
// add some extra style here
|
|
||||||
QString myStyle = QgsApplication::reportStyleSheet();
|
|
||||||
myStyle.append( QStringLiteral( "body { margin: auto; width: 97% } "
|
|
||||||
"table.tabular-view, table.list-view { border-collapse: collapse; table-layout:fixed; width: 100% !important; } "
|
|
||||||
"h1 { line-height: inherit; } "
|
|
||||||
"td, th { word-wrap: break-word; vertical-align: top; } "
|
|
||||||
".list-view th:first-child, .list-view td:first-child { width: 15%; } "
|
|
||||||
".list-view.highlight { padding-left: inherit; } "
|
|
||||||
".tabular-view th:first-child, .tabular-view td:first-child { width: 20%; } "
|
|
||||||
".tabular-view th.strong { background-color: #eee; }"
|
|
||||||
".tabular-view th, .tabular-view td { "
|
|
||||||
" border: solid 1px #eee;"
|
|
||||||
"} \n " ) );
|
|
||||||
// Inject the stylesheet
|
// Inject the stylesheet
|
||||||
const QString html { mRasterLayer->htmlMetadata().replace( QStringLiteral( "<head>" ), QStringLiteral( R"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
|
const QString html { mRasterLayer->htmlMetadata().replace( QStringLiteral( "<head>" ), QStringLiteral( R"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
|
||||||
mMetadataViewer->setHtml( html );
|
mMetadataViewer->setHtml( html );
|
||||||
|
@ -1309,7 +1309,7 @@ QString QgsApplication::showSettings()
|
|||||||
return myState;
|
return myState;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsApplication::reportStyleSheet()
|
QString QgsApplication::reportStyleSheet( const StyleSheetType &styleSheetType )
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Make the style sheet desktop preferences aware by using qappliation
|
// Make the style sheet desktop preferences aware by using qappliation
|
||||||
@ -1376,9 +1376,13 @@ QString QgsApplication::reportStyleSheet()
|
|||||||
" padding: 0px 3px; "
|
" padding: 0px 3px; "
|
||||||
" font-size: small;"
|
" font-size: small;"
|
||||||
"}"
|
"}"
|
||||||
".section {"
|
"th .strong {"
|
||||||
" font-weight: bold;"
|
" font-weight: bold;"
|
||||||
" padding-top:25px;"
|
"}"
|
||||||
|
"hr {"
|
||||||
|
" border: 0;"
|
||||||
|
" height: 0;"
|
||||||
|
" border-top: 1px solid black;"
|
||||||
"}"
|
"}"
|
||||||
".list-view .highlight {"
|
".list-view .highlight {"
|
||||||
" text-align: right;"
|
" text-align: right;"
|
||||||
@ -1388,24 +1392,68 @@ QString QgsApplication::reportStyleSheet()
|
|||||||
" padding-left: 20px;"
|
" padding-left: 20px;"
|
||||||
" font-weight: bold;"
|
" font-weight: bold;"
|
||||||
"}"
|
"}"
|
||||||
"th .strong {"
|
".tabular-view .odd-row {"
|
||||||
" 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;"
|
" background-color: #f9f9f9;"
|
||||||
"}"
|
"}"
|
||||||
"hr {"
|
".section {"
|
||||||
" border: 0;"
|
" font-weight: bold;"
|
||||||
" height: 0;"
|
" padding-top:25px;"
|
||||||
" border-top: 1px solid black;"
|
|
||||||
"}" );
|
"}" );
|
||||||
|
|
||||||
|
// We have some subtle differences between Qt based style and QWebKit style
|
||||||
|
if ( styleSheetType == StyleSheetType::Qt )
|
||||||
|
{
|
||||||
|
myStyle += QStringLiteral(
|
||||||
|
".tabular-view{ "
|
||||||
|
" border-collapse: collapse;"
|
||||||
|
" width: 95%;"
|
||||||
|
"}"
|
||||||
|
".tabular-view th, .tabular-view td { "
|
||||||
|
" border:10px solid black;"
|
||||||
|
"}" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myStyle += QStringLiteral(
|
||||||
|
"body { "
|
||||||
|
" margin: auto;"
|
||||||
|
" width: 97%;"
|
||||||
|
"}"
|
||||||
|
"table.tabular-view, table.list-view { "
|
||||||
|
" border-collapse: collapse;"
|
||||||
|
" table-layout:fixed;"
|
||||||
|
" width: 100% !important;"
|
||||||
|
"}"
|
||||||
|
// Override
|
||||||
|
"h1 { "
|
||||||
|
" line-height: inherit;"
|
||||||
|
"}"
|
||||||
|
"td, th {"
|
||||||
|
" word-wrap: break-word; "
|
||||||
|
" vertical-align: top;"
|
||||||
|
"}"
|
||||||
|
// Set first column width
|
||||||
|
".list-view th:first-child, .list-view td:first-child {"
|
||||||
|
" width: 15%;"
|
||||||
|
"}"
|
||||||
|
".list-view.highlight { "
|
||||||
|
" padding-left: inherit; "
|
||||||
|
"}"
|
||||||
|
// Set first column width for inner tables
|
||||||
|
".tabular-view th:first-child, .tabular-view td:first-child { "
|
||||||
|
" width: 20%; "
|
||||||
|
"}"
|
||||||
|
// Makes titles bg stand up
|
||||||
|
".tabular-view th.strong { "
|
||||||
|
" background-color: #eee; "
|
||||||
|
"}"
|
||||||
|
// Give some visual appearance to those ugly nested tables
|
||||||
|
".tabular-view th, .tabular-view td { "
|
||||||
|
" border: solid 1px #eee;"
|
||||||
|
"}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return myStyle;
|
return myStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +126,20 @@ class CORE_EXPORT QgsApplication : public QApplication
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The StyleSheetType enum represents the stylesheet type that
|
||||||
|
* a widget supports.
|
||||||
|
*
|
||||||
|
* Is is used by widgets that display HTML content to retrieve
|
||||||
|
* the standard QGIS stylesheet, maintained according to QGIS
|
||||||
|
* visual guidelines.
|
||||||
|
*/
|
||||||
|
enum StyleSheetType
|
||||||
|
{
|
||||||
|
Qt, //! StyleSheet for Qt GUI widgets (based on QLabel or QTextBrowser), supports basic CSS and Qt extensions
|
||||||
|
WebBrowser, //! StyleSheet for embedded browsers (QtWebKit), supports full standard CSS
|
||||||
|
};
|
||||||
|
|
||||||
static const char *QGIS_ORGANIZATION_NAME;
|
static const char *QGIS_ORGANIZATION_NAME;
|
||||||
static const char *QGIS_ORGANIZATION_DOMAIN;
|
static const char *QGIS_ORGANIZATION_DOMAIN;
|
||||||
static const char *QGIS_APPLICATION_NAME;
|
static const char *QGIS_APPLICATION_NAME;
|
||||||
@ -463,17 +477,20 @@ class CORE_EXPORT QgsApplication : public QApplication
|
|||||||
static endian_t endian();
|
static endian_t endian();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a standard css style sheet for reports.
|
* Returns a css style sheet for reports, the \a styleSheetType argument
|
||||||
|
* determines what type of stylesheet is supported by the widget.
|
||||||
*
|
*
|
||||||
* Typically you will use this method by doing:
|
* Typically you will use this method by doing:
|
||||||
* QString myStyle = QgsApplication::reportStyleSheet();
|
* QString myStyle = QgsApplication::reportStyleSheet();
|
||||||
* textBrowserReport->document()->setDefaultStyleSheet(myStyle);
|
* textBrowserReport->document()->setDefaultStyleSheet(myStyle);
|
||||||
|
* if you are using a QgsWebView you will need to manually inject
|
||||||
|
* the CSS into a <head><script> tag instead.
|
||||||
*
|
*
|
||||||
* \returns QString containing the CSS 2.1 compliant stylesheet.
|
* \returns the stylesheet CSS rules.
|
||||||
* \note you can use the special Qt extensions too, for example
|
* \note if styleSheetType equals StyleSheetType::Qt you can use the special Qt extensions too,
|
||||||
* the gradient fills for backgrounds.
|
* for example the gradient fills for backgrounds.
|
||||||
*/
|
*/
|
||||||
static QString reportStyleSheet();
|
static QString reportStyleSheet( const StyleSheetType &styleSheetType = StyleSheetType::Qt );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience function to get a summary of the paths used in this
|
* Convenience function to get a summary of the paths used in this
|
||||||
|
Loading…
x
Reference in New Issue
Block a user