mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 21:36:16 +00:00
Dive site edit: add second "create" line without completion
We now have TWO special entries. One with just what the user has typed and one with the first completion of that text. This way both Henrik and Linus can get what they want. I'm not sure I love this, but it's easy to revert if the consensus is that this is too confusing. But it's much easier to discuss this if people can actually play with it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4ec27b1751
commit
f98ace681a
3 changed files with 18 additions and 17 deletions
|
@ -29,7 +29,7 @@ int LocationInformationModel::columnCount(const QModelIndex &parent) const
|
||||||
int LocationInformationModel::rowCount(const QModelIndex &parent) const
|
int LocationInformationModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return internalRowCount + 1;
|
return internalRowCount + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
||||||
|
@ -38,17 +38,19 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
// Special case to handle the 'create dive site' with name.
|
// Special case to handle the 'create dive site' with name.
|
||||||
if (index.row() == 0) {
|
if (index.row() < 2) {
|
||||||
if (index.column() == UUID)
|
if (index.column() == UUID)
|
||||||
return 0;
|
return 0;
|
||||||
switch(role) {
|
switch(role) {
|
||||||
case Qt::DisplayRole : {
|
case Qt::DisplayRole : {
|
||||||
struct dive_site *ds;
|
if (index.row() == 1) {
|
||||||
int i;
|
struct dive_site *ds;
|
||||||
for_each_dive_site(i, ds) {
|
int i;
|
||||||
QString dsName(ds->name);
|
for_each_dive_site(i, ds) {
|
||||||
if (dsName.startsWith(textField->text()))
|
QString dsName(ds->name);
|
||||||
return dsName;
|
if (dsName.startsWith(textField->text()))
|
||||||
|
return dsName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return textField->text();
|
return textField->text();
|
||||||
}
|
}
|
||||||
|
@ -60,8 +62,8 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The dive sites are -1 because of the first item.
|
// The dive sites are -2 because of the first two items.
|
||||||
struct dive_site *ds = get_dive_site(index.row()-1);
|
struct dive_site *ds = get_dive_site(index.row() - 2);
|
||||||
|
|
||||||
if (!ds)
|
if (!ds)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -112,7 +114,7 @@ int32_t LocationInformationModel::addDiveSite(const QString& name, int lon, int
|
||||||
latitude.udeg = lat;
|
latitude.udeg = lat;
|
||||||
longitude.udeg = lon;
|
longitude.udeg = lon;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), dive_site_table.nr + 1, dive_site_table.nr + 1);
|
beginInsertRows(QModelIndex(), dive_site_table.nr + 2, dive_site_table.nr + 2);
|
||||||
uint32_t uuid = create_dive_site_with_gps(name.toUtf8().data(), latitude, longitude);
|
uint32_t uuid = create_dive_site_with_gps(name.toUtf8().data(), latitude, longitude);
|
||||||
qSort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than);
|
qSort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than);
|
||||||
internalRowCount = dive_site_table.nr;
|
internalRowCount = dive_site_table.nr;
|
||||||
|
@ -122,7 +124,7 @@ int32_t LocationInformationModel::addDiveSite(const QString& name, int lon, int
|
||||||
|
|
||||||
bool LocationInformationModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool LocationInformationModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() == 0)
|
if (!index.isValid() || index.row() < 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (role != Qt::EditRole)
|
if (role != Qt::EditRole)
|
||||||
|
@ -140,7 +142,7 @@ bool LocationInformationModel::removeRows(int row, int count, const QModelIndex
|
||||||
if(row >= rowCount())
|
if(row >= rowCount())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), row + 1, row + 1);
|
beginRemoveRows(QModelIndex(), row + 2, row + 2);
|
||||||
struct dive_site *ds = get_dive_site(row);
|
struct dive_site *ds = get_dive_site(row);
|
||||||
if (ds)
|
if (ds)
|
||||||
delete_dive_site(ds->uuid);
|
delete_dive_site(ds->uuid);
|
||||||
|
|
|
@ -256,8 +256,8 @@ void LocationManagementEditHelper::handleActivation(const QModelIndex& activated
|
||||||
activated.row(), LocationInformationModel::UUID);
|
activated.row(), LocationInformationModel::UUID);
|
||||||
last_uuid = uuidIdx.data().toInt();
|
last_uuid = uuidIdx.data().toInt();
|
||||||
|
|
||||||
// Special case: first option, add dive site.
|
// Special case: first two options: add dive site.
|
||||||
if (activated.row() == 0) {
|
if (activated.row() < 2) {
|
||||||
qDebug() << "Setting to " << activated.data().toString();
|
qDebug() << "Setting to " << activated.data().toString();
|
||||||
emit setLineEditText(activated.data().toString());
|
emit setLineEditText(activated.data().toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -503,9 +503,8 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||||
struct dive_site *ds = get_dive_site_by_uuid(
|
struct dive_site *ds = get_dive_site_by_uuid(
|
||||||
index.model()->data(index.model()->index(index.row(),0)).toInt()
|
index.model()->data(index.model()->index(index.row(),0)).toInt()
|
||||||
);
|
);
|
||||||
|
|
||||||
//Special case: do not show name, but instead, show
|
//Special case: do not show name, but instead, show
|
||||||
if (index.row() == 0) {
|
if (index.row() < 2) {
|
||||||
diveSiteName = index.data().toString();
|
diveSiteName = index.data().toString();
|
||||||
bottomText = index.data(Qt::ToolTipRole).toString();
|
bottomText = index.data(Qt::ToolTipRole).toString();
|
||||||
goto print_part;
|
goto print_part;
|
||||||
|
|
Loading…
Add table
Reference in a new issue