/***************************************************************************
 *   Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl>                 *
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

#ifndef FORWARDINGMODEL_H
#define FORWARDINGMODEL_H

#include <QAbstractTableModel>
#include <QModelIndex>
#include <QStringList>

/**
  Class that can be serialized into some type stored in QVariant (for example QString or QStringList).
*/
class VariantSerializable {
public:
  virtual QVariant toVariant() const=0;
  virtual void fromVariant(const QVariant& data)=0;
  virtual ~VariantSerializable() {}
};

class ForwardingModel : public QAbstractTableModel, public VariantSerializable
{
Q_OBJECT
public:
  ForwardingModel(QObject* parent = 0);
  bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
  bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
  int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
  int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
  virtual QFlags< Qt::ItemFlag > flags(const QModelIndex& index) const;
  QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
  QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;

  // QStringList is used to store data
  virtual QVariant toVariant() const;
  virtual void fromVariant(const QVariant& data);

private:
  struct Item {
    bool remote;
    quint16 lport;
    quint16 tport;
    QString host;
  };
  QList<Item> items;
};

#endif // FORWARDINGMODEL_H
