<file>res/images/zoom_in.png</file>
<file>res/images/zoom_out.png</file>
<file>res/images/location_search.png</file>
+ <file>res/images/search_history.png</file>
+ <file>res/images/clear_btn_d.png</file>
+ <file>res/images/clear_btn_s.png</file>
+ <file>res/images/clear_btn.png</file>
</qresource>
</RCC>
ui/routewaypointlistview.cpp \
user/user.cpp \
ui/locationsearchpanel.cpp \
- ui/textmodifier.cpp
+ ui/textmodifier.cpp \
+ ui/searchhistorylistview.cpp \
+ ui/searchhistorylistitem.cpp
HEADERS += application.h \
common.h \
coordinates/geocoordinate.h \
ui/routewaypointlistview.h \
user/user.h \
ui/locationsearchpanel.h \
- ui/textmodifier.h
+ ui/textmodifier.h \
+ ui/searchhistorylistview.h \
+ ui/searchhistorylistitem.h
QT += network \
webkit
DEFINES += QT_NO_DEBUG_OUTPUT
: m_selected(false),
m_expandedHeight(ITEM_MIN_HEIGHT),
m_normalHeight(ITEM_MIN_HEIGHT),
- m_subItemTextWidth(0)
+ m_subItemTextWidth(SUBITEM_TEXT_MAX_WIDTH)
{
qDebug() << __PRETTY_FUNCTION__;
void ListView::clearUnused(const QStringList &itemIDs)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__ << itemIDs.count();
foreach (QString key, m_listItems.keys()) {
if (!itemIDs.contains(key)) {
{
qDebug() << __PRETTY_FUNCTION__;
- QHashIterator<QString, ListItem*> itemIterator(m_listItems);
- ListItem *item = 0;
- int counter = 0;
+ ListItem *listItem = 0;
- while (itemIterator.hasNext()) {
- itemIterator.next();
- if (index == counter) {
- item = itemIterator.value();
- break;
- }
- counter++;
+ if (index < count())
+ listItem = dynamic_cast<ListItem*>(item(index));
+
+ return listItem;
+}
+
+void ListView::prependListItem(const QString &key, ListItem *item)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (!m_listItems.contains(key)) {
+ insertItem(0, item);
+ m_listItems.insert(key, item);
}
+}
- return item;
+void ListView::removeLastItem()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ ListItem *item = listItemAt(count() - 1);
+
+ if (item) {
+ if (item) {
+ m_listItems.remove(item->title());
+ takeItem(row(item));
+ if (m_currentItem == item)
+ m_currentItem = 0;
+ delete item;
+ }
+ }
}
ListItem *ListView::selectedItem()
#ifndef LISTVIEW_H
#define LISTVIEW_H
+#include <QHash>
#include <QListWidget>
class GeoCoordinate;
ListItem *listItemAt(int index);
/**
+ * @brief Prepends item to view and item list.
+ *
+ * @param key user ID
+ * @param item item to prepend to view and list
+ */
+ void prependListItem(const QString &key, ListItem *item);
+
+ /**
+ * @brief Removes last ListItem in list.
+ */
+ void removeLastItem();
+
+ /**
* @brief Returns selected ListItem.
*
* @return ListItem if there is selected, 0 otherwise
USA.
*/
+#include <QPair>
+#include <QSettings>
+
+#include "avatarimage.h"
+#include "../common.h"
+#include "extendedlistitem.h"
#include "extendedlistitemdelegate.h"
#include "locationlistitem.h"
#include "locationlistview.h"
#include "imagebutton.h"
#include "panelcommon.h"
#include "routing/location.h"
+#include "searchhistorylistitem.h"
+#include "searchhistorylistview.h"
#include "locationsearchpanel.h"
+const QString SETTINGS_SEARCH_HISTORY = "SEARCH_HISTORY";
+
LocationSearchPanel::LocationSearchPanel(QWidget *parent)
: PanelBase(parent)
{
headerLayout->addWidget(m_resultsLabel, 0, Qt::AlignCenter);
setHeaderText(0);
+ // --- SEARCH HISTORY LIST VIEW ---
+ m_searchHistoryListView = new SearchHistoryListView(this);
+ m_searchHistoryListView->setItemDelegate(new ExtendedListItemDelegate(this));
+
// --- SEARCH RESULTS LIST VIEW ---
m_locationListView = new LocationListView(this);
m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
QVBoxLayout *resultsListViewLayout = new QVBoxLayout;
resultsListViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
+ resultsListViewLayout->addWidget(m_searchHistoryListView);
resultsListViewLayout->addWidget(m_locationListView);
// --- MAIN LAYOUT ---
ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png",
":/res/images/search_s.png", "", this);
+
connect(searchLocationButton, SIGNAL(clicked()),
this, SIGNAL(requestSearchLocation()));
+ m_clearLocationListButton = new ImageButton(":/res/images/clear_btn.png",
+ ":/res/images/clear_btn_s.png",
+ ":/res/images/clear_btn_d.png", this);
+ m_clearLocationListButton->setDisabled(true);
+
+ connect(m_clearLocationListButton, SIGNAL(clicked()),
+ this, SLOT(showSearchHistoryList()));
+
m_contextButtonLayout->addWidget(m_routeButton);
m_contextButtonLayout->addWidget(searchLocationButton);
+ m_contextButtonLayout->addWidget(m_clearLocationListButton);
+
+ readSettings();
+ showSearchHistoryList();
+}
+
+LocationSearchPanel::~LocationSearchPanel()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ QList<QVariant> searchHistories;
+
+ for (int i = 0; i < m_searchHistoryListView->count(); ++i) {
+ SearchHistoryListItem *item = dynamic_cast<SearchHistoryListItem*>(
+ m_searchHistoryListView->listItemAt(i));
+
+ if (item) {
+ QList<QVariant> searchHistory;
+ searchHistory.append(item->title());
+ searchHistory.append(item->dateTime().toString());
+ searchHistories.append(searchHistory);
+ }
+ }
+
+ settings.setValue(SETTINGS_SEARCH_HISTORY, searchHistories);
+}
+
+void LocationSearchPanel::appendSearchHistory(QString searchString, QDateTime currentDateTime)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (m_searchHistoryListView->count() >= 10)
+ m_searchHistoryListView->removeLastItem();
+
+ SearchHistoryListItem *item = new SearchHistoryListItem();
+ item->setSearchHistoryData(searchString, currentDateTime);
+ m_searchHistoryListView->prependListItem(searchString, item);
}
void LocationSearchPanel::clearListsSelections()
{
qDebug() << __PRETTY_FUNCTION__;
+ m_searchHistoryListView->hide();
setHeaderText(locations.count());
-
m_locationListView->clearList();
for (int i = 0; i < locations.size(); ++i) {
}
m_locationListView->scrollToTop();
+ m_clearLocationListButton->setEnabled(true);
+ m_locationListView->show();
+}
+
+void LocationSearchPanel::readSettings()
+{
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+ QList<QVariant> searchHistories = settings.value(
+ SETTINGS_SEARCH_HISTORY).toList();
+
+ for (int i = 0; i < searchHistories.count(); ++i) {
+ QList<QVariant> searchHistory = searchHistories.at(i).toList();
+ appendSearchHistory(searchHistory.at(0).toString(),
+ QDateTime::fromString(searchHistory.at(1).toString()));
+ }
}
void LocationSearchPanel::routeToSelectedLocation()
m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty());
}
+
+void LocationSearchPanel::showSearchHistoryList()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_locationListView->clearList();
+ m_locationListView->hide();
+ m_resultsLabel->setText(tr("Search history:"));
+ m_clearLocationListButton->setDisabled(true);
+ m_searchHistoryListView->show();
+}
class ImageButton;
class Location;
class LocationListView;
+class SearchHistoryListView;
/**
* @brief Location search panel
*/
LocationSearchPanel(QWidget *parent = 0);
+ /**
+ * @brief Destructor
+ *
+ * Writes search history to settings.
+ */
+ ~LocationSearchPanel();
+
/*******************************************************************************
* BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
******************************************************************************/
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
private:
+ void readSettings();
+
/**
* @brief Set text for header
*
void setHeaderText(int count);
private slots:
+
+ void appendSearchHistory(QString searchString, QDateTime currentTime = QDateTime());
+
/**
* @brief Clears lists' selections.
*
void clearListsSelections();
/**
+ * @brief Shows search history list.
+ */
+ void showSearchHistoryList();
+
+ /**
* @brief Populates location list view.
*
* @param locations list of Location objects
* DATA MEMBERS
******************************************************************************/
private:
- QLabel *m_resultsLabel; ///< Location list label
+ QLabel *m_resultsLabel; ///< Location list label
- ImageButton *m_routeButton; ///< Route to location button
- LocationListView *m_locationListView; ///< Search results list view
+ ImageButton *m_clearLocationListButton; ///< Clear location list button
+ ImageButton *m_routeButton; ///< Route to location button
+ SearchHistoryListView *m_searchHistoryListView; ///< Search history list view
+ LocationListView *m_locationListView; ///< Search results list view
};
#endif // LOCATIONSEARCHPANEL_H
connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
this, SLOT(startLocationSearch()));
+
+ connect(this, SIGNAL(searchForLocation(QString)),
+ m_locationSearchPanel, SLOT(appendSearchHistory(QString)));
}
void MainWindow::buildMap()
--- /dev/null
+#include <QDebug>
+
+#include "avatarimage.h"
+#include "../common.h"
+#include "listcommon.h"
+
+#include "searchhistorylistitem.h"
+
+const int SEARCH_HISTORY_SUBITEM_TEXT_MAX_WIDTH = SUBITEM_TEXT_MAX_WIDTH + MARGIN + IMAGE_WIDTH;
+
+SearchHistoryListItem::SearchHistoryListItem()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ setSubitemTextWidth(SEARCH_HISTORY_SUBITEM_TEXT_MAX_WIDTH);
+}
+
+SearchHistoryListItem::~SearchHistoryListItem()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+QDateTime SearchHistoryListItem::dateTime() const
+{
+ return m_dateTime;
+}
+
+void SearchHistoryListItem::setDateTime(const QDateTime &dateTime)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (dateTime.isNull())
+ m_dateTime = QDateTime::currentDateTime();
+ else
+ m_dateTime = dateTime;
+}
+
+void SearchHistoryListItem::setSearchHistoryData(const QString &searchString,
+ const QDateTime &dateTime)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ setDateTime(dateTime);
+
+ setTitle(shortenText(searchString, ITEM_WIDTH - 3 * MARGIN,
+ ListItem::TEXT_SIZE_NORMAL));
+
+ setImage(AvatarImage::create(QPixmap(":/res/images/search_history.png"), AvatarImage::Small));
+
+ clearSubItems();
+ addSubItem(m_dateTime.toString(), QPixmap(":/res/images/clock.png"));
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Jussi Laitinen - jussi.laitinen@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#ifndef SEARCHHISTORYLISTITEM_H
+#define SEARCHHISTORYLISTITEM_H
+
+#include <QDateTime>
+
+#include "extendedlistitem.h"
+
+/**
+* @brief List item stores information about search history.
+*
+* @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
+*/
+class SearchHistoryListItem : public ExtendedListItem
+{
+public:
+ /**
+ * @brief Constructor.
+ *
+ * Sets sub items' text width.
+ */
+ SearchHistoryListItem();
+
+ /**
+ * @brief Destructor.
+ */
+ ~SearchHistoryListItem();
+
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+ /**
+ * @brief Returns date and time.
+ *
+ * @return QDateTime
+ */
+ QDateTime dateTime() const;
+
+ /**
+ * @brief Set location data for this item.
+ *
+ * @param location Location data
+ */
+ void setSearchHistoryData(const QString &searchString, const QDateTime &dateTime);
+
+private:
+ /**
+ * @brief Sets date and time.
+ *
+ * @param dateTime QDateTime date and time
+ */
+ void setDateTime(const QDateTime &dateTime);
+
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
+private:
+ QDateTime m_dateTime; ///< Date time
+};
+
+#endif // LOCATIONLISTITEM_H