#ifndef PROPERTIES_EDITOR_H
#define PROPERTIES_EDITOR_H

#include "model_delegates.h"
#include "ui_properties_editor.h"


class PropertiesEditor: public QWidget, public Ui::PropertiesEditor {
	Q_OBJECT
public:
	explicit PropertiesEditor(QWidget * parent = 0);
	~PropertiesEditor();
	
	void setProperties(const PropertyStorage & p) {on_buttonPropClear_clicked(); addProperties(p);}
	void addProperties(const PropertyStorage & p);
	void clear() {on_buttonPropClear_clicked();}
	PropertyStorage properties();
	
	void setDefaultProperties(const PropertyStorage & p) {defaults = p;}
	const PropertyStorage & defaultProperties() const {return defaults;}
	
private:
	bool eventFilter(QObject * o, QEvent * e);
	QString uniqueName(QString n);
	QTreeWidgetItem * addProperty(const PropertyStorage::Property & p);
	
	FlagsDelegate * flags_delegate;
	VariantTypeDelegate * type_delegate;
	PropertyStorage defaults;
	QIcon icon_plugin;
	
public slots:
	void reloadPlugins();
	void addDefaultProperties();
	
private slots:
	void filterList();
	void setVariantValue(void * ve_, int type);
	void updateTreeLayout() {treeProps->doItemsLayout();}
	void on_buttonPropAdd_clicked();
	void on_buttonPropDup_clicked();
	void on_buttonPropDefault_clicked() {addDefaultProperties();}
	void on_buttonPropDelete_clicked();
	void on_buttonPropClear_clicked();
	void on_buttonPropUp_clicked();
	void on_buttonPropDown_clicked();
	void on_treeProps_itemChanged(QTreeWidgetItem * item, int column);
	
signals:
	void propertiesChanged();
	
};

#endif // PROPERTIES_EDITOR_H
