/*
Copyright (C) 2006 Evan Teran
                   eteran@alum.rit.edu

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef RESULTVIEWMODEL_20070419_H_
#define RESULTVIEWMODEL_20070419_H_

#include <QAbstractItemModel>
#include <QVector>
#include "Types.h"

struct Result {
	edb::address_t block;
	edb::address_t size;
	QString type;
	QString data;
};

class ResultViewModel : public QAbstractItemModel {
	Q_OBJECT
public:
	ResultViewModel(QObject *parent = 0);

public:
	virtual QVariant data(const QModelIndex &index, int role) const;
	virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
	virtual QModelIndex parent(const QModelIndex &index) const;
	virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
	virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
	virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
	virtual void sort (int column, Qt::SortOrder order = Qt::AscendingOrder);
	
private:
	static bool BlockLess(const Result &s1, const Result &s2)		{ return s1.block < s2.block; }
	static bool SizeLess(const Result &s1, const Result &s2)		{ return s1.size < s2.size; }
	static bool TypeLess(const Result &s1, const Result &s2)		{ return s1.type < s2.type; }
	static bool DataLess(const Result &s1, const Result &s2)		{ return s1.data < s2.data; }
	static bool BlockGreater(const Result &s1, const Result &s2)	{ return s1.block > s2.block; }
	static bool SizeGreater(const Result &s1, const Result &s2)		{ return s1.size > s2.size; }
	static bool TypeGreater(const Result &s1, const Result &s2)		{ return s1.type > s2.type; }
	static bool DataGreater(const Result &s1, const Result &s2)		{ return s1.data > s2.data; }
	
public:
	void addResult(const Result &r);
	void clearResults();
	void update();
	void setUpdatesEnabled(bool value);
	bool updatesEnabled() const;
	
public:
	QVector<Result> &results() { return m_Results; }

private:
	QVector<Result> m_Results;
	bool			m_UpdatesEnabled;
};

#endif

