--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary 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 mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "../../includes/History.h"
+#include <QDebug>
+
+History::History(int maxSize, QObject *parent) :
+ QObject(parent)
+{
+ _maxSize = maxSize;
+ currentElement = -1;
+ _prevAvailable = false;
+ _nextAvailable = false;
+ _listAvailable = false;
+}
+
+
+void History::setMaxSize(int size) {
+ if(maxSize() <= 0) return;
+ if(size > _maxSize) {
+ _maxSize = size;
+ }
+ else {
+ _maxSize = size;
+ if(currentElement > 0) {
+ _history.remove(0, currentElement);
+ }
+
+ while(_history.size() > _maxSize) {
+ _history.pop_back();
+ }
+
+ setCurrentElement(0);
+ }
+}
+
+int History::maxSize() {
+ return _maxSize;
+}
+
+void History::add(QString word) {
+ if(currentElement != -1) {
+ //we search the same word so we don't add it again
+ if(_history[currentElement] == word)
+ return;
+ }
+
+ //if we are not in head, we deleted everything ahed us
+ if(currentElement > 0) {
+ _history.remove(0, currentElement);
+ }
+
+
+ if(_history.contains(word)) {
+ _history.remove(_history.indexOf(word));
+ }
+
+ //add new word to head
+ _history.push_front(word);
+
+ //fit to max size
+ while(_history.size() > _maxSize) {
+ _history.pop_back();
+ }
+
+ currentElement = 0;
+
+ if(_history.size() > 1) {
+ _prevAvailable = true;
+ _nextAvailable = false;
+ _listAvailable = true;
+ }
+ else {
+ _prevAvailable = false;
+ _nextAvailable = false;
+ _listAvailable = true;
+ }
+
+ emit historyChanged(_prevAvailable,
+ _nextAvailable,
+ _listAvailable);
+}
+
+QString History::previous() {
+ if(_prevAvailable) {
+ currentElement++;
+
+ _nextAvailable = true;
+
+ if(currentElement+1 == _history.size()) {
+ _prevAvailable = false;
+ }
+
+ emit historyChanged(_prevAvailable,
+ _nextAvailable,
+ _listAvailable);
+
+ return _history[currentElement];
+ }
+ return QString();
+}
+
+QString History::next() {
+ if(_nextAvailable) {
+ currentElement--;
+
+ _prevAvailable = true;
+
+ if(currentElement == 0) {
+ _nextAvailable = false;
+ }
+
+ emit historyChanged(_prevAvailable,
+ _nextAvailable,
+ _listAvailable);
+
+ return _history[currentElement];
+ }
+ return QString();
+}
+
+QStringList History::list() {
+ QStringList result;
+
+ if(_listAvailable) {
+ for(int i=0; i<_history.size(); i++) {
+ result << _history[i];
+ }
+ }
+ return result;
+}
+
+bool History::nextAvailable() {
+ return _nextAvailable;
+}
+
+bool History::prevAvailable() {
+ return _prevAvailable;
+}
+
+bool History::listAvailable() {
+ return _listAvailable;
+}
+
+void History::setCurrentElement(int element) {
+ if(element < 0 || element >= _history.size()) return;
+
+ currentElement = element;
+
+ if(currentElement > 0) {
+ _nextAvailable = true;
+ }
+ else {
+ _nextAvailable = false;
+ }
+
+ if(currentElement+1 < _history.size()) {
+ _prevAvailable = true;
+ }
+ else {
+ _prevAvailable = false;
+ }
+
+ emit historyChanged(_prevAvailable,
+ _nextAvailable,
+ _listAvailable);
+}
connect(&_timerSearch, SIGNAL(timeout()), this, SLOT(translationReady()));
connect(&_timerHtmlSearch, SIGNAL(timeout()), this,
SLOT(htmlTranslationReady()));
+
+ _history = new History(5, this);
}
Backbone::Backbone(QString pluginPath, QString configPath, QObject *parent)
-QList<QString> Backbone::getHistory() {
- //TODO code needed
+History* Backbone::history() {
+ return _history;
}
#include "../../includes/CommonDictInterface.h"
#include "../../includes/settings.h"
#include "../../includes/translation.h"
+#include "../../includes/History.h"
/*! Inner part of dictionary - glues together GUI and plugins
QList<CommonDictInterface*> getPlugins();
//! \return history of performed searches
- QList<QString> getHistory(); //TODO implementation needed (in future)
+ History* history();
//! \return return search fesult
QMultiHash<QString, Translation*> result();
void saveDefaultPrefs(QSettings*);
CommonDictInterface* plugin(QString type); //< search for given type plugin
+ History* _history;
+
};
#endif // BACKBONE_H
gui/MenuWidget.cpp \
gui/MenuTabWidget.cpp \
gui/DictManagerWidget.cpp \
- gui/DictTypeSelectDialog.cpp
+ gui/DictTypeSelectDialog.cpp \
+ backbone/History.cpp \
+ gui/HistoryListDialog.cpp
HEADERS += gui/MainWindow.h \
gui/SearchBarWidget.h \
gui/MenuTabWidget.h \
gui/DictManagerWidget.h \
gui/DictTypeSelectDialog.h \
- gui/TranslationWidgetAutoResizer.h
+ gui/TranslationWidgetAutoResizer.h \
+ ../includes/History.h \
+ gui/HistoryListDialog.h
FORMS += gui/MainWindow.ui
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary 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 mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "HistoryListDialog.h"
+
+HistoryListDialog::HistoryListDialog(History *history, SearchBarWidget *parent):
+ QDialog(parent)
+{
+ this->history = history;
+ searchBar = parent;
+
+ verticalLayout = new QVBoxLayout;
+ setLayout(verticalLayout);
+
+ historyListWidget = new QListWidget;
+ verticalLayout->addWidget(historyListWidget);
+
+
+ QStringList words = history->list();
+
+ for(int i=0; i<words.count(); i++) {
+ QListWidgetItem* item = new QListWidgetItem(
+ QString::number(i+1) + ". " + words[i]);
+ historyListWidget->addItem(item);
+ }
+
+ setModal(true);
+
+ setWindowTitle(tr("History"));
+
+ setMinimumHeight(300);
+
+ connect(historyListWidget, SIGNAL(clicked(QModelIndex)),
+ this, SLOT(itemClicked(QModelIndex)));
+}
+
+
+void HistoryListDialog::itemClicked(QModelIndex index) {
+ QString selectedWord = history->list()[index.row()];
+
+ history->setCurrentElement(index.row());
+
+ searchBar->search(selectedWord);
+
+ accept();
+}
+
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary 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 mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef HISTORYLISTDIALOG_H
+#define HISTORYLISTDIALOG_H
+
+#include <QDialog>
+#include "SearchBarWidget.h"
+#include "../../includes/History.h"
+#include <QtGui>
+
+class HistoryListDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ explicit HistoryListDialog(History* history, SearchBarWidget*parent);
+
+private Q_SLOTS:
+ void itemClicked(QModelIndex);
+private:
+ History* history;
+ SearchBarWidget* searchBar;
+
+ QListWidget* historyListWidget;
+ QVBoxLayout* verticalLayout;
+
+};
+
+#endif // HISTORYLISTDIALOG_H
#include "SearchBarWidget.h"
#include <QDebug>
#include "../../includes/DictDialog.h"
+#include "HistoryListDialog.h"
SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
this->backbone = backbone;
+ history = backbone->history();
+
initializeUI();
setMaximumHeight(150);
connect(backbone, SIGNAL(htmlReady()),
this, SLOT(setIdle()));
+
+ connect(history, SIGNAL(historyChanged(bool,bool,bool)),
+ this, SLOT(updateHistoryButtons(bool,bool,bool)));
+
searchWordLineEdit->setFocus();
+
+ setEnabled(true);
}
SearchBarWidget::~SearchBarWidget() {
Qt::AlignRight | Qt::AlignVCenter);
verticalLayout->addLayout(horizontalLayout);
-
}
if(!_isSearching && !word.isEmpty()) {
searchWordLineEdit->setText(word);
setBusy();
+ history->add(word);
emit searchForTranslations(word);
}
}
void SearchBarWidget::setEnabled(bool enabled) {
searchWordLineEdit->setEnabled(enabled);
- historyNextToolButton->setEnabled(enabled);
- historyPrevToolButton->setEnabled(enabled);
- historyShowToolButton->setEnabled(enabled);
+
+ if(enabled) {
+ historyNextToolButton->setEnabled(history->nextAvailable());
+ historyPrevToolButton->setEnabled(history->prevAvailable());
+ historyShowToolButton->setEnabled(history->listAvailable());
+ }
}
void SearchBarWidget::setBusy() {
}
void SearchBarWidget::historyNextToolButtonClicked() {
-
+ QString next = history->next();
+ if(!next.isEmpty()) {
+ searchWordLineEdit->setText(next);
+ }
}
void SearchBarWidget::historyPrevToolButtonClicked() {
-
+ QString prev = history->previous();
+ if(!prev.isEmpty()) {
+ searchWordLineEdit->setText(prev);
+ }
}
void SearchBarWidget::historyShowToolButtonClicked() {
-
+ HistoryListDialog listDialog(history, this);
+ listDialog.exec();
}
void SearchBarWidget::clearSearchWordToolButtonClicked() {
searchWordLineEdit->clear();
}
-void SearchBarWidget::showHistoryListDialog() {
-
-}
bool SearchBarWidget::isSearching() const {
return _isSearching;
}
+
+void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) {
+ if(!isSearching()) {
+ historyPrevToolButton->setEnabled(prev);
+ historyNextToolButton->setEnabled(next);
+ historyShowToolButton->setEnabled(list);
+ }
+}
#include <QWidget>
#include <QtGui>
#include "../backbone/backbone.h"
-
+#include "../../includes/History.h"
//! Displays search bar
/*!
void historyPrevToolButtonClicked();
void historyNextToolButtonClicked();
void historyShowToolButtonClicked();
+ void updateHistoryButtons(bool prev, bool next, bool list);
private:
Backbone* backbone;
+ History* history;
QLineEdit* searchWordLineEdit;
QToolButton* clearSearchWordToolButton;
QPushButton* searchPushButton;
bool _isSearching;
void initializeUI();
- void showHistoryListDialog();
};
#endif // SEARCHBARWIDGET_H
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary 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 mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef HISTORY_H
+#define HISTORY_H
+
+#include <QObject>
+#include <QVector>
+#include <QStringList>
+
+class History : public QObject
+{
+ Q_OBJECT
+public:
+ explicit History(int maxSize = 5, QObject *parent = 0);
+
+Q_SIGNALS:
+ void historyChanged(bool prevAvailable,
+ bool nextAvailable,
+ bool listAvailable);
+
+public:
+ void add(QString);
+ QString previous();
+ QString next();
+ QStringList list();
+
+ bool prevAvailable();
+ bool nextAvailable();
+ bool listAvailable();
+
+ void setCurrentElement(int element);
+
+ int maxSize();
+
+ void setMaxSize(int size);
+
+private:
+ QVector<QString> _history;
+ int _maxSize;
+ int currentElement;
+ bool _prevAvailable;
+ bool _nextAvailable;
+ bool _listAvailable;
+};
+
+#endif // HISTORY_H
SOURCES += tst_Backbone.cpp \
- ../../src/base/backbone/backbone.cpp
+ ../../src/base/backbone/backbone.cpp \
+ ../../src/base/backbone/History.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += \
../../src/includes/translation.h \
../../src/includes/settings.h \
../../src/includes/CommonDictInterface.h \
+ ../../src/includes/History.h \
TranslationMock.h
check.target = check
+++ /dev/null
-<!DOCTYPE QtCreatorProject>
-<qtcreator>
- <data>
- <variable>ProjectExplorer.Project.ActiveTarget</variable>
- <value type="int">0</value>
- </data>
- <data>
- <variable>ProjectExplorer.Project.EditorSettings</variable>
- <valuemap type="QVariantMap">
- <value key="EditorConfiguration.Codec" type="QByteArray">UTF-8</value>
- </valuemap>
- </data>
- <data>
- <variable>ProjectExplorer.Project.Target.0</variable>
- <valuemap type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Desktop</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Target.DesktopTarget</value>
- <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">0</value>
- <value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
- <valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
- <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
- <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
- </valuemap>
- <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
- <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
- <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
- <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
- </valuemap>
- <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
- <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
- <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
- <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
- <value type="QString">clean</value>
- </valuelist>
- <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
- </valuemap>
- <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
- <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
- <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt w PATH Debug</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mDictionaryTests-build</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">3</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
- </valuemap>
- <valuemap key="ProjectExplorer.Target.BuildConfiguration.1" type="QVariantMap">
- <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
- <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
- </valuemap>
- <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
- <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
- <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
- <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
- </valuemap>
- <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
- <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
- <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
- <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
- <value type="QString">clean</value>
- </valuelist>
- <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
- </valuemap>
- <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
- <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
- <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt w PATH Release</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">3</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
- </valuemap>
- <valuemap key="ProjectExplorer.Target.BuildConfiguration.2" type="QVariantMap">
- <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
- <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
- </valuemap>
- <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
- <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
- <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
- <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
- </valuemap>
- <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
- <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
- <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
- <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
- <value type="QString">clean</value>
- </valuelist>
- <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
- </valuemap>
- <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
- <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
- <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt 4.6.3 OpenSource Debug</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
- </valuemap>
- <valuemap key="ProjectExplorer.Target.BuildConfiguration.3" type="QVariantMap">
- <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
- <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
- </valuemap>
- <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
- <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
- <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
- <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
- </valuemap>
- <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
- <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
- <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
- <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
- <value type="QString">clean</value>
- </valuelist>
- <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
- </valuemap>
- <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
- <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
- <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt 4.6.3 OpenSource Release</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
- <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
- </valuemap>
- <value key="ProjectExplorer.Target.BuildConfigurationCount" type="int">4</value>
- <valuemap key="ProjectExplorer.Target.RunConfiguration.0" type="QVariantMap">
- <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">mDictionaryTests</value>
- <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4RunConfiguration</value>
- <value key="Qt4ProjectManager.Qt4RunConfiguration.BaseEnvironmentBase" type="int">2</value>
- <valuelist key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments" type="QVariantList"/>
- <value key="Qt4ProjectManager.Qt4RunConfiguration.ProFile" type="QString">mDictionaryTests.pro</value>
- <value key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix" type="bool">false</value>
- <value key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal" type="bool">false</value>
- <valuelist key="Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges" type="QVariantList"/>
- <value key="Qt4ProjectManager.Qt4RunConfiguration.UserSetName" type="bool">false</value>
- <value key="Qt4ProjectManager.Qt4RunConfiguration.UserSetWorkingDirectory" type="bool">false</value>
- <value key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory" type="QString"></value>
- </valuemap>
- <value key="ProjectExplorer.Target.RunConfigurationCount" type="int">1</value>
- </valuemap>
- </data>
- <data>
- <variable>ProjectExplorer.Project.TargetCount</variable>
- <value type="int">1</value>
- </data>
- <data>
- <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
- <value type="int">4</value>
- </data>
-</qtcreator>
#include <QtCore/QString>
#include <QtTest/QtTest>
+#include <QStringList>
#include <QList>
#include <QTime>
#include "../../src/base/backbone/backbone.h"
void stopSearchingTest();
void searchTest();
void translationTest();
- void multiTranslationTest();
+ void historyTest();
void quitTest();
};
}
qDebug() << "main " << this->thread()->currentThreadId();
- QStringList list;
- list << "pigwa";
+ QString list("pigwa");
back->search(list);
usleep(2000);
QTime time;
time.start();
- QStringList list;
- list << "nic";
+ QString list("nic");
back->search(list);
qDebug() << "Time for backbone.search: " << time.elapsed();
usleep(1000);
QVERIFY2(back->result().size() == total*2, "Lost some of the translations");
}
-void BackboneTest::multiTranslationTest() {
- QSignalSpy translatS(back, SIGNAL(ready()));
- QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
-
-
- QTime time;
- QStringList list;
-
- list << "a" << "b" << "c";
- back->search(list);
- qDebug() << "Time for backbone.search: " << time.elapsed();
- usleep(1000);
- time.start();
- back->translationReady();
- qDebug() << "Time for backbone->translation: " << time.elapsed();
-
- QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
- QVERIFY2(back->result().size() == total*2*3,
- "Lost some of the translations");
-}
-
-
-
void BackboneTest::quitTest() {
QSignalSpy translatS(back, SIGNAL(closeOk()));
for(int i = 0; i < total; i++) {
QVERIFY2(translatS.count() == 1, "Lost finall 'closeOk()' signal");
}
+void BackboneTest::historyTest() {
+ History* history = back->history();
+
+ history->add("mleko");
+
+ QCOMPARE(history->nextAvailable(), FALSE);
+ QCOMPARE(history->prevAvailable(), FALSE);
+ QCOMPARE(history->listAvailable(), TRUE);
+
+
+ history->add("szklanka");
+ QCOMPARE(history->nextAvailable(), FALSE);
+ QCOMPARE(history->prevAvailable(), TRUE);
+
+ history->previous();
+ QCOMPARE(history->nextAvailable(), TRUE);
+ QCOMPARE(history->prevAvailable(), FALSE);
+
+ history->add("pic");
+ QStringList words = history->list();
+ QCOMPARE(words[0], QString("pic"));
+ QCOMPARE(words[1], QString("mleko"));
+
+ history->add("qqq");
+
+ history->previous();
+ history->add("pic");
+
+ words = history->list();
+ QCOMPARE(words[0], QString("qqq"));
+ QCOMPARE(words[1], QString("pic"));
+ QCOMPARE(words[2], QString("mleko"));
+
+ history->setCurrentElement(0);
+ QCOMPARE(history->nextAvailable(), FALSE);
+ QCOMPARE(history->prevAvailable(), TRUE);
+ QCOMPARE(history->listAvailable(), TRUE);
+
+ history->setCurrentElement(1);
+ QCOMPARE(history->nextAvailable(), TRUE);
+ QCOMPARE(history->prevAvailable(), TRUE);
+ QCOMPARE(history->listAvailable(), TRUE);
+
+ history->setMaxSize(1);
+ words = history->list();
+ QCOMPARE(words[0], QString("pic"));
+
+ QCOMPARE(history->nextAvailable(), FALSE);
+ QCOMPARE(history->prevAvailable(), FALSE);
+ QCOMPARE(history->listAvailable(), TRUE);
+}
+
QTEST_APPLESS_MAIN(BackboneTest);