#ifndef OBJECT_EDITOR_H
#define DATABASEDEVICES_H

#include <QDoubleSpinBox>
#include <QStyledItemDelegate>
#include <QDialog>
#include "SH_plugins.h"
#include "model_delegates.h"
#include "ui_object_editor.h"


class ObjectEditor: public QWidget, public Ui::ObjectEditor {
	Q_OBJECT
public:
	explicit ObjectEditor(QWidget * parent = 0);
	~ObjectEditor();

	const SHS::Object & object() const {return object_;}
	void setObject(const SHS::Object & o);

	PacketPinDelegate * pins_delegate;

private:
	QStringList objectPath(QTreeWidgetItem * ti);
	SHS::Object * objectByTreeItem(QTreeWidgetItem * ti);
	void createObjectTree(const SHS::Object & o, QTreeWidgetItem * ti);
	SHPacketWidgetBase * commandEditor(const SHS::Command & cmd);
	void saveCurrentCommands();
	
	FlagsDelegate * flags_delegate;
	PacketReplyByDelegate * reply_by_delegate;
	SHS::Object object_;
	QStringList last_packet_names;
	QDialog command_dialog;
	QMap<QString, SHPacketWidgetBase*> packet_editors;
	
public slots:

private slots:
	void deleteEditors();
	void changedPlugins();
	void filterPackets();
	void on_buttonPacketAdd_clicked();
	void on_buttonPacketDup_clicked();
	void on_buttonPacketDelete_clicked();
	void on_buttonPacketClear_clicked();
	void on_buttonObjectAdd_clicked();
	void on_buttonObjectDup_clicked();
	void on_buttonObjectDelete_clicked();
	void on_buttonObjectClear_clicked();
	void on_treeCommands_itemChanged(QTreeWidgetItem * item, int column);
	void on_treeCommands_itemClicked(QTreeWidgetItem * item, int column);
	void on_treeCommands_currentItemChanged(QTreeWidgetItem * , QTreeWidgetItem *);
	void on_treeCommands_itemDoubleClicked(QTreeWidgetItem * item, int column);
	void on_treeObject_itemChanged(QTreeWidgetItem * item, int column);
	void on_treeObject_currentItemChanged(QTreeWidgetItem * , QTreeWidgetItem *);
	void on_treeObject_itemSelectionChanged();
	void on_propertiesObject_propertiesChanged();
	
};

#endif // DATABASEDEVICES_H
