Skip to content

Commit

Permalink
fixed ticket #1133: title adjusted on resize, use of option label; de…
Browse files Browse the repository at this point in the history
…scription used as tooltip; layout of vector fields combobox; dont use empty not required option

git-svn-id: http://svn.osgeo.org/qgis/trunk@10787 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed May 13, 2009
1 parent 0efa74c commit ae73a32
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 127 deletions.
217 changes: 100 additions & 117 deletions src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,8 +1557,7 @@ QDomNode QgsGrassModule::nodeByKey( QDomElement elem, QString key )
QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
QWidget * parent )
: QGroupBox( parent ),
QgsGrassModuleItem( module, key, qdesc, gdesc, gnode ),
: QgsGrassModuleGroupBoxItem( module, key, qdesc, gdesc, gnode, parent ),
mControlType( NoControl ), mValueType( String ), mOutputType( None ), mHaveLimits( false ), mIsOutput( false )
{
QgsDebugMsg( "called." );
Expand All @@ -1568,18 +1567,6 @@ QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,

mLayout = new QVBoxLayout();

QString tit;
if ( mDescription.length() > 40 )
{
tit = mDescription.left( 40 ) + " ...";
}
else
{
tit = mDescription;
}

setTitle( " " + tit + " " );

// Is it output?
QDomNode promptNode = gnode.namedItem( "gisprompt" );
if ( !promptNode.isNull() )
Expand Down Expand Up @@ -1925,8 +1912,11 @@ QStringList QgsGrassModuleOption::options()
list.push_back( mKey + "=" + mAnswer );
}
else
{
list.push_back( mKey + "=" + value() );
{
QString val = value();
if ( !val.isEmpty() ) {
list.push_back( mKey + "=" + val );
}
}
return list;
}
Expand All @@ -1939,7 +1929,7 @@ QString QgsGrassModuleOption::ready()

