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 <QVariant>
00036
00037 namespace YAML
00038 {
00039 class Node;
00040 class Emitter;
00041 }
00042
00043 class QModelIndex;
00044 class QPainter;
00045 class QStyleOptionViewItem;
00046
00047 namespace rviz
00048 {
00049
00050 class PropertyTreeModel;
00051
00103 class Property: public QObject
00104 {
00105 Q_OBJECT
00106 public:
00133 Property( const QString& name = QString(),
00134 const QVariant default_value = QVariant(),
00135 const QString& description = QString(),
00136 Property* parent = 0,
00137 const char *changed_slot = 0,
00138 QObject* receiver = 0 );
00139
00143 virtual ~Property();
00144
00149 virtual void removeAllChildren();
00150
00162 virtual bool setValue( const QVariant& new_value );
00163
00166 virtual QVariant getValue() const;
00167
00172 virtual void setName( const QString& name );
00173
00175 virtual QString getName() const;
00176
00178 std::string getNameStd() const { return getName().toStdString(); }
00179
00182 virtual void setDescription( const QString& description );
00183
00185 virtual QString getDescription() const;
00186
00205 virtual Property* subProp( const QString& sub_name );
00206
00211 virtual int numChildren() const { return children_.size(); }
00212
00220 Property* childAt( int index ) const;
00221
00227 virtual Property* childAtUnchecked( int index ) const;
00228
00230 Property* getParent() const;
00231
00238 void setParent( Property* new_parent );
00239
00252 virtual QVariant getViewData( int column, int role ) const;
00253
00258 virtual Qt::ItemFlags getViewFlags( int column ) const;
00259
00269 virtual bool paint( QPainter* painter,
00270 const QStyleOptionViewItem& option ) const { return false; }
00271
00272
00289 virtual QWidget* createEditor( QWidget* parent,
00290 const QStyleOptionViewItem& option );
00291
00295 bool isAncestorOf( Property* possible_child ) const;
00296
00305 Property* takeChild( Property* child );
00306
00311 virtual Property* takeChildAt( int index );
00312
00318 virtual void addChild( Property* child, int index = -1 );
00319
00321 void setModel( PropertyTreeModel* model );
00322
00324 PropertyTreeModel* getModel() const { return model_; }
00325
00332 int rowNumberInParent() const;
00333
00335 virtual void moveChild( int from_index, int to_index );
00336
00339 virtual void load( const YAML::Node& yaml_node );
00340
00343 virtual void save( YAML::Emitter& emitter );
00344
00351 virtual void loadChildren( const YAML::Node& yaml_node );
00352
00355 virtual void saveChildren( YAML::Emitter& emitter );
00356
00360 virtual bool shouldBeSaved() const { return !is_read_only_; }
00361
00366 void hide() { setHidden( true ); }
00367
00372 void show() { setHidden( false ); }
00373
00382 virtual void setHidden( bool hidden );
00383
00386 virtual bool getHidden() const { return hidden_; }
00387
00395 virtual void setReadOnly( bool read_only ) { is_read_only_ = read_only; }
00396
00399 virtual bool getReadOnly() { return is_read_only_; }
00400
00405 virtual void collapse();
00406
00416 virtual void expand();
00417
00418 Q_SIGNALS:
00420 void aboutToChange();
00422 void changed();
00423
00425 void hiddenChanged( bool hidden );
00426
00427 protected:
00432 void loadValue( const YAML::Node& yaml_node );
00433
00438 void saveValue( YAML::Emitter& emitter );
00439
00444 QVariant value_;
00445
00458 PropertyTreeModel* model_;
00459
00465 bool child_indexes_valid_;
00466
00467 private:
00470 void reindexChildren();
00471
00472 Property* parent_;
00473 QList<Property*> children_;
00474 QString description_;
00475 bool hidden_;
00476
00479 static Property* failprop_;
00480
00481 int row_number_within_parent_;
00482 bool is_read_only_;
00483 };
00484
00485 }
00486
00487 #endif // PROPERTY_H