Skip to content
Permalink
Browse files

replace the message bar by a multiline qlabel

  • Loading branch information
pblottiere committed May 29, 2016
1 parent 36d7dc4 commit ea950340dba882fcf175945d12561eab281ad579
Showing with 17 additions and 13 deletions.
  1. +16 −12 src/gui/qgsattributeform.cpp
  2. +1 −1 src/gui/qgsattributeform.h
@@ -49,11 +49,11 @@ int QgsAttributeForm::sFormCounter = 0;

QgsAttributeForm::QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &feature, const QgsAttributeEditorContext &context, QWidget* parent )
: QWidget( parent )
, mInvalidConstraintMessageBarItem( nullptr )
, mLayer( vl )
, mMessageBar( nullptr )
, mMultiEditUnsavedMessageBarItem( nullptr )
, mMultiEditMessageBarItem( nullptr )
, mInvalidConstraintMessage( nullptr )
, mContext( context )
, mButtonBox( nullptr )
, mSearchButtonBox( nullptr )
@@ -762,29 +762,29 @@ bool QgsAttributeForm::currentFormFeature( QgsFeature &feature )

void QgsAttributeForm::clearInvalidConstraintsMessage()
{
if ( mInvalidConstraintMessageBarItem != nullptr )
{
mMessageBar->popWidget( mInvalidConstraintMessageBarItem );
mInvalidConstraintMessageBarItem = nullptr;
}
mInvalidConstraintMessage->clear();
mInvalidConstraintMessage->setStyleSheet( "" );
}

void QgsAttributeForm::displayInvalidConstraintMessage( const QStringList &f,
const QStringList &d )
{
clearInvalidConstraintsMessage();

// show only the third first error
// show only the third first errors (to avoid a too long label)
int max = 3;
int size = f.size() > max ? max : f.size();
QString descriptions;
for ( int i = 0; i < size; i++ )
descriptions += "<br />- " + f[i] + ": " + d[i];
descriptions += QString( "<li>%1: <i>%2</i></li>" ).arg( f[i] ).arg( d[i] );

QString icPath = QgsApplication::iconPath( "/mIconWarn.png" );

mInvalidConstraintMessageBarItem =
new QgsMessageBarItem( tr( "Invalid fields: " ),
descriptions, QgsMessageBar::WARNING );
mMessageBar->pushItem( mInvalidConstraintMessageBarItem );
QString title = QString( "<img src=\"%1\"> <b>%2:" ).arg( icPath ).arg( tr( "Invalid fields" ) );
QString msg = QString( "%1</b><ul>%2</ul>" ).arg( title ).arg( descriptions ) ;

mInvalidConstraintMessage->setText( msg );
mInvalidConstraintMessage->setStyleSheet( "QLabel { background-color : #ffc800; }" );
}

bool QgsAttributeForm::currentFormValidConstraints( QStringList &invalidFields,
@@ -1025,6 +1025,10 @@ void QgsAttributeForm::init()
mMessageBar = new QgsMessageBar( this );
mMessageBar->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
vl->addWidget( mMessageBar );

mInvalidConstraintMessage = new QLabel( this );
vl->addWidget( mInvalidConstraintMessage );

setLayout( vl );

// Get a layout
@@ -307,13 +307,13 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
void clearInvalidConstraintsMessage();
void displayInvalidConstraintMessage( const QStringList &invalidFields,
const QStringList &description );
QgsMessageBarItem *mInvalidConstraintMessageBarItem;

QgsVectorLayer* mLayer;
QgsFeature mFeature;
QgsMessageBar* mMessageBar;
QgsMessageBarItem* mMultiEditUnsavedMessageBarItem;
QgsMessageBarItem* mMultiEditMessageBarItem;
QLabel* mInvalidConstraintMessage;
QList<QgsWidgetWrapper*> mWidgets;
QgsAttributeEditorContext mContext;
QDialogButtonBox* mButtonBox;

0 comments on commit ea95034

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