#ifndef TREE_VIEW_H
#define TREE_VIEW_H

#include <QTreeView>
#include <QItemDelegate>
#include <QHeaderView>
#include <QPainter>
#include "WLItem.h"
#include "WLModel.h"
#include "qbu_qt4.h"

class WLEditor: public QItemDelegate
{
	Q_OBJECT
	
	public:
		WLEditor(QObject *parent = 0);

		QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;

		void setEditorData(QWidget *editor, const QModelIndex &index) const;
		
		void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;

		void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};

class WLView: public QTreeView
{
	Q_OBJECT
	
	public:
	
		WLView(QWidget* parent=NULL);
		
		inline WLModel* wlmodel() const
		{
			return static_cast<WLModel*>(model());
		}
		
		void displayMenu(const QPoint&);
	
	signals:
		void exportET();
		
	public slots:
		
		void newFolder();
		
		void moveUp();
		
		void moveDown();
		
		void clear();
		
// 		void fill();

		void copy();
		
		void insert();
		
		void rename();
		
		void editObject(const QModelIndex& index=QModelIndex());
		
		void newObject();
		void createText();
		void createTextArr();
		void createTime();
		void createTInterval();
		void createConstant();
		void createVConstant();
		void createArray();
		
		void duplicateObj();
		
		void sliceObj();

		void arrayTrace();
		
		void mergeTS();
		
		void vect2array();
		
		void tif2ev();
		
		void ev2tif();
		
// 		void exportET();
		
		void deleteObject();
		
		void removeTimeTags();
		
		void selectAllData();
		void deleteAllDataItems();
		void deleteAllTimeIntervalItems();
		void deleteAllConstantItems();
		void clearCacheSelected();
		void clearCache();
		
		void newSelectedIndexes(const QModelIndexList&);
		void setCurrentItem(WLItem* i);
		
	protected:
		void drawRow(QPainter * painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
		
		QList<WLItem*> selectedItems();
		
		void mousePressEvent(QMouseEvent* e);
		
		QMenu * RButtonMenu;
		QDialog* objTypeSelector;
		arrDialog *arrTypeSelector;
		WLEditor* delegate;
		
};

#endif
