mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Show only 1 possibility if string is unique
We should only show one possibility if the dive_site name string is unique - we don't have that dive_site yet - so we pass to the Completer filter a Dummy string that will surelly not be a dive site - konami code. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
86bd9c7a90
commit
56240cff5b
2 changed files with 29 additions and 9 deletions
|
@ -32,6 +32,18 @@ int LocationInformationModel::rowCount(const QModelIndex &parent) const
|
||||||
return internalRowCount + 2;
|
return internalRowCount + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct dive_site *get_dive_site_name_start_which_str(const QString& str) {
|
||||||
|
struct dive_site *ds;
|
||||||
|
int i;
|
||||||
|
for_each_dive_site(i,ds) {
|
||||||
|
QString dsName(ds->name);
|
||||||
|
if (dsName.startsWith(str)) {
|
||||||
|
return ds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
|
@ -44,20 +56,25 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
|
||||||
switch(role) {
|
switch(role) {
|
||||||
case Qt::DisplayRole : {
|
case Qt::DisplayRole : {
|
||||||
if (index.row() == 1) {
|
if (index.row() == 1) {
|
||||||
struct dive_site *ds;
|
struct dive_site *ds = get_dive_site_name_start_which_str(textField->text());
|
||||||
int i;
|
if(ds)
|
||||||
for_each_dive_site(i, ds) {
|
return ds->name;
|
||||||
QString dsName(ds->name);
|
|
||||||
if (dsName.startsWith(textField->text()))
|
|
||||||
return dsName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return textField->text();
|
return textField->text();
|
||||||
}
|
}
|
||||||
case Qt::ToolTipRole : {
|
case Qt::ToolTipRole : {
|
||||||
return QString(tr("Create dive site with this name"));
|
return QString(tr("Create dive site with this name"));
|
||||||
}
|
}
|
||||||
case Qt::EditRole : return textField->text();
|
case Qt::EditRole : {
|
||||||
|
if (index.row() == 1) {
|
||||||
|
struct dive_site *ds = get_dive_site_name_start_which_str(textField->text());
|
||||||
|
if (!ds)
|
||||||
|
return "NOT HERE";
|
||||||
|
if (QString(ds->name) == textField->text())
|
||||||
|
return "NOT HERE";
|
||||||
|
}
|
||||||
|
return textField->text();
|
||||||
|
}
|
||||||
case Qt::DecorationRole : return QIcon(":plus");
|
case Qt::DecorationRole : return QIcon(":plus");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QAbstractProxyModel>
|
||||||
|
|
||||||
QSize DiveListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QSize DiveListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
@ -489,12 +490,14 @@ LocationFilterDelegate::LocationFilterDelegate(QObject *parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &origIdx) const
|
||||||
{
|
{
|
||||||
QFont fontBigger = qApp->font();
|
QFont fontBigger = qApp->font();
|
||||||
QFont fontSmaller = qApp->font();
|
QFont fontSmaller = qApp->font();
|
||||||
QFontMetrics fmBigger(fontBigger);
|
QFontMetrics fmBigger(fontBigger);
|
||||||
QStyleOptionViewItemV4 opt = option;
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
const QAbstractProxyModel *proxyModel = dynamic_cast<const QAbstractProxyModel*>(origIdx.model());
|
||||||
|
QModelIndex index = proxyModel->mapToSource(origIdx);
|
||||||
QStyledItemDelegate::initStyleOption(&opt, index);
|
QStyledItemDelegate::initStyleOption(&opt, index);
|
||||||
QBrush bg;
|
QBrush bg;
|
||||||
QString diveSiteName = index.data().toString();
|
QString diveSiteName = index.data().toString();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue