Skip to content
Permalink
Browse files

Move and unify scaleIconSize into QgsApplication::scaleIconSize

  • Loading branch information
nirvn committed Oct 15, 2020
1 parent 76cfbab commit 060750420220ae304ce37a7d1015d0c89a567294
@@ -935,6 +935,17 @@ Do not include generated variables (like system name, user name etc.)
Set a single custom expression variable.

.. versionadded:: 3.0
%End

static int scaleIconSize( int standardSize );
%Docstring
Scales an icon size to compensate for display pixel density, making the icon
size hi-dpi friendly, whilst still resulting in pixel-perfect sizes for low-dpi
displays.

``standardSize`` should be set to a standard icon size, e.g. 16, 24, 48, etc.

.. versionadded:: 3.16
%End

int maxConcurrentConnectionsPerPool() const;
@@ -13,18 +13,16 @@
* *
***************************************************************************/

#include <QApplication>
#include <QDesktopWidget>
#include <QMimeData>
#include <QTextStream>

#include "qgslayertreemodel.h"

#include "qgsapplication.h"
#include "qgslayertree.h"
#include "qgslayertreeutils.h"
#include "qgslayertreemodellegendnode.h"
#include "qgsproject.h"
#include "qgsapplication.h"
#include "qgsdataitem.h"
#include "qgsmaphittest.h"
#include "qgsmaplayer.h"
@@ -723,12 +721,7 @@ void QgsLayerTreeModel::setLayerStyleOverrides( const QMap<QString, QString> &ov

int QgsLayerTreeModel::scaleIconSize( int standardSize )
{
QFontMetrics fm( ( QFont() ) );
const double scale = 1.1 * standardSize / 24;
int scaledIconSize = static_cast< int >( std::floor( std::max( Qgis::UI_SCALE_FACTOR * fm.height() * scale, static_cast< double >( standardSize ) ) ) );
if ( QApplication::desktop() )
scaledIconSize *= QApplication::desktop()->devicePixelRatio();
return scaledIconSize;
return QgsApplication::scaleIconSize( standardSize );
}

void QgsLayerTreeModel::nodeWillAddChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo )
@@ -75,6 +75,8 @@

#include "layout/qgspagesizeregistry.h"

#include <QApplication>
#include <QDesktopWidget>
#include <QDir>
#include <QFile>
#include <QFileInfo>
@@ -1276,7 +1278,6 @@ void QgsApplication::initQgis()

}


QgsAuthManager *QgsApplication::authManager()
{
if ( auto *lInstance = instance() )
@@ -1821,6 +1822,16 @@ void QgsApplication::setCustomVariable( const QString &name, const QVariant &val
emit instance()->customVariablesChanged();
}

int QgsApplication::scaleIconSize( int standardSize )
{
QFontMetrics fm( ( QFont() ) );
const double scale = 1.1 * standardSize / 24;
int scaledIconSize = static_cast< int >( std::floor( std::max( Qgis::UI_SCALE_FACTOR * fm.height() * scale, static_cast< double >( standardSize ) ) ) );
if ( QApplication::desktop() )
scaledIconSize *= QApplication::desktop()->devicePixelRatio();
return scaledIconSize;
}

int QgsApplication::maxConcurrentConnectionsPerPool() const
{
return CONN_POOL_MAX_CONCURRENT_CONNS;
@@ -871,6 +871,17 @@ class CORE_EXPORT QgsApplication : public QApplication
*/
static void setCustomVariable( const QString &name, const QVariant &value );

/**
* Scales an icon size to compensate for display pixel density, making the icon
* size hi-dpi friendly, whilst still resulting in pixel-perfect sizes for low-dpi
* displays.
*
* \a standardSize should be set to a standard icon size, e.g. 16, 24, 48, etc.
*
* \since QGIS 3.16
*/
static int scaleIconSize( int standardSize );

/**
* The maximum number of concurrent connections per connections pool.
*
@@ -14,6 +14,7 @@
***************************************************************************/
#include "qgsguiutils.h"

#include "qgsapplication.h"
#include "qgssettings.h"
#include "qgsencodingfiledialog.h"
#include "qgslogger.h"
@@ -243,9 +244,7 @@ namespace QgsGuiUtils

int scaleIconSize( int standardSize )
{
QFontMetrics fm( ( QFont() ) );
const double scale = 1.1 * standardSize / 24;
return static_cast< int >( std::floor( std::max( Qgis::UI_SCALE_FACTOR * fm.height() * scale, static_cast< double >( standardSize ) ) ) );
return QgsApplication::scaleIconSize( standardSize );
}

QSize iconSize( bool dockableToolbar )

0 comments on commit 0607504

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