if ( mControlType == LineEdit )
{
if ( mLineEdits.at( 0 )->text().trimmed().length() == 0 )
if ( mLineEdits.at( 0 )->text().trimmed().length() == 0 && mRequired )
{
error.append( tr( "%1: missing value" ).arg( title() ) );
}
Expand All @@ -1965,7 +1955,7 @@ QgsGrassModuleFlag::QgsGrassModuleFlag( QgsGrassModule *module, QString key,
else
setChecked( false );

setText( mDescription );
setText( mTitle );
}

QStringList QgsGrassModuleFlag::options()
Expand All @@ -1982,39 +1972,37 @@ QgsGrassModuleFlag::~QgsGrassModuleFlag()
{
}

void QgsGrassModuleFlag::resizeEvent ( QResizeEvent * event )
{
adjustText();
}

void QgsGrassModuleFlag::adjustText()
{
QString t = fontMetrics().elidedText ( mTitle , Qt::ElideRight, width() - iconSize().width() - 20 );

setText( t );
}

/************************** QgsGrassModuleInput ***************************/

QgsGrassModuleInput::QgsGrassModuleInput( QgsGrassModule *module,
QgsGrassModuleStandardOptions *options, QString key,
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
QWidget * parent )
: QGroupBox( parent ),
QgsGrassModuleItem( module, key, qdesc, gdesc, gnode ),
: QgsGrassModuleGroupBoxItem( module, key, qdesc, gdesc, gnode, parent ),
mModuleStandardOptions( options ),
mGeometryTypeOption( 0 ), mVectorLayerOption( 0 ),
mRegionButton( 0 ), mUpdate( false )
{
QgsDebugMsg( "called." );
mGeometryTypeMask = GV_POINT | GV_LINE | GV_AREA;

QString tit;
if ( mDescription.isEmpty() )
if ( mTitle.isEmpty() )
{
tit = "Input";
mTitle = tr( "Input" );
}
else
{
if ( mDescription.length() > 40 )
{
tit = mDescription.left( 40 ) + " ...";
}
else
{
tit = mDescription;
}
}

setTitle( " " + tit + " " );
adjustTitle();

QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
Expand Down Expand Up @@ -2517,7 +2505,8 @@ QgsGrassModuleItem::QgsGrassModuleItem( QgsGrassModule *module, QString key,
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode )
: mModule( module ),
mKey( key ),
mHidden( false )
mHidden( false ),
mRequired (false)
{
//mAnswer = qdesc.attribute("answer", "");

Expand All @@ -2540,20 +2529,40 @@ QgsGrassModuleItem::QgsGrassModuleItem( QgsGrassModule *module, QString key,
mHidden = true;
}

QString label, description;
if ( !qdesc.attribute( "label" ).isEmpty() )
{
mDescription = qdesc.attribute( "label" );
label = qdesc.attribute( "label" );
}
else
if ( label.isEmpty() )
{
QDomNode n = gnode.namedItem( "description" );
QDomNode n = gnode.namedItem( "label" );
if ( !n.isNull() )
{
QDomElement e = n.toElement();
mDescription = e.text().trimmed();
mDescription.replace( 0, 1, mDescription.left( 1 ).toUpper() );
label = e.text().trimmed();
label.replace( 0, 1, label.left( 1 ).toUpper() );
}
}
QDomNode n = gnode.namedItem( "description" );
if ( !n.isNull() )
{
QDomElement e = n.toElement();
description = e.text().trimmed();
description.replace( 0, 1, description.left( 1 ).toUpper() );
}

if ( !label.isEmpty() ) {
mTitle = label;
mToolTip = description;
} else {
mTitle = description;
}

if ( gnode.toElement().attribute( "required" ) == "yes" )
{
mRequired = true;
}

mId = qdesc.attribute( "id" );
}
Expand All @@ -2564,33 +2573,47 @@ QStringList QgsGrassModuleItem::options() { return QStringList(); }

QgsGrassModuleItem::~QgsGrassModuleItem() {}

/***************** QgsGrassModuleGroupBoxItem *********************/

QgsGrassModuleGroupBoxItem::QgsGrassModuleGroupBoxItem( QgsGrassModule *module, QString key,
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
QWidget * parent )
: QGroupBox( parent ),
QgsGrassModuleItem( module, key, qdesc, gdesc, gnode )
{
adjustTitle();

setToolTip ( mToolTip );
}

QgsGrassModuleGroupBoxItem::~QgsGrassModuleGroupBoxItem() {}

void QgsGrassModuleGroupBoxItem::resizeEvent ( QResizeEvent * event )
{
adjustTitle();
setToolTip ( mToolTip );
}

void QgsGrassModuleGroupBoxItem::adjustTitle()
{
QString tit = fontMetrics().elidedText ( mTitle, Qt::ElideRight, width() - 20 );

setTitle( tit );
}

/***************** QgsGrassModuleGdalInput *********************/

QgsGrassModuleGdalInput::QgsGrassModuleGdalInput(
QgsGrassModule *module, int type, QString key, QDomElement &qdesc,
QDomElement &gdesc, QDomNode &gnode, QWidget * parent )
: QGroupBox( parent ),
QgsGrassModuleItem( module, key, qdesc, gdesc, gnode ),
: QgsGrassModuleGroupBoxItem( module, key, qdesc, gdesc, gnode, parent ),
mType( type ), mOgrLayerOption( 0 ), mOgrWhereOption( 0 )
{
QString tit;
if ( mDescription.isEmpty() )
if ( mTitle.isEmpty() )
{
tit = "OGR/PostGIS/GDAL Input";
mTitle = "OGR/PostGIS/GDAL Input";
}
else
{
if ( mDescription.length() > 40 )
{
tit = mDescription.left( 40 ) + " ...";
}
else
{
tit = mDescription;
}
}

setTitle( " " + tit + " " );
adjustTitle();

QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
Expand All @@ -2614,7 +2637,7 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput(
}

// Read "whereoption" if defined
opt = qdesc.attribute( "whereoption" );
opt = qdesc.attribute( "where" );
if ( !opt.isNull() )
{
QDomNode optNode = QgsGrassModule::nodeByKey( gdesc, opt );
Expand Down Expand Up @@ -2797,28 +2820,14 @@ QgsGrassModuleField::QgsGrassModuleField(
QgsGrassModule *module, QgsGrassModuleStandardOptions *options,
QString key, QDomElement &qdesc,
QDomElement &gdesc, QDomNode &gnode, QWidget * parent )
: QGroupBox( parent ),
QgsGrassModuleItem( module, key, qdesc, gdesc, gnode ),
: QgsGrassModuleGroupBoxItem( module, key, qdesc, gdesc, gnode, parent ),
mModuleStandardOptions( options ), mLayerInput( 0 )
{
QString tit;
if ( mDescription.isEmpty() )
if ( mTitle.isEmpty() )
{
tit = tr( "Attribute field" );
}
else
{
if ( mDescription.length() > 40 )
{
tit = mDescription.left( 40 ) + " ...";
}
else
{
tit = mDescription;
}
mTitle = tr( "Attribute field" );
}

setTitle( " " + tit + " " );
adjustTitle();

QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
Expand All @@ -2836,7 +2845,9 @@ QgsGrassModuleField::QgsGrassModuleField(
connect( mLayerInput, SIGNAL( valueChanged() ), this, SLOT( updateFields() ) );
}

mFieldComboBox = new QComboBox( this );
QHBoxLayout *l = new QHBoxLayout( this );
mFieldComboBox = new QComboBox( );
l->addWidget( mFieldComboBox );

// Fill in layer current fields
updateFields();
Expand Down Expand Up @@ -2888,29 +2899,15 @@ QgsGrassModuleSelection::QgsGrassModuleSelection(
QgsGrassModule *module, QgsGrassModuleStandardOptions *options,
QString key, QDomElement &qdesc,
QDomElement &gdesc, QDomNode &gnode, QWidget * parent )
: QGroupBox( parent ),
QgsGrassModuleItem( module, key, qdesc, gdesc, gnode ),
: QgsGrassModuleGroupBoxItem( module, key, qdesc, gdesc, gnode, parent ),
mModuleStandardOptions( options ), mLayerInput( 0 ),
mVectorLayer( 0 )
{
QString tit;
if ( mDescription.isEmpty() )
{
tit = tr( "Attribute field" );
}
else
if ( mTitle.isEmpty() )
{
if ( mDescription.length() > 40 )
{
tit = mDescription.left( 40 ) + " ...";
}
else
{
tit = mDescription;
}
mTitle = tr( "Selected categories" );
}

setTitle( " " + tit + " " );
adjustTitle();

QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
Expand Down Expand Up @@ -3005,28 +3002,14 @@ QgsGrassModuleFile::QgsGrassModuleFile(
QgsGrassModule *module,
QString key, QDomElement &qdesc,
QDomElement &gdesc, QDomNode &gnode, QWidget * parent )
: QGroupBox( parent ),
QgsGrassModuleItem( module, key, qdesc, gdesc, gnode ),
: QgsGrassModuleGroupBoxItem( module, key, qdesc, gdesc, gnode, parent ),
mType( Old )
{
QString tit;
if ( mDescription.isEmpty() )
if ( mTitle.isEmpty() )
{
tit = tr( "File" );
mTitle = tr( "File" );
}
else
{
if ( mDescription.length() > 40 )
{
tit = mDescription.left( 40 ) + " ...";
}
else
{
tit = mDescription;
}
}

setTitle( " " + tit + " " );
adjustTitle();

QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
Expand Down Expand Up @@ -3126,7 +3109,7 @@ QString QgsGrassModuleFile::ready()
QString path = mLineEdit->text().trimmed();


if ( path.length() == 0 )
if ( path.length() == 0 && mRequired )
{
error.append( tr( "%1: missing value" ).arg( title() ) );
return error;
Expand Down
Loading

0 comments on commit ae73a32

Please sign in to comment.