Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef PROPERTY_H
00030 #define PROPERTY_H
00031
00032 #include <string>
00033
00034 #include <QObject>
00035 #include <QIcon>
00036 #include <QVariant>
00037
00038 #include "rviz/config.h"
00039
00040 class QModelIndex;
00041 class QPainter;
00042 class QStyleOptionViewItem;
00043
00044 namespace rviz
00045 {
00046
00047 class PropertyTreeModel;
00048
00100 class Property: public QObject
00101 {
00102 Q_OBJECT
00103 public:
00130 Property( const QString& name = QString(),
00131 const QVariant default_value = QVariant(),
00132 const QString& description = QString(),
00133 Property* parent = 0,
00134 const char *changed_slot = 0,
00135 QObject* receiver = 0 );
00136
00140 virtual ~Property();
00141
00148 virtual void removeChildren( int start_index = 0, int count = -1 );
00149
00161 virtual bool setValue( const QVariant& new_value );
00162
00165 virtual QVariant getValue() const;
00166
00171 virtual void setName( const QString& name );
00172
00174 virtual QString getName() const;
00175
00177 std::string getNameStd() const { return getName().toStdString(); }
00178
00181 virtual void setDescription( const QString& description );
00182
00184 virtual QString getDescription() const;
00185
00187 virtual void setIcon( const QIcon& icon ) { icon_=icon; }
00188
00189 virtual QIcon getIcon() const { return icon_; }
00190
00209 virtual Property* subProp( const QString& sub_name );
00210
00215 virtual int numChildren() const { return children_.size(); }
00216
00224 Property* childAt( int index ) const;
00225
00231 virtual Property* childAtUnchecked( int index ) const;
00232
00234 bool contains( Property* possible_child ) const;
00235
00237 Property* getParent() const;
00238
00245 void setParent( Property* new_parent );
00246
00259 virtual QVariant getViewData( int column, int role ) const;
00260
00265 virtual Qt::ItemFlags getViewFlags( int column ) const;
00266
00276 virtual bool paint( QPainter* painter,
00277 const QStyleOptionViewItem& option ) const { return false; }
00278
00279
00296 virtual QWidget* createEditor( QWidget* parent,
00297 const QStyleOptionViewItem& option );
00298
00302 bool isAncestorOf( Property* possible_child ) const;
00303
00312 Property* takeChild( Property* child );
00313
00318 virtual Property* takeChildAt( int index );
00319
00325 virtual void addChild( Property* child, int index = -1 );
00326
00328 void setModel( PropertyTreeModel* model );
00329
00331 PropertyTreeModel* getModel() const { return model_; }
00332
00339 int rowNumberInParent() const;
00340
00342 virtual void moveChild( int from_index, int to_index );
00343
00346 virtual void load( const Config& config );
00347
00350 virtual void save( Config config ) const;
00351
00353 bool shouldBeSaved() const { return !is_read_only_ && save_; }
00354
00357 void setShouldBeSaved( bool save ) { save_ = save; }
00358
00361 virtual bool getDisableChildren();
00362
00367 void hide() { setHidden( true ); }
00368
00373 void show() { setHidden( false ); }
00374
00380 virtual void setHidden( bool hidden );
00381
00384 virtual bool getHidden() const { return hidden_; }
00385
00393 virtual void setReadOnly( bool read_only ) { is_read_only_ = read_only; }
00394
00397 virtual bool getReadOnly() { return is_read_only_; }
00398
00403 virtual void collapse();
00404
00414 virtual void expand();
00415
00416 Q_SIGNALS:
00418 void aboutToChange();
00420 void changed();
00421
00423 void childListChanged( Property* this_property );
00424
00425 protected:
00430 void loadValue( const Config& config );
00431
00436 QVariant value_;
00437
00450 PropertyTreeModel* model_;
00451
00457 bool child_indexes_valid_;
00458
00459 QIcon icon_;
00460
00461 private:
00464 void reindexChildren();
00465
00466 Property* parent_;
00467 QList<Property*> children_;
00468 QString description_;
00469 bool hidden_;
00470
00473 static Property* failprop_;
00474
00475 int row_number_within_parent_;
00476 bool is_read_only_;
00477 bool save_;
00478 };
00479
00480 }
00481
00482 #endif // PROPERTY_H