Random fixes and improvements

Whitespace fixes, constructor fixes, new slot (still unused)

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-22 14:31:56 -03:00 committed by Dirk Hohndel
parent fdec250723
commit eb2c78e953
2 changed files with 25 additions and 18 deletions

View file

@ -410,12 +410,10 @@ bool DiveLocationModel::setData(const QModelIndex& index, const QVariant& value,
return true; return true;
} }
DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent),
proxy(new DiveLocationFilterProxyModel()), model(new DiveLocationModel()), view(new DiveLocationListView())
{ {
location_line_edit = this; location_line_edit = this;
proxy = new DiveLocationFilterProxyModel();
model = new DiveLocationModel();
view = new DiveLocationListView();
proxy->setSourceModel(model); proxy->setSourceModel(model);
proxy->setFilterKeyColumn(DiveLocationModel::NAME); proxy->setFilterKeyColumn(DiveLocationModel::NAME);
@ -429,19 +427,24 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent)
view->setSelectionMode(QAbstractItemView::SingleSelection); view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setParent(0, Qt::Popup); view->setParent(0, Qt::Popup);
view->installEventFilter(this); view->installEventFilter(this);
view->setFocusProxy(location_line_edit); view->setFocusPolicy(Qt::NoFocus);
view->setFocusProxy(this);
connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName); connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName);
connect(this, &QLineEdit::editingFinished, this, &DiveLocationLineEdit::setDiveSiteName);
connect(view, &QAbstractItemView::activated, this, &DiveLocationLineEdit::itemActivated); connect(view, &QAbstractItemView::activated, this, &DiveLocationLineEdit::itemActivated);
} }
void DiveLocationLineEdit::setDiveSiteName()
{
}
bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e)
{ {
if(e->type() == QEvent::KeyPress) { if(e->type() == QEvent::KeyPress) {
QKeyEvent *keyEv = (QKeyEvent*) e; QKeyEvent *keyEv = (QKeyEvent*) e;
qDebug() << view->focusProxy()->objectName();
if (keyEv->key() == Qt::Key_Escape) { if (keyEv->key() == Qt::Key_Escape) {
view->hide(); view->hide();
return true; return true;
@ -451,15 +454,12 @@ bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e)
view->hide(); view->hide();
return false; return false;
} }
event(e); event(e);
} } else if(e->type() == QEvent::MouseButtonPress ) {
if (!view->underMouse()) {
if(e->type() == QEvent::MouseButtonPress ) { view->hide();
if (!view->underMouse()) { return true;
view->hide(); }
return true;
}
} }
return false; return false;
@ -507,7 +507,6 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s)
void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev)
{ {
qDebug() << "Pressing key" << ev->key();
QLineEdit::keyPressEvent(ev); QLineEdit::keyPressEvent(ev);
if(ev->key() != Qt::Key_Left && if(ev->key() != Qt::Key_Left &&
ev->key() != Qt::Key_Right && ev->key() != Qt::Key_Right &&
@ -554,8 +553,8 @@ void DiveLocationLineEdit::showPopup()
view->setGeometry(pos.x(), pos.y(), w, h); view->setGeometry(pos.x(), pos.y(), w, h);
if (!view->isVisible()) { if (!view->isVisible()) {
view->show(); proxy->invalidate();
view->setFocus(); view->show();
} }
} }

View file

@ -90,11 +90,17 @@ public:
class DiveLocationLineEdit : public QLineEdit { class DiveLocationLineEdit : public QLineEdit {
Q_OBJECT Q_OBJECT
public: public:
enum DiveSiteType { NO_DIVE_SITE, NEW_DIVE_SITE, EXISTING_DIVE_SITE };
DiveLocationLineEdit(QWidget *parent =0 ); DiveLocationLineEdit(QWidget *parent =0 );
void refreshDiveSiteCache(); void refreshDiveSiteCache();
void setTemporaryDiveSiteName(const QString& s); void setTemporaryDiveSiteName(const QString& s);
bool eventFilter(QObject*, QEvent*); bool eventFilter(QObject*, QEvent*);
void itemActivated(const QModelIndex& index); void itemActivated(const QModelIndex& index);
void setDiveSiteName();
DiveSiteType currDiveSiteType() const;
uint32_t currDiveSiteUuid() const;
protected: protected:
void keyPressEvent(QKeyEvent *ev); void keyPressEvent(QKeyEvent *ev);
void showPopup(); void showPopup();
@ -102,6 +108,8 @@ private:
DiveLocationFilterProxyModel *proxy; DiveLocationFilterProxyModel *proxy;
DiveLocationModel *model; DiveLocationModel *model;
DiveLocationListView *view; DiveLocationListView *view;
DiveSiteType currType;
uint32_t currUuid;
}; };
#endif #endif