Skip to content

Commit 749fc45

Browse files
committed
Implemented undo functionality for Movie Watchlist
1 parent e047814 commit 749fc45

9 files changed

+73
-136
lines changed

MovieTableModel.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//
44

55
#include "MovieTableModel.h"
6+
#include <string>
7+
68
using namespace std;
79

810
QVariant MovieTableModel::data(const QModelIndex &index, int role) const
@@ -26,7 +28,7 @@ QVariant MovieTableModel::data(const QModelIndex &index, int role) const
2628
case 1:
2729
return QString::fromStdString(currentMovie.getGenre());
2830
case 2:
29-
return QString::fromStdString(to_string(currentMovie.getLikes()));
31+
return QString::fromStdString(currentMovie.getTrailer());
3032
}
3133
}
3234

MovieTableModel.cpp.autosave

-114
This file was deleted.

moc_usermode.cpp

+20-15
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ QT_BEGIN_MOC_NAMESPACE
2121
QT_WARNING_PUSH
2222
QT_WARNING_DISABLE_DEPRECATED
2323
struct qt_meta_stringdata_userMode_t {
24-
QByteArrayData data[8];
25-
char stringdata0[152];
24+
QByteArrayData data[9];
25+
char stringdata0[174];
2626
};
2727
#define QT_MOC_LITERAL(idx, ofs, len) \
2828
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@@ -38,13 +38,15 @@ QT_MOC_LITERAL(3, 38, 24), // "on_trailerButton_clicked"
3838
QT_MOC_LITERAL(4, 63, 20), // "on_addButton_clicked"
3939
QT_MOC_LITERAL(5, 84, 21), // "on_nextButton_clicked"
4040
QT_MOC_LITERAL(6, 106, 21), // "on_openButton_clicked"
41-
QT_MOC_LITERAL(7, 128, 23) // "on_deleteButton_clicked"
41+
QT_MOC_LITERAL(7, 128, 23), // "on_deleteButton_clicked"
42+
QT_MOC_LITERAL(8, 152, 21) // "on_undoButton_clicked"
4243

4344
},
4445
"userMode\0on_suggestionButton_clicked\0"
4546
"\0on_trailerButton_clicked\0"
4647
"on_addButton_clicked\0on_nextButton_clicked\0"
47-
"on_openButton_clicked\0on_deleteButton_clicked"
48+
"on_openButton_clicked\0on_deleteButton_clicked\0"
49+
"on_undoButton_clicked"
4850
};
4951
#undef QT_MOC_LITERAL
5052

@@ -54,27 +56,29 @@ static const uint qt_meta_data_userMode[] = {
5456
7, // revision
5557
0, // classname
5658
0, 0, // classinfo
57-
6, 14, // methods
59+
7, 14, // methods
5860
0, 0, // properties
5961
0, 0, // enums/sets
6062
0, 0, // constructors
6163
0, // flags
6264
0, // signalCount
6365

6466
// slots: name, argc, parameters, tag, flags
65-
1, 0, 44, 2, 0x08 /* Private */,
66-
3, 0, 45, 2, 0x08 /* Private */,
67-
4, 0, 46, 2, 0x08 /* Private */,
68-
5, 0, 47, 2, 0x08 /* Private */,
69-
6, 0, 48, 2, 0x08 /* Private */,
70-
7, 0, 49, 2, 0x08 /* Private */,
67+
1, 0, 49, 2, 0x08 /* Private */,
68+
3, 0, 50, 2, 0x08 /* Private */,
69+
4, 0, 51, 2, 0x08 /* Private */,
70+
5, 0, 52, 2, 0x08 /* Private */,
71+
6, 0, 53, 2, 0x08 /* Private */,
72+
7, 0, 54, 2, 0x08 /* Private */,
73+
8, 0, 55, 2, 0x08 /* Private */,
7174

7275
// slots: parameters
7376
QMetaType::Void,
7477
QMetaType::Void,
7578
QMetaType::Void,
7679
QMetaType::Void,
7780
QMetaType::Void,
81+
QMetaType::Void,
7882
QMetaType::Void,
7983

8084
0 // eod
@@ -92,6 +96,7 @@ void userMode::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, vo
9296
case 3: _t->on_nextButton_clicked(); break;
9397
case 4: _t->on_openButton_clicked(); break;
9498
case 5: _t->on_deleteButton_clicked(); break;
99+
case 6: _t->on_undoButton_clicked(); break;
95100
default: ;
96101
}
97102
}
@@ -123,13 +128,13 @@ int userMode::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
123128
if (_id < 0)
124129
return _id;
125130
if (_c == QMetaObject::InvokeMetaMethod) {
126-
if (_id < 6)
131+
if (_id < 7)
127132
qt_static_metacall(this, _c, _id, _a);
128-
_id -= 6;
133+
_id -= 7;
129134
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
130-
if (_id < 6)
135+
if (_id < 7)
131136
*reinterpret_cast<int*>(_a[0]) = -1;
132-
_id -= 6;
137+
_id -= 7;
133138
}
134139
return _id;
135140
}

