mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-25 21:59:30 +01:00
Topping: implement sorting properly
This commit is contained in:
parent
b5d175fc5b
commit
b80ca397ad
3 changed files with 33 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Eliot
|
* Eliot
|
||||||
* Copyright (C) 2010-2012 Olivier Teulière
|
* Copyright (C) 2012-2013 Olivier Teulière
|
||||||
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -21,11 +21,11 @@
|
||||||
#include <QtGui/QStandardItemModel>
|
#include <QtGui/QStandardItemModel>
|
||||||
#include <QtGui/QMenu>
|
#include <QtGui/QMenu>
|
||||||
#include <QtGui/QHeaderView>
|
#include <QtGui/QHeaderView>
|
||||||
|
#include <QtGui/QSortFilterProxyModel>
|
||||||
|
|
||||||
#include "topping_widget.h"
|
#include "topping_widget.h"
|
||||||
#include "qtcommon.h"
|
#include "qtcommon.h"
|
||||||
#include "play_word_mediator.h"
|
#include "play_word_mediator.h"
|
||||||
#include "validator_factory.h"
|
|
||||||
|
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "dic.h"
|
#include "dic.h"
|
||||||
|
@ -59,16 +59,22 @@ ToppingWidget::ToppingWidget(QWidget *parent, PlayModel &iPlayModel, PublicGame
|
||||||
QObject::connect(m_mediator, SIGNAL(notifyProblem(QString)),
|
QObject::connect(m_mediator, SIGNAL(notifyProblem(QString)),
|
||||||
this, SIGNAL(notifyProblem(QString)));
|
this, SIGNAL(notifyProblem(QString)));
|
||||||
|
|
||||||
// Associate the model to the view
|
// Associate the model to the view.
|
||||||
|
// We use a proxy for easy sorting.
|
||||||
m_model = new QStandardItemModel(this);
|
m_model = new QStandardItemModel(this);
|
||||||
tableViewMoves->setModel(m_model);
|
QSortFilterProxyModel * proxyModel = new QSortFilterProxyModel(this);
|
||||||
m_model->setColumnCount(3);
|
proxyModel->setDynamicSortFilter(true);
|
||||||
m_model->setHeaderData(0, Qt::Horizontal, _q("Word"), Qt::DisplayRole);
|
proxyModel->setSourceModel(m_model);
|
||||||
m_model->setHeaderData(1, Qt::Horizontal, _q("Ref"), Qt::DisplayRole);
|
tableViewMoves->setModel(proxyModel);
|
||||||
m_model->setHeaderData(2, Qt::Horizontal, _q("Points"), Qt::DisplayRole);
|
|
||||||
|
|
||||||
QObject::connect(lineEditRack, SIGNAL(returnPressed()),
|
m_model->setColumnCount(4);
|
||||||
this, SLOT(search()));
|
m_model->setHeaderData(0, Qt::Horizontal, _q("#"), Qt::DisplayRole);
|
||||||
|
m_model->setHeaderData(1, Qt::Horizontal, _q("Word"), Qt::DisplayRole);
|
||||||
|
m_model->setHeaderData(2, Qt::Horizontal, _q("Ref"), Qt::DisplayRole);
|
||||||
|
m_model->setHeaderData(3, Qt::Horizontal, _q("Points"), Qt::DisplayRole);
|
||||||
|
tableViewMoves->sortByColumn(3);
|
||||||
|
// XXX: why is this needed? It is not needed in the ArbitrationWidget class
|
||||||
|
tableViewMoves->horizontalHeader()->setSortIndicator(3, Qt::DescendingOrder);
|
||||||
|
|
||||||
// Add a context menu to the table header
|
// Add a context menu to the table header
|
||||||
QAction *lockSizesAction = new QAction(_q("Lock columns sizes"), this);
|
QAction *lockSizesAction = new QAction(_q("Lock columns sizes"), this);
|
||||||
|
@ -82,6 +88,8 @@ ToppingWidget::ToppingWidget(QWidget *parent, PlayModel &iPlayModel, PublicGame
|
||||||
// Allow very thin columns
|
// Allow very thin columns
|
||||||
tableViewMoves->horizontalHeader()->setMinimumSectionSize(1);
|
tableViewMoves->horizontalHeader()->setMinimumSectionSize(1);
|
||||||
|
|
||||||
|
tableViewMoves->horizontalHeader()->resizeSection(1, 140);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +123,6 @@ void ToppingWidget::updateModel()
|
||||||
// Clear the table
|
// Clear the table
|
||||||
m_model->removeRows(0, m_model->rowCount());
|
m_model->removeRows(0, m_model->rowCount());
|
||||||
|
|
||||||
// Force the sort column
|
|
||||||
tableViewMoves->sortByColumn(2);
|
|
||||||
|
|
||||||
if (m_game == NULL)
|
if (m_game == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -127,26 +132,28 @@ void ToppingWidget::updateModel()
|
||||||
const Move &m = triedMoves[i];
|
const Move &m = triedMoves[i];
|
||||||
int rowNum = m_model->rowCount();
|
int rowNum = m_model->rowCount();
|
||||||
m_model->insertRow(rowNum);
|
m_model->insertRow(rowNum);
|
||||||
|
m_model->setData(m_model->index(rowNum, 0), i);
|
||||||
if (m.isValid())
|
if (m.isValid())
|
||||||
{
|
{
|
||||||
m_model->setData(m_model->index(rowNum, 0), qfw(m.getRound().getWord()));
|
m_model->setData(m_model->index(rowNum, 1), qfw(m.getRound().getWord()));
|
||||||
m_model->setData(m_model->index(rowNum, 1),
|
m_model->setData(m_model->index(rowNum, 2),
|
||||||
qfw(m.getRound().getCoord().toString()));
|
qfw(m.getRound().getCoord().toString()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ASSERT(m.isInvalid(), "Unhandled move type");
|
ASSERT(m.isInvalid(), "Unhandled move type");
|
||||||
m_model->setData(m_model->index(rowNum, 0), qfw(m.getBadWord()));
|
m_model->setData(m_model->index(rowNum, 1), qfw(m.getBadWord()));
|
||||||
m_model->setData(m_model->index(rowNum, 1), qfw(m.getBadCoord()));
|
m_model->setData(m_model->index(rowNum, 2), qfw(m.getBadCoord()));
|
||||||
}
|
}
|
||||||
m_model->setData(m_model->index(rowNum, 2), m.getScore());
|
m_model->setData(m_model->index(rowNum, 3), m.getScore());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_autoResizeColumns)
|
if (m_autoResizeColumns)
|
||||||
{
|
{
|
||||||
tableViewMoves->resizeColumnToContents(0);
|
tableViewMoves->resizeColumnToContents(0);
|
||||||
tableViewMoves->resizeColumnToContents(1);
|
// tableViewMoves->resizeColumnToContents(1);
|
||||||
tableViewMoves->resizeColumnToContents(2);
|
tableViewMoves->resizeColumnToContents(2);
|
||||||
|
tableViewMoves->resizeColumnToContents(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Eliot
|
* Eliot
|
||||||
* Copyright (C) 2008-2012 Olivier Teulière
|
* Copyright (C) 2012-2013 Olivier Teulière
|
||||||
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
|
|
@ -142,9 +142,15 @@
|
||||||
<property name="sortingEnabled">
|
<property name="sortingEnabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<attribute name="horizontalHeaderHighlightSections">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
<attribute name="horizontalHeaderStretchLastSection">
|
<attribute name="horizontalHeaderStretchLastSection">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute name="verticalHeaderVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in a new issue