Stabilize the location model/proxy model

Since I removed the old location edit from the UI, I also need to
remove a bit of code from the UI that was calling it.

fix a few crashes regarding the old location edit.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-09-21 15:04:52 -03:00 committed by Dirk Hohndel
parent be6e190bd2
commit 8c9a4ecd4b
3 changed files with 33 additions and 33 deletions

View file

@ -7,6 +7,7 @@
#include "filtermodels.h"
#include "divelocationmodel.h"
#include "divesitehelpers.h"
#include "modeldelegates.h"
#include <QDebug>
#include <QShowEvent>
@ -327,13 +328,19 @@ DiveLocationLineEdit *location_line_edit = 0;
bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
if(source_row == 0 || source_row == 1)
if(source_row == 0)
return true;
QString sourceString = sourceModel()->index(source_row, DiveLocationModel::NAME).data(Qt::DisplayRole).toString();
return sourceString.toLower().startsWith(location_line_edit->text().toLower());
}
bool DiveLocationFilterProxyModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const
{
return source_left.data().toString() <= source_right.data().toString();
}
DiveLocationModel::DiveLocationModel(QObject *o)
{
resetModel();
@ -342,7 +349,6 @@ DiveLocationModel::DiveLocationModel(QObject *o)
void DiveLocationModel::resetModel()
{
beginResetModel();
qDebug() << "Dive site table size" <<dive_site_table.nr;
endResetModel();
}
@ -403,18 +409,20 @@ bool DiveLocationModel::setData(const QModelIndex& index, const QVariant& value,
DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent)
{
location_line_edit = this;
proxy = new DiveLocationFilterProxyModel();
model = new DiveLocationModel();
view = new DiveLocationListView();
proxy->setSourceModel(model);
view->setModel(model);
proxy->setFilterKeyColumn(DiveLocationModel::NAME);
view->setModel(proxy);
view->setModelColumn(DiveLocationModel::NAME);
view->setItemDelegate(new LocationFilterDelegate());
connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName);
//HACK:
/* This is being show currently just to test. */
qDebug() << "AAAAAAH";
qDebug() << model->rowCount() << model->columnCount();
view->show();
}
@ -429,7 +437,7 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString& str)
int i;
for_each_dive_site(i,ds) {
QString dsName(ds->name);
if (dsName.startsWith(str)) {
if (dsName.toLower().startsWith(str.toLower())) {
return ds;
}
}
@ -439,11 +447,19 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString& str)
void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s)
{
QModelIndex i0 = model->index(0, DiveLocationModel::NAME);
QModelIndex i1 = model->index(1, DiveLocationModel::NAME);
model->setData(i0, text());
struct dive_site *ds = get_dive_site_name_start_which_str(text());
QModelIndex i1 = model->index(1, DiveLocationModel::NAME);
model->setData(i1, ds ? ds->name : INVALID_DIVE_SITE_NAME);
QString i1_name = INVALID_DIVE_SITE_NAME;
if (struct dive_site *ds = get_dive_site_name_start_which_str(text())) {
const QString orig_name = QString(ds->name).toLower();
const QString new_name = text().toLower();
if (new_name != orig_name)
i1_name = QString(ds->name);
}
model->setData(i1, i1_name );
proxy->invalidate();
}
DiveLocationListView::DiveLocationListView(QWidget *parent)

View file

@ -64,6 +64,7 @@ class DiveLocationFilterProxyModel : public QSortFilterProxyModel {
public:
DiveLocationFilterProxyModel(QObject *parent = 0);
virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
virtual bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const;
};
class DiveLocationModel : public QAbstractTableModel {

View file

@ -55,23 +55,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.extraData->setModel(extraDataModel);
closeMessage();
QCompleter *completer = new QCompleter();
QListView *completerListview = new QListView();
LocationInformationModel::instance()->setFirstRowTextField(ui.location);
completer->setPopup(completerListview);
completer->setModel(LocationInformationModel::instance());
completer->setCompletionColumn(LocationInformationModel::NAME);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completerListview->setItemDelegate(new LocationFilterDelegate());
completerListview->setMouseTracking(true);
locationManagementEditHelper = new LocationManagementEditHelper();
connect(locationManagementEditHelper, &LocationManagementEditHelper::setLineEditText,
ui.location, &QLineEdit::setText);
completerListview->installEventFilter(locationManagementEditHelper);
connect(completerListview, &QAbstractItemView::clicked,
locationManagementEditHelper, &LocationManagementEditHelper::handleActivation);
ui.location->setCompleter(completer);
ui.editDiveSiteButton->setEnabled(true);
connect(ui.editDiveSiteButton, SIGNAL(clicked()), MainWindow::instance(), SIGNAL(startDiveSiteEdit()));
@ -238,7 +221,7 @@ bool MainTab::eventFilter(QObject *obj, QEvent *ev)
if (line) {
if (ev->type() == QEvent::Resize) {
if (line->completer()->popup()->isVisible()) {
/*if (line->completer()->popup()->isVisible()) {
QListView *choices = qobject_cast<QListView*>(line->completer()->popup());
QPoint p = ui.location->mapToGlobal(ui.location->pos());
choices->setGeometry(
@ -246,7 +229,9 @@ bool MainTab::eventFilter(QObject *obj, QEvent *ev)
p.y() + 3,
choices->geometry().width(),
choices->geometry().height());
}
*/
}
}
return false;
@ -392,7 +377,7 @@ void MainTab::enableEdition(EditMode newEditMode)
displayMessage(tr("Multiple dives are being edited."));
} else {
displayMessage(tr("This dive is being edited."));
locationManagementEditHelper->resetDiveSiteUuid();
//locationManagementEditHelper->resetDiveSiteUuid();
}
editMode = newEditMode != NONE ? newEditMode : DIVE;
}
@ -474,10 +459,6 @@ void MainTab::updateDiveInfo(bool clear)
{
// I don't like this code here - but globe() wasn't initialized on the constructor.
{
QListView *completerListview = qobject_cast<QListView*>(ui.location->completer()->popup());
#ifndef NO_MARBLE
connect(completerListview, SIGNAL(entered(QModelIndex)), GlobeGPS::instance(), SLOT(centerOnIndex(QModelIndex)), Qt::UniqueConnection);
#endif
}
ui.location->refreshDiveSiteCache();
@ -861,7 +842,9 @@ void MainTab::updateDisplayedDiveSite()
const QString new_name = ui.location->text();
const QString orig_name = displayed_dive_site.name;
const uint32_t orig_uuid = displayed_dive_site.uuid;
const uint32_t new_uuid = locationManagementEditHelper->diveSiteUuid();
//TODO: FIX THIS
const uint32_t new_uuid = orig_uuid;
// locationManagementEditHelper->diveSiteUuid();
qDebug() << "Updating Displayed Dive Site";