Skip to content

Commit

Permalink
move QgsHighlight style setting in a static method (#10064)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed May 23, 2019
1 parent 1802c52 commit f0f0790
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 61 deletions.
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsidentifymenu.sip.in
Expand Up @@ -146,6 +146,13 @@ exec

:param idResults: the list of identify results to choose within
:param pos: the position where the menu will be executed
%End

static void styleHighlight( QgsHighlight *highlight );
%Docstring
Applies style from the settings to the highlight

.. versionadded:: 3.8
%End

protected:
Expand Down
72 changes: 32 additions & 40 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -16,6 +16,35 @@
* *
***************************************************************************/

#include <QCloseEvent>
#include <QLabel>
#include <QAction>
#include <QTreeWidgetItem>
#include <QPixmap>
#include <QMenu>
#include <QClipboard>
#include <QDesktopWidget>
#include <QMenuBar>
#include <QPushButton>
#include <QPrinter>
#include <QPrintDialog>
#include <QDesktopServices>
#include <QMessageBox>
#include <QComboBox>
#include <QTextDocument>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QFileDialog>
#include <QFileInfo>
#include <QRegExp>

//graph
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#include <qwt_legend.h>
#include "qgscolorramp.h" // for random colors

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsactionmanager.h"
Expand Down Expand Up @@ -50,35 +79,8 @@
#include "qgssettings.h"
#include "qgsgui.h"
#include "qgsexpressioncontextutils.h"
#include "qgsidentifymenu.h"

#include <QCloseEvent>
#include <QLabel>
#include <QAction>
#include <QTreeWidgetItem>
#include <QPixmap>
#include <QMenu>
#include <QClipboard>
#include <QDesktopWidget>
#include <QMenuBar>
#include <QPushButton>
#include <QPrinter>
#include <QPrintDialog>
#include <QDesktopServices>
#include <QMessageBox>
#include <QComboBox>
#include <QTextDocument>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QFileDialog>
#include <QFileInfo>
#include <QRegExp>

//graph
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#include <qwt_legend.h>
#include "qgscolorramp.h" // for random colors

QgsIdentifyResultsWebView::QgsIdentifyResultsWebView( QWidget *parent ) : QgsWebView( parent )
{
Expand Down Expand Up @@ -1807,17 +1809,7 @@ void QgsIdentifyResultsDialog::highlightFeature( QTreeWidgetItem *item )
highlight->setWidth( 2 );
}

QgsSettings settings;
QColor color = QColor( settings.value( QStringLiteral( "Map/highlight/color" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() );
int alpha = settings.value( QStringLiteral( "Map/highlight/colorAlpha" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt();
double buffer = settings.value( QStringLiteral( "Map/highlight/buffer" ), Qgis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble();
double minWidth = settings.value( QStringLiteral( "Map/highlight/minWidth" ), Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble();

highlight->setColor( color ); // sets also fill with default alpha
color.setAlpha( alpha );
highlight->setFillColor( color ); // sets fill with alpha
highlight->setBuffer( buffer );
highlight->setMinWidth( minWidth );
QgsIdentifyMenu::styleHighlight( highlight );
highlight->show();
mHighlights.insert( featItem, highlight );
}
Expand Down Expand Up @@ -2119,7 +2111,7 @@ void QgsIdentifyResultsDialog::formatChanged( int index )
return;
}

QgsRaster::IdentifyFormat format = ( QgsRaster::IdentifyFormat ) combo->itemData( index, Qt::UserRole ).toInt();
QgsRaster::IdentifyFormat format = static_cast<QgsRaster::IdentifyFormat>( combo->itemData( index, Qt::UserRole ).toInt() );
QgsDebugMsg( QStringLiteral( "format = %1" ).arg( format ) );
QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( combo->itemData( index, Qt::UserRole + 1 ).value<QObject *>() );
if ( !layer )
Expand Down
14 changes: 3 additions & 11 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -42,6 +42,8 @@
#include "qgsfeaturelistcombobox.h"
#include "qgsexpressioncontextutils.h"
#include "qgsfeaturefiltermodel.h"
#include "qgsidentifymenu.h"


QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget *parent )
: QWidget( parent )
Expand Down Expand Up @@ -636,17 +638,7 @@ void QgsRelationReferenceWidget::highlightFeature( QgsFeature f, CanvasExtent ca
// highlight
deleteHighlight();
mHighlight = new QgsHighlight( mCanvas, f, mReferencedLayer );
QgsSettings settings;
QColor color = QColor( settings.value( QStringLiteral( "Map/highlight/color" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() );
int alpha = settings.value( QStringLiteral( "Map/highlight/colorAlpha" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt();
double buffer = settings.value( QStringLiteral( "Map/highlight/buffer" ), Qgis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble();
double minWidth = settings.value( QStringLiteral( "Map/highlight/minWidth" ), Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble();

mHighlight->setColor( color ); // sets also fill with default alpha
color.setAlpha( alpha );
mHighlight->setFillColor( color ); // sets fill with alpha
mHighlight->setBuffer( buffer );
mHighlight->setMinWidth( minWidth );
QgsIdentifyMenu::styleHighlight( mHighlight );
mHighlight->show();

QTimer *timer = new QTimer( this );
Expand Down
26 changes: 16 additions & 10 deletions src/gui/qgsidentifymenu.cpp
Expand Up @@ -617,21 +617,27 @@ void QgsIdentifyMenu::handleMenuHover()
continue;

QgsHighlight *hl = new QgsHighlight( mCanvas, result.mFeature.geometry(), vl );
QgsSettings settings;
QColor color = QColor( settings.value( QStringLiteral( "Map/highlight/color" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() );
int alpha = settings.value( QStringLiteral( "Map/highlight/colorAlpha" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt();
double buffer = settings.value( QStringLiteral( "Map/highlight/buffer" ), Qgis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble();
double minWidth = settings.value( QStringLiteral( "Map/highlight/minWidth" ), Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble();
hl->setColor( color ); // sets also fill with default alpha
color.setAlpha( alpha );
hl->setFillColor( color ); // sets fill with alpha
hl->setBuffer( buffer );
hl->setMinWidth( minWidth );
styleHighlight( hl );
mRubberBands.append( hl );
connect( vl, &QObject::destroyed, this, &QgsIdentifyMenu::layerDestroyed );
}
}

void QgsIdentifyMenu::styleHighlight( QgsHighlight *highlight )
{
QgsSettings settings;
QColor color = QColor( settings.value( QStringLiteral( "Map/highlight/color" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() );
int alpha = settings.value( QStringLiteral( "Map/highlight/colorAlpha" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt();
double buffer = settings.value( QStringLiteral( "Map/highlight/buffer" ), Qgis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble();
double minWidth = settings.value( QStringLiteral( "Map/highlight/minWidth" ), Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble();

highlight->setColor( color ); // sets also fill with default alpha
color.setAlpha( alpha );
highlight->setFillColor( color ); // sets fill with alpha
highlight->setBuffer( buffer );
highlight->setMinWidth( minWidth );
}

void QgsIdentifyMenu::deleteRubberBands()
{
QList<QgsHighlight *>::const_iterator it = mRubberBands.constBegin();
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsidentifymenu.h
Expand Up @@ -160,6 +160,13 @@ class GUI_EXPORT QgsIdentifyMenu : public QMenu
*/
QList<QgsMapToolIdentify::IdentifyResult> exec( const QList<QgsMapToolIdentify::IdentifyResult> &idResults, QPoint pos );

/**
* Applies style from the settings to the highlight
*
* \since QGIS 3.8
*/
static void styleHighlight( QgsHighlight *highlight );

protected:
void closeEvent( QCloseEvent *e ) override;

Expand Down

0 comments on commit f0f0790

Please sign in to comment.