[QGIS Commit] r10787 - trunk/qgis/src/plugins/grass
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed May 13 15:11:00 EDT 2009
Author: rblazek
Date: 2009-05-13 15:10:59 -0400 (Wed, 13 May 2009)
New Revision: 10787
Modified:
trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp
trunk/qgis/src/plugins/grass/qgsgrassmodule.h
Log:
fixed ticket #1133: title adjusted on resize, use of option label; description used as tooltip; layout of vector fields combobox; dont use empty not required option
Modified: trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp 2009-05-13 14:22:34 UTC (rev 10786)
+++ trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp 2009-05-13 19:10:59 UTC (rev 10787)
@@ -1557,8 +1557,7 @@
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." );
@@ -1568,18 +1567,6 @@
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() )
@@ -1925,8 +1912,11 @@
list.push_back( mKey + "=" + mAnswer );
}
else
- {
- list.push_back( mKey + "=" + value() );
+ {
+ QString val = value();
+ if ( !val.isEmpty() ) {
+ list.push_back( mKey + "=" + val );
+ }
}
return list;
}
@@ -1939,7 +1929,7 @@
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() ) );
}
@@ -1965,7 +1955,7 @@
else
setChecked( false );
- setText( mDescription );
+ setText( mTitle );
}
QStringList QgsGrassModuleFlag::options()
@@ -1982,14 +1972,25 @@
{
}
+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 )
@@ -1997,25 +1998,12 @@
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;
- }
- }
+ adjustTitle();
- setTitle( " " + tit + " " );
-
QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
QString element = promptElem.attribute( "element" );
@@ -2517,7 +2505,8 @@
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode )
: mModule( module ),
mKey( key ),
- mHidden( false )
+ mHidden( false ),
+ mRequired (false)
{
//mAnswer = qdesc.attribute("answer", "");
@@ -2540,21 +2529,41 @@
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" );
}
@@ -2564,34 +2573,48 @@
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;
- }
- }
+ adjustTitle();
- setTitle( " " + tit + " " );
-
QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
QString element = promptElem.attribute( "element" );
@@ -2614,7 +2637,7 @@
}
// Read "whereoption" if defined
- opt = qdesc.attribute( "whereoption" );
+ opt = qdesc.attribute( "where" );
if ( !opt.isNull() )
{
QDomNode optNode = QgsGrassModule::nodeByKey( gdesc, opt );
@@ -2797,29 +2820,15 @@
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" );
+ mTitle = tr( "Attribute field" );
}
- else
- {
- if ( mDescription.length() > 40 )
- {
- tit = mDescription.left( 40 ) + " ...";
- }
- else
- {
- tit = mDescription;
- }
- }
+ adjustTitle();
- setTitle( " " + tit + " " );
-
QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
QString element = promptElem.attribute( "element" );
@@ -2836,7 +2845,9 @@
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();
@@ -2888,30 +2899,16 @@
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() )
+ if ( mTitle.isEmpty() )
{
- tit = tr( "Attribute field" );
+ mTitle = tr( "Selected categories" );
}
- else
- {
- if ( mDescription.length() > 40 )
- {
- tit = mDescription.left( 40 ) + " ...";
- }
- else
- {
- tit = mDescription;
- }
- }
+ adjustTitle();
- setTitle( " " + tit + " " );
-
QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
QString element = promptElem.attribute( "element" );
@@ -3005,29 +3002,15 @@
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;
- }
- }
+ adjustTitle();
- setTitle( " " + tit + " " );
-
QDomNode promptNode = gnode.namedItem( "gisprompt" );
QDomElement promptElem = promptNode.toElement();
QString element = promptElem.attribute( "element" );
@@ -3126,7 +3109,7 @@
QString path = mLineEdit->text().trimmed();
- if ( path.length() == 0 )
+ if ( path.length() == 0 && mRequired )
{
error.append( tr( "%1: missing value" ).arg( title() ) );
return error;
Modified: trunk/qgis/src/plugins/grass/qgsgrassmodule.h
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassmodule.h 2009-05-13 14:22:34 UTC (rev 10786)
+++ trunk/qgis/src/plugins/grass/qgsgrassmodule.h 2009-05-13 19:10:59 UTC (rev 10787)
@@ -325,25 +325,61 @@
//! Optional option id used by other options which depend on this
QString mId;
- //! GRASS description
- QString mDescription;
+ //! Item title, GRASS label or description
+ QString mTitle;
+ //! Item tooltip, GRASS description if defined
+ QString mToolTip;
+
//! Hidden option or displayed
bool mHidden;
//! Predefined answer from config
QString mAnswer;
+ //! Is it required
+ bool mRequired;
+
private:
};
+/****************** QgsGrassModuleGroupBoxItem ************************/
+
+/*! \class QgsGrassModuleGroupBoxItem
+ * \brief GRASS module option box
+ */
+class QgsGrassModuleGroupBoxItem: public QGroupBox, public QgsGrassModuleItem
+{
+ Q_OBJECT
+
+ public:
+ /*! \brief Constructor
+ * \param qdesc option element in QGIS module description XML file
+ * \param gdesc GRASS module XML description file
+ * \param gnode option node in GRASS module XML description file
+ */
+ QgsGrassModuleGroupBoxItem( QgsGrassModule *module, QString key,
+ QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
+ QWidget * parent = 0 );
+
+ //! Destructor
+ virtual ~QgsGrassModuleGroupBoxItem();
+
+ void resizeEvent ( QResizeEvent * event );
+
+ public slots:
+ //! Adjust title size, called on resize
+ void adjustTitle();
+
+};
+
/****************** QgsGrassModuleOption ************************/
/*! \class QgsGrassModuleOption
* \brief GRASS option
*/
-class QgsGrassModuleOption: public QGroupBox, public QgsGrassModuleItem
+class QgsGrassModuleOption: public QgsGrassModuleGroupBoxItem
{
Q_OBJECT
@@ -458,9 +494,15 @@
//! Destructor
~QgsGrassModuleFlag();
+
//! Retruns list of options which will be passed to module
virtual QStringList options();
- private:
+
+ void resizeEvent ( QResizeEvent * event );
+
+ public slots:
+ //! Adjust title size, called on resize
+ void adjustText();
};
/************************ QgsGrassModuleInput **********************/
@@ -468,7 +510,7 @@
/*! \class QgsGrassModuleInput
* \brief Class representing raster or vector module input
*/
-class QgsGrassModuleInput: public QGroupBox, public QgsGrassModuleItem
+class QgsGrassModuleInput: public QgsGrassModuleGroupBoxItem
{
Q_OBJECT
@@ -575,7 +617,7 @@
/*! \class QgsGrassModuleGdalInput
* \brief GDAL/OGR module input
*/
-class QgsGrassModuleGdalInput: public QGroupBox, public QgsGrassModuleItem
+class QgsGrassModuleGdalInput: public QgsGrassModuleGroupBoxItem
{
Q_OBJECT
@@ -629,7 +671,7 @@
/*! \class QgsGrassModuleField
* \brief GRASS vector attribute column.
*/
-class QgsGrassModuleField: public QGroupBox, public QgsGrassModuleItem
+class QgsGrassModuleField: public QgsGrassModuleGroupBoxItem
{
Q_OBJECT
@@ -676,7 +718,7 @@
/*! \class QgsGrassModuleSelection
* \brief List of categories taken from current layer selection.
*/
-class QgsGrassModuleSelection: public QGroupBox, public QgsGrassModuleItem
+class QgsGrassModuleSelection: public QgsGrassModuleGroupBoxItem
{
Q_OBJECT
@@ -724,10 +766,10 @@
/*********************** QgsGrassModuleFile **********************/
-/*! \class QgsGrassModuleSelection
+/*! \class QgsGrassModuleFile
* \brief Input/output file.
*/
-class QgsGrassModuleFile: public QGroupBox, public QgsGrassModuleItem
+class QgsGrassModuleFile: public QgsGrassModuleGroupBoxItem
{
Q_OBJECT
More information about the QGIS-commit
mailing list