Skip to content
Permalink
Browse files

more complete QgsMessageBarItem: inherits from QWidget to allow furth…

…er editing
  • Loading branch information
3nids authored and NathanW2 committed Aug 15, 2013
1 parent 69d80b9 commit 45aa1dafa7cb403ae568f8cef4eb1b53acf59523
@@ -51,6 +51,7 @@
%Include qgsmaptooltouch.sip
%Include qgsmaptoolzoom.sip
%Include qgsmessagebar.sip
%Include qgsmessagebaritem.sip
%Include qgsmessagelogviewer.sip
%Include qgsmessageviewer.sip
%Include qgsnewhttpconnection.sip
@@ -15,41 +15,49 @@ class QgsMessageBar: QFrame
QgsMessageBar( QWidget *parent = 0 );
~QgsMessageBar();

/*! display a widget on the bar after hiding the currently visible one
* and putting it in a stack
* @param widget widget to add

/*! display a message item on the bar after hiding the currently visible one
* and putting it in a stack.
* @param item item to display
*/
void pushItem( QgsMessageBarItem *item /Transfer/);

/*! display a widget as a message on the bar after hiding the currently visible one
* and putting it in a stack.
* @param widget message widget to display
* @param level is QgsMessageBar::INFO, WARNING or CRITICAL
* @param duration timeout duration of message in seconds, 0 value indicates no timeout
*/
void pushWidget( QWidget *widget /Transfer/, MessageLevel level = INFO, int duration = 0 );
QgsMessageBarItem *pushWidget( QWidget *widget /Transfer/, MessageLevel level = INFO, int duration = 0 );

/*! remove the passed widget from the bar (if previously added),
* then display the next one in the stack if any or hide the bar
* @param widget widget to remove
* @return true if the widget was removed, false otherwise
*/
bool popWidget( QWidget *widget );
bool popWidget( QgsMessageBarItem *item );

//! make out a widget containing a message to be displayed on the bar
static QWidget* createMessage( const QString &text, QWidget *parent = 0 ) /Factory/;
//! make out a widget containing icon and message to be displayed on the bar
static QWidget* createMessage( const QString &text, const QIcon &icon, QWidget *parent = 0 ) /Factory/;
//make out a widget containing a message to be displayed on the bar
static QgsMessageBarItem* createMessage( const QString &text, QWidget *parent = 0 ) /Factory/;
//! make out a widget containing title and message to be displayed on the bar
static QWidget* createMessage( const QString &title, const QString &text, QWidget *parent = 0 ) /Factory/;
//! make out a widget containing icon, title and message to be displayed on the bar
static QWidget* createMessage( const QString &title, const QString &text, const QIcon &icon, QWidget *parent = 0 ) /Factory/;

static QgsMessageBarItem* createMessage( const QString &title, const QString &text, QWidget *parent = 0 ) /Factory/;
//! make out a widget containing title and message to be displayed on the bar
static QgsMessageBarItem* createMessage( QWidget *widget, QWidget *parent = 0 ) /Factory/;
//! convenience method for pushing a non-widget-based message to the bar
void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 0 );
QString pushMessage( const QString &text, MessageLevel level = INFO, int duration = 0 );
//! convenience method for pushing a non-widget-based message with title to the bar
void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 );
QString pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 );

//! return the item for given uuid if the item still exists, 0 otherwise
QgsMessageBarItem* itemAtId( QString uuid );

signals:
//! emitted when a message widget is added to the bar
void widgetAdded( QWidget *widget );
void widgetAdded( QgsMessageBarItem *item );

//! emitted when a widget was removed from the bar
void widgetRemoved( QWidget *widget );
void widgetRemoved( QgsMessageBarItem *item );

