require 'rubygems'
require 'Qt4'


class StringListModel < Qt::AbstractListModel

# Q_OBJECT
#
#public:
# StringListModel(const QStringList &strings, QObject *parent = 0)
#	 : QAbstractListModel(parent), stringList(strings) {}
#
# int rowCount(const QModelIndex &parent = QModelIndex()) const;
# QVariant data(const QModelIndex &index, int role) const;
# QVariant headerData(int section, Qt::Orientation orientation,
#					 int role = Qt::DisplayRole) const;
#
#	Qt::ItemFlags flags(const QModelIndex &index) const;
#    bool setData(const QModelIndex &index, const QVariant &value,
#                  int role = Qt::EditRole);
#	bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex());
#    bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex());

#@stringList
#
#
  def initialize(list=[])

    @stringList=list
    super()

  end

  def rowCount(parent)
    return @stringList.length;
  end
#
  def headerData(section, orientation, role)
    if (role != Qt::DisplayRole)
      return Qt::Variant.new
    end

    if (orientation == Qt::Horizontal)
      return "Column #{section}"
    else
      return "Row #{section}"
    end
  end
#
  def flags(index)
    if (!index.isValid())
      return Qt::ItemIsEnabled
    end
    return Qt::AbstractItemModel.flags(index) | Qt::ItemIsEditable
  end

  def data(index, role)
    if (!index.isValid())
      return Qt::Variant.new()
    end
    if (index.row() >= @stringList.length())
      return Qt::Variant.new()
    end
    if (role == Qt::DisplayRole || role == Qt::EditRole)
      return @stringList.at(index.row())
    else
      return Qt::Variant.new()
    end
  end

  def setData(index, value, role)
    if (index.isValid() && role == Qt::EditRole)
      @stringList[index.row()]=value.toString()
      emit dataChanged(index, index);
      return true;
    end
    return false;
  end

  def insertRows(position, rows, parent)

  end
#
# bool StringListModel::insertRows(int position, int rows, const QModelIndex &parent)
# {
#     beginInsertRows(QModelIndex(), position, position+rows-1);
#
#     for (int row = 0; row < rows; ++row) {
#         stringList.insert(position, "");
#     }
#
#     endInsertRows();
#     return true;
# }
#
  def removeRows(position, rows, parent)

  end

#  bool StringListModel::removeRows(int position, int rows, const QModelIndex &parent)
# {
#     beginRemoveRows(QModelIndex(), position, position+rows-1);
#
#     for (int row = 0; row < rows; ++row) {
#         stringList.removeAt(position);
#     }
#
#     endRemoveRows();
#     return true;
# }
#
#
end


app=Qt::Application.new(ARGV)
#Qt.debug_level = Qt::DebugLevel::High

numbers=[]
numbers << "One" << "Two" << "Three" << "Four" << "Five"
#
model = StringListModel.new(numbers)
#
view = Qt::ListView.new
view.setModel(model)
view.show

app.exec
