#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QStandardItemModel>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    model = new QStandardItemModel(4, 3, this);

    QStandardItem *item0 = new QStandardItem(QString("101"));
    model->setItem(0, 0, item0);
    QStandardItem *item1 = new QStandardItem(QString("101"));
    model->setItem(1, 0, item1);
    QStandardItem *item2 = new QStandardItem(QString("101"));
    model->setItem(2, 0, item2);
    QStandardItem *item3 = new QStandardItem(QString("101"));
    model->setItem(3, 0, item3);

    QStandardItem *item10 = new QStandardItem(QString("This is a short string."));
    model->setItem(0, 2, item10);
    QStandardItem *item11 = new QStandardItem(QString("This is a not too short string. This is a really not too short string."));
    model->setItem(1, 2, item11);
    QStandardItem *item12 = new QStandardItem(QString("This is a short string again."));
    model->setItem(2, 2, item12);
    QStandardItem *item13 = new QStandardItem(QString("This is a very looong string. This is a really very looong string. Very looong string."));
    model->setItem(3, 2, item13);

    ui->tableView->setModel(model);
    ui->tableView->horizontalHeader()->setResizeMode(
            QHeaderView::ResizeToContents);
    ui->tableView->verticalHeader()->setResizeMode(
            QHeaderView::ResizeToContents);
    ui->tableView->resizeColumnsToContents();
    ui->tableView->resizeRowsToContents();

    connect(ui->tableView->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
            ui->tableView, SLOT(resizeRowsToContents()));
}

MainWindow::~MainWindow()
{
    delete ui;
    delete model;
}