public slots:
/*! remove the currently displayed widget from the bar and
@@ -0,0 +1,49 @@
class QgsMessageBarItem: QWidget
{
%TypeHeaderCode
#include <qgsmessagebaritem.h>
#include <qgsmessagebar.h>
%End

public:
//! make out a widget containing a message to be displayed on the bar
QgsMessageBarItem( const QString &text, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO, int duration = 0, QWidget *parent = 0 );

//! make out a widget containing title and message to be displayed on the bar
QgsMessageBarItem( const QString &title, const QString &text, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO, int duration = 0, QWidget *parent = 0 );

//! make out a widget containing title, message and widget to be displayed on the bar
QgsMessageBarItem( const QString &title, const QString &text, QWidget *widget, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO, int duration = 0, QWidget *parent = 0 );

//! make out a widget containing a widget to be displayed on the bar
QgsMessageBarItem( QWidget *widget, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO, int duration = 0, QWidget *parent = 0 );

QgsMessageBarItem *setText( QString text );

QgsMessageBarItem *setTitle( QString title );

QgsMessageBarItem *setLevel( QgsMessageBar::MessageLevel level );

QgsMessageBarItem *setWidget( QWidget *widget );

QgsMessageBarItem *setIcon( const QIcon &icon );

QgsMessageBarItem *setDuration( int duration );

//! returns the duration in second of the message
int duration();

//! get the uuid of this message
QString id();

//! returns the level
QgsMessageBar::MessageLevel level();

//! returns the styleSheet
QString getStyleSheet();

signals:
//! emitted when the message level has changed
void styleChanged( QString styleSheet );
};

@@ -147,6 +147,7 @@
#include "qgsmergeattributesdialog.h"
#include "qgsmessageviewer.h"
#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"
#include "qgsmimedatautils.h"
#include "qgsmessagelog.h"
#include "qgsmultibandcolorrenderer.h"
@@ -2923,8 +2924,8 @@ void QgisApp::addDatabaseLayers( QStringList const & layerPathList, QString cons
QLabel *msgLabel = new QLabel( tr( "%1 is an invalid layer and cannot be loaded. Please check the <a href=\"#messageLog\">message log</a> for further info." ).arg( layerPath ), messageBar() );
msgLabel->setWordWrap( true );
connect( msgLabel, SIGNAL( linkActivated( QString ) ), mLogDock, SLOT( show() ) );
messageBar()->pushWidget( msgLabel,
QgsMessageBar::WARNING );
QgsMessageBarItem *item = new QgsMessageBarItem( msgLabel, QgsMessageBar::WARNING );
messageBar()->pushItem( item );
delete layer;
}
//qWarning("incrementing iterator");
@@ -3590,22 +3591,24 @@ bool QgisApp::addProject( QString projectFile )
{
// create the notification widget for macros

QWidget *macroMsg = QgsMessageBar::createMessage( tr( "Security warning" ),
tr( "project macros have been disabled." ),
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
mInfoBar );

QToolButton *btnEnableMacros = new QToolButton( macroMsg );
QToolButton *btnEnableMacros = new QToolButton();
btnEnableMacros->setText( tr( "Enable macros" ) );
btnEnableMacros->setStyleSheet( "background-color: rgba(255, 255, 255, 0); color: black; text-decoration: underline;" );
btnEnableMacros->setCursor( Qt::PointingHandCursor );
btnEnableMacros->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
connect( btnEnableMacros, SIGNAL( clicked() ), mInfoBar, SLOT( popWidget() ) );
connect( btnEnableMacros, SIGNAL( clicked() ), this, SLOT( enableProjectMacros() ) );
macroMsg->layout()->addWidget( btnEnableMacros );

QgsMessageBarItem *macroMsg = new QgsMessageBarItem(
tr( "Security warning" ),
tr( "project macros have been disabled." ),
btnEnableMacros,
QgsMessageBar::WARNING,
0,
mInfoBar );
// display the macros notification widget
mInfoBar->pushWidget( macroMsg, QgsMessageBar::WARNING );
mInfoBar->pushItem( macroMsg );
}
}
}
@@ -4214,66 +4217,63 @@ void QgisApp::labelingFontNotFound( QgsVectorLayer* vlayer, const QString& fontf
// TODO: update when pref for how to resolve missing family (use matching algorithm or just default font) is implemented
QString substitute = tr( "Default system font substituted." );

QWidget* fontMsg = QgsMessageBar::createMessage(
tr( "Labeling" ),
tr( "Font for layer <b><u>%1</u></b> was not found (<i>%2</i>). %3" ).arg( vlayer->name() ).arg( fontfamily ).arg( substitute ),
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
messageBar() );

QToolButton* btnOpenPrefs = new QToolButton( fontMsg );
QToolButton* btnOpenPrefs = new QToolButton();
btnOpenPrefs->setStyleSheet( "QToolButton{ background-color: rgba(255, 255, 255, 0); color: black; text-decoration: underline; }" );
btnOpenPrefs->setCursor( Qt::PointingHandCursor );
btnOpenPrefs->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
btnOpenPrefs->setToolButtonStyle( Qt::ToolButtonTextOnly );

// store pointer to vlayer in data of QAction
QAction* act = new QAction( fontMsg );
QAction* act = new QAction( btnOpenPrefs );
act->setData( QVariant( QMetaType::QObjectStar, &vlayer ) );
act->setText( tr( "Open labeling dialog" ) );
btnOpenPrefs->addAction( act );
btnOpenPrefs->setDefaultAction( act );
btnOpenPrefs->setToolTip( "" );

connect( btnOpenPrefs, SIGNAL( triggered( QAction* ) ), this, SLOT( labelingDialogFontNotFound( QAction* ) ) );
fontMsg->layout()->addWidget( btnOpenPrefs );

// no timeout set, since notice needs attention and is only shown first time layer is labeled
messageBar()->pushWidget( fontMsg, QgsMessageBar::WARNING );
QgsMessageBarItem* fontMsg = new QgsMessageBarItem(
tr( "Labeling" ),
tr( "Font for layer <b><u>%1</u></b> was not found (<i>%2</i>). %3" ).arg( vlayer->name() ).arg( fontfamily ).arg( substitute ),
btnOpenPrefs,
QgsMessageBar::WARNING,
0,
messageBar() );
messageBar()->pushItem( fontMsg );
}

void QgisApp::commitError( QgsVectorLayer* vlayer )
{
QWidget *errorMsg = QgsMessageBar::createMessage(
tr( "Commit errors" ),
tr( "Could not commit changes to layer %1" ).arg( vlayer->name() ),
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
messageBar() );

QgsMessageViewer *mv = new QgsMessageViewer( errorMsg );
QgsMessageViewer *mv = new QgsMessageViewer();
mv->setWindowTitle( tr( "Commit errors" ) );
mv->setMessageAsPlainText( tr( "Could not commit changes to layer %1" ).arg( vlayer->name() )
+ "\n\n"
+ tr( "Errors: %1\n" ).arg( vlayer->commitErrors().join( "\n " ) )
);

QToolButton *showMore = new QToolButton();
// store pointer to vlayer in data of QAction
QAction *act = new QAction( errorMsg );
QAction *act = new QAction( showMore );
act->setData( QVariant( QMetaType::QObjectStar, &vlayer ) );
act->setText( tr( "Show more" ) );

QToolButton *showMore = new QToolButton( errorMsg );
showMore->setStyleSheet( "background-color: rgba(255, 255, 255, 0); color: black; text-decoration: underline;" );
showMore->setCursor( Qt::PointingHandCursor );
showMore->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
showMore->addAction( act );
showMore->setDefaultAction( act );

connect( showMore, SIGNAL( triggered( QAction* ) ), mv, SLOT( exec() ) );
connect( showMore, SIGNAL( triggered( QAction* ) ), showMore, SLOT( deleteLater() ) );
errorMsg->layout()->addWidget( showMore );

// no timeout set, since notice needs attention and is only shown first time layer is labeled
messageBar()->pushWidget( errorMsg, QgsMessageBar::WARNING );
QgsMessageBarItem *errorMsg = new QgsMessageBarItem(
tr( "Commit errors" ),
tr( "Could not commit changes to layer %1" ).arg( vlayer->name() ),
showMore,
QgsMessageBar::WARNING,
0,
messageBar() );
messageBar()->pushItem( errorMsg );
}

void QgisApp::labelingDialogFontNotFound( QAction* act )
@@ -6147,7 +6147,7 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
mMapCanvas->freeze();
QgsMapLayer *dupLayer;
QString layerDupName, unSppType;
QList<QWidget *> msgBars;
QList<QgsMessageBarItem *> msgBars;

foreach ( QgsMapLayer * selectedLyr, selectedLyrs )
{
@@ -6188,23 +6188,25 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )

if ( unSppType.isEmpty() && dupLayer && !dupLayer->isValid() )
{
msgBars.append( QgsMessageBar::createMessage(
tr( "Duplicate layer: " ),
tr( "%1 (duplication resulted in invalid layer)" ).arg( selectedLyr->name() ) ,
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
mInfoBar ) );
msgBars.append( new QgsMessageBarItem(
tr( "Duplicate layer: " ),
tr( "%1 (duplication resulted in invalid layer)" ).arg( selectedLyr->name() ) ,
QgsMessageBar::WARNING,
0,
mInfoBar ) );
continue;
}

if ( !unSppType.isEmpty() || !dupLayer )
{
msgBars.append( QgsMessageBar::createMessage(
tr( "Duplicate layer: " ),
tr( "%1 (%2 type unsupported)" )
.arg( selectedLyr->name() )
.arg( !unSppType.isEmpty() ? QString( "'" ) + unSppType + "' " : "" ),
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
mInfoBar ) );
msgBars.append( new QgsMessageBarItem(
tr( "Duplicate layer: " ),
tr( "%1 (%2 type unsupported)" )
.arg( selectedLyr->name() )
.arg( !unSppType.isEmpty() ? QString( "'" ) + unSppType + "' " : "" ),
QgsMessageBar::WARNING,
0,
mInfoBar ) );
continue;
}

@@ -6261,9 +6263,9 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
mMapCanvas->freeze( false );

// display errors in message bar after duplication of layers
foreach ( QWidget * msgBar, msgBars )
foreach ( QgsMessageBarItem * msgBar, msgBars )
{
mInfoBar->pushWidget( msgBar, QgsMessageBar::WARNING );
mInfoBar->pushItem( msgBar );
}
}

@@ -75,7 +75,7 @@ QgsRubberBand* QgsMapToolEdit::createRubberBand( QGis::GeometryType geometryType
rb->setWidth( settings.value( "/qgis/digitizing/line_width", 1 ).toInt() );
QColor color( settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(),
settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(),
settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt());
settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt() );
double myAlpha = settings.value( "/qgis/digitizing/line_color_alpha", 200 ).toInt() / 255.0 ;
if ( alternativeBand )
{
@@ -84,9 +84,9 @@ QgsRubberBand* QgsMapToolEdit::createRubberBand( QGis::GeometryType geometryType
}
if ( geometryType == QGis::Polygon )
{
color.setAlphaF ( myAlpha );
color.setAlphaF( myAlpha );
}
color.setAlphaF ( myAlpha );
color.setAlphaF( myAlpha );
rb->setColor( color );
rb->show();
return rb;
@@ -89,6 +89,7 @@ qgsmaptoolidentify.cpp
qgsmaptoolpan.cpp
qgsmaptoolzoom.cpp
qgsmessagebar.cpp
qgsmessagebaritem.cpp
qgsmessageviewer.cpp
qgsmessagelogviewer.cpp
qgsnewhttpconnection.cpp
@@ -201,6 +202,7 @@ qgsmapcanvas.h
qgsmapoverviewcanvas.h
qgsmaptoolemitpoint.h
qgsmaptoolidentify.h
qgsmessagebaritem.h
qgsmessagebar.h
qgsmessageviewer.h
qgsmessagelogviewer.h
@@ -253,6 +255,7 @@ qgsmaptoolemitpoint.h
qgsmaptoolidentify.h
qgsmaptoolpan.h
qgsmaptoolzoom.h
qgsmessagebaritem.h
qgsmessagebar.h
qgsmessageviewer.h
qgsoptionsdialogbase.h

0 comments on commit 45aa1da

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