Browse Source

Catching and displaying exceptions.

master
Maximilian Stiefel 6 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"?>
<!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>
<data>
<variable>EnvironmentId</variable>

11
qml/pages/FirstPage.qml

@ -10,7 +10,7 @@ Page {
contentHeight: parent.height
SilicaListView {
anchors.fill: parent
spacing: Theme.paddingLarge
spacing: Theme.paddingMedium
model: DictModel {
id: dict_model
}
@ -53,14 +53,15 @@ Page {
delegate: Column {
width: page.width
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
font.family: Theme.fontFamilyHeading
font.pixelSize: Theme.fontSizeLarge
wrapMode: Text.WordWrap
maximumLineCount: 10
//maximumLineCount: 3
anchors {
horizontalCenter: parent.horizontalCenter
left: parent.left
right: parent.right
leftMargin: Theme.paddingMedium
rightMargin: Theme.paddingMedium
}

10
src/dict_model.cpp

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

Loading…
Cancel
Save