#ifndef MODEL_DELEGATES_H
#define MODEL_DELEGATES_H

#include <QMetaEnum>
#include <QTreeWidget>
#include <QDoubleSpinBox>
#include <QStyledItemDelegate>
#include <QComboBox>
#include <QSqlRecord>
#include <propertystorage.h>
//#include "core.h"

class QToolButton;

//const int TypeFile = QVariant::UserType + 0x100;
//const int TypeDir  = QVariant::UserType + 0x101;

// QMap<QString, BlockItemPin::Device> variant2devices(const QVariant & v);
// QVariant devices2variant(const QMap<QString, BlockItemPin::Device> & v);

/*
class TreePathes: public QTreeWidget {
	Q_OBJECT
public:
	explicit TreePathes(QWidget * parent = 0);
	void setDevices(const QMap<QString, BlockItemPin::Device> & devs);
	QMap<QString, BlockItemPin::Device> devices() const;
	int max_devices;
	QStringList classes;
private:
	QToolButton * buttonAdd, * buttonDel;
private slots:
	void adjustButtons();
	void addDevice();
	void delDevice();
};
*/


class PinAlignDelegate: public QStyledItemDelegate {
	Q_OBJECT
public:
	PinAlignDelegate(QObject * parent = 0): QStyledItemDelegate(parent) {}
	QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	QString displayText(const QVariant & value, const QLocale & locale) const;
	void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const {return QSize(60, 26);}
};


class PinBusDelegate: public QStyledItemDelegate {
	Q_OBJECT
public:
	PinBusDelegate(QObject * parent = 0): QStyledItemDelegate(parent) {}
	QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	QString displayText(const QVariant & value, const QLocale & locale) const;
	void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const {return QSize(60, 26);}
public slots:
	void updateDB();
private:
	typedef QPair<int, QString> ISPair;
	QVector<ISPair> buses;
};



/*
class PinDeviceDelegate: public QStyledItemDelegate {
	Q_OBJECT
public:
	PinDeviceDelegate(QObject * parent = 0): QStyledItemDelegate(parent) {}
	QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	QString displayText(const QVariant & value, const QLocale & locale) const;
	QString getText(const QVariant & value) const;
	void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
	void setEditorData(QWidget * editor, const QModelIndex & index) const {}
	void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
	//QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
};
*/



class FlagsDelegate: public QStyledItemDelegate {
	Q_OBJECT
public:
	FlagsDelegate(QObject * parent = 0);
	void setEnum(const QMetaEnum & e) {me = e;}
	void hideEnumerator(const QString & name) {hidden_ << name;}
	void setSingle(bool yes) {single = yes;}
	QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	QString displayText(const QVariant & value, const QLocale & locale) const;
	void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const {return QSize(60, 26);}
private:
	bool single;
	QMetaEnum me;
	QStringList hidden_;
};




class PacketPinDelegate: public QStyledItemDelegate {
	Q_OBJECT
public:
	PacketPinDelegate(QObject * parent = 0);
	QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const {return QSize(60, 26);}
	QTreeWidget * pins;
private:
};




class PinPluginDelegate: public QStyledItemDelegate {
	Q_OBJECT
public:
	PinPluginDelegate(QObject * parent = 0): QStyledItemDelegate(parent) {}
	QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const {return QSize(60, 26);}
private:
};




class PacketReplyByDelegate: public QStyledItemDelegate {
	Q_OBJECT
public:
	PacketReplyByDelegate(QObject * parent = 0);
	QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const {return QSize(60, 26);}
	QTreeWidget * packets;
private:
};




class VariantTypeDelegate: public QStyledItemDelegate {
	Q_OBJECT
public:
	VariantTypeDelegate(QObject * parent = 0);
	QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	QString displayText(const QVariant & value, const QLocale & ) const;
	void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const {return QSize(60, 26);}
};


#endif // MODEL_DELEGATES_H