repository/watchlist.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using namespace std;
77
WatchList::WatchList(string type)
88
{
99
this->movieList = vector<Movie>();
10+
this->backupList = vector<vector<Movie> >();
1011
this->currentPos = 0;
1112
this->maximumPos = 0;
1213
this->suggestions = vector<Movie>();
@@ -15,6 +16,7 @@ WatchList::WatchList(string type)
1516

1617
void WatchList::add()
1718
{
19+
backupList.push_back(getArray());
1820
this->movieList.push_back(this->suggestions[this->currentPos]);
1921
this->suggestions.erase(this->suggestions.begin() + this->currentPos);
2022
this->currentPos--;
@@ -35,6 +37,7 @@ int WatchList::getPosition(string name)
3537

3638
int WatchList::del(string title)
3739
{
40+
backupList.push_back(getArray());
3841
int pos = getPosition(title);
3942

4043
if (pos == -1)

repository/watchlist.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class WatchList
1212
protected:
1313
vector<Movie> movieList;
1414
vector<Movie> suggestions;
15+
vector<vector<Movie> > backupList;
1516
int currentPos, maximumPos;
1617
string type;
1718

@@ -47,6 +48,8 @@ class WatchList
4748
virtual void openInApp() = 0;
4849

4950
string getType() const { return this->type; }
51+
52+
void undo() { this->movieList = backupList[backupList.size() - 1]; backupList.pop_back(); };
5053
};
5154

5255
class CSVWatchList : public WatchList
@@ -60,4 +63,4 @@ class HTMLWatchList : public WatchList
6063
void saveToFile();
6164
void openInApp();
6265
};
63-
#endif //LMDB_WATCHLIST_H
66+
#endif //LMDB_WATCHLIST_H

ui_usermode.h

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Ui_userMode
3939
QListWidget *items;
4040
QPushButton *openButton;
4141
QTableView *tableView;
42+
QPushButton *undoButton;
4243

4344
void setupUi(QDialog *userMode)
4445
{
@@ -82,6 +83,9 @@ class Ui_userMode
8283
tableView = new QTableView(userMode);
8384
tableView->setObjectName(QStringLiteral("tableView"));
8485
tableView->setGeometry(QRect(70, 210, 256, 192));
86+
undoButton = new QPushButton(userMode);
87+
undoButton->setObjectName(QStringLiteral("undoButton"));
88+
undoButton->setGeometry(QRect(10, 390, 61, 32));
8589

8690
retranslateUi(userMode);
8791

@@ -98,6 +102,7 @@ class Ui_userMode
98102
addButton->setText(QApplication::translate("userMode", "Add Movie", Q_NULLPTR));
99103
nextButton->setText(QApplication::translate("userMode", "Next Movie", Q_NULLPTR));
100104
openButton->setText(QApplication::translate("userMode", "Open in App", Q_NULLPTR));
105+
undoButton->setText(QApplication::translate("userMode", "Undo", Q_NULLPTR));
101106
} // retranslateUi
102107

103108
};

usermode.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include "ui_usermode.h"
33
#include "MovieTableModel.h"
44

5+
void userMode::updateTable()
6+
{ MovieTableModel *mymodel = new MovieTableModel(wlist); ui->tableView->setModel(mymodel); }
7+
58
userMode::userMode(Controller ctrl, WatchList *wlist, QWidget *parent) :
69
QDialog(parent),
710
ui(new Ui::userMode)
@@ -98,3 +101,15 @@ void userMode::on_deleteButton_clicked()
98101

99102
this->updateTable();
100103
}
104+
105+
void userMode::on_undoButton_clicked()
106+
{
107+
this->wlist->undo();
108+
109+
ui->items->clear();
110+
111+
for (Movie mov: wlist->getArray())
112+
ui->items->addItem(QString::fromStdString(mov.toStr()));
113+
114+
this->updateTable();
115+
}

usermode.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QDialog>
55
#include "repository/watchlist.h"
66
#include "controller/controller.h"
7+
#include "MovieTableModel.h"
78

89
namespace Ui {
910
class userMode;
@@ -13,9 +14,14 @@ class userMode : public QDialog
1314
{
1415
Q_OBJECT
1516

17+
private:
18+
Ui::userMode *ui;
19+
Controller ctrl;
20+
WatchList *wlist;
21+
1622
public:
1723
explicit userMode(Controller ctrl, WatchList *wlist, QWidget *parent = 0);
18-
void updateTable() { MovieTableModel *mymodel = new MovieTableModel(wlist); ui->tableView->setModel(mymodel); }
24+
void updateTable();
1925
~userMode();
2026

2127
private slots:
@@ -31,10 +37,9 @@ private slots:
3137

3238
void on_deleteButton_clicked();
3339

34-
private:
35-
Ui::userMode *ui;
36-
Controller ctrl;
37-
WatchList *wlist;
40+
void on_undoButton_clicked();
41+
42+
3843
};
3944

4045
#endif // USERMODE_H

usermode.ui

+13
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@
157157
</rect>
158158
</property>
159159
</widget>
160+
<widget class="QPushButton" name="undoButton">
161+
<property name="geometry">
162+
<rect>
163+
<x>10</x>
164+
<y>390</y>
165+
<width>61</width>
166+
<height>32</height>
167+
</rect>
168+
</property>
169+
<property name="text">
170+
<string>Undo</string>
171+
</property>
172+
</widget>
160173
</widget>
161174
<resources/>
162175
<connections/>

0 commit comments

Comments
 (0)