Browse Source

Catching and displaying exceptions.

master
Maximilian Stiefel 7 years ago
parent
commit
75f2df5dfa
  1. 2
      harbour-wordbook.pro.user
  2. 11
      qml/pages/FirstPage.qml
  3. 10
      src/dict_model.cpp
  4. 1
      src/dict_model.h

2
harbour-wordbook.pro.user

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.4.1, 2018-04-20T18:10:16. --> <!-- Written by QtCreator 4.4.1, 2018-04-20T18:55:17. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

11
qml/pages/FirstPage.qml

@ -10,7 +10,7 @@ Page {
contentHeight: parent.height contentHeight: parent.height
SilicaListView { SilicaListView {
anchors.fill: parent anchors.fill: parent
spacing: Theme.paddingLarge spacing: Theme.paddingMedium
model: DictModel { model: DictModel {
id: dict_model id: dict_model
} }
@ -53,14 +53,15 @@ Page {
delegate: Column { delegate: Column {
width: page.width width: page.width
Label { Label {
text: "This is a test with a longer text.jjjjj jjj jjjjjj jjj jjjjjjjj jjjj jjjjjjjjjj jjjjjj" id: body
text: msg2usr
color: Theme.primaryColor color: Theme.primaryColor
font.family: Theme.fontFamilyHeading
font.pixelSize: Theme.fontSizeLarge font.pixelSize: Theme.fontSizeLarge
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
maximumLineCount: 10 //maximumLineCount: 3
anchors { anchors {
horizontalCenter: parent.horizontalCenter left: parent.left
right: parent.right
leftMargin: Theme.paddingMedium leftMargin: Theme.paddingMedium
rightMargin: Theme.paddingMedium rightMargin: Theme.paddingMedium
} }

10
src/dict_model.cpp

@ -34,8 +34,9 @@ DictModel::DictModel(QObject *parent) :
QAbstractListModel(parent) QAbstractListModel(parent)
{ {
d_msg = ""; d_msg = "";
// Create dictionary // Create dictionary.
d_wordbook = dictcc::creator::create("DESV"); d_wordbook = dictcc::creator::create("DESV");
// Initialise with shared pointer to empty lists, so it actually holds data.
d_result = d_wordbook->get_translations(); d_result = d_wordbook->get_translations();
} }
@ -96,9 +97,16 @@ void DictModel::search(QString word)
// Perform search // Perform search
try { try {
d_result = d_wordbook->search(word.toStdString()); d_result = d_wordbook->search(word.toStdString());
d_msg = nullptr;
} catch (const dictcc::dict_exception& e) { } catch (const dictcc::dict_exception& e) {
d_result = d_wordbook->reset_search(); d_result = d_wordbook->reset_search();
d_msg = e.what(); d_msg = e.what();
} }
endResetModel(); endResetModel();
} }
void DictModel::change_language(QString lang)
{
d_wordbook.reset();
d_wordbook = dictcc::creator::create(lang.toStdString());
}

1
src/dict_model.h

@ -53,6 +53,7 @@ public:
//Q_INVOKABLE void activate(const int i); //Q_INVOKABLE void activate(const int i);
Q_INVOKABLE void search(QString word); Q_INVOKABLE void search(QString word);
Q_INVOKABLE void change_language(QString lang);
private: private:
std::shared_ptr<dictcc::dict> d_wordbook = nullptr; std::shared_ptr<dictcc::dict> d_wordbook = nullptr;

Loading…
Cancel
Save