#ifndef SIGDISTRIBUTIONWIDGET_H
#define SIGDISTRIBUTIONWIDGET_H

#include <QtGui/QWidget>
#include "ui_sigdistributionwidget.h"
#include "viflow.h"

class QNumTableWidgetItem : public QTableWidgetItem
{

public:
	int number;

	QNumTableWidgetItem(int num) : 	QTableWidgetItem(UserType + 2)
	{
		number = num;
		setData(Qt::DisplayRole, QVariant(number));
	}

	virtual bool operator<(const QTableWidgetItem &other)
	{
		QNumTableWidgetItem *other1 = (QNumTableWidgetItem *) &other;
		return other1->number < number;
	}
};


class QSignatureTableWidgetItem : public QTableWidgetItem
{

public:
	signature_t sig;

	QSignatureTableWidgetItem(signature_t sig) : QTableWidgetItem(UserType + 1)
	{
		char s[17];
		this->sig = sig;
		prettyPrintSignature(this->sig, s, 17);
		setData(Qt::DisplayRole, QVariant(QString(s)));
	}

	virtual bool operator<(const QTableWidgetItem &other)
	{
		QSignatureTableWidgetItem *other1 = (QSignatureTableWidgetItem *) &other;
		return other1->sig < sig;
	}
};

class SigDistributionWidget : public QWidget
{
    Q_OBJECT

    typedef struct SignatureInfo_TAG {
    	signature_t sig;
    	int count;
    } SignatureInfo;

public slots:
    void signatureListChanged(CortageList *CL);

    void regenerateTables( void );

    void onHeaderClicked(int section);
   // void changedSorting(int column);
    void onSignatureClick(QTableWidgetItem *);

signals:
	void updatePoints(signature_t sig);


public:
    SigDistributionWidget(QWidget *parent = 0);
    ~SigDistributionWidget();

private:
    Ui::SigDistributionWidgetClass ui;

    CortageList *cortageList;
  /*  SignatureInfo *info;
    SignatureInfo ** numSort;
    SignatureInfo ** sigSort;*/
    int maxcount;
    int tenaryBits[SIGNATURE_PATTERNS_NUMBER][3];

    static int sortBySig(const void *a, const void *b);
    static int sortByNum(const void *a, const void *b);

};

#endif // SIGDISTRIBUTIONWIDGET_H
