/
NoteView.cpp
67 lines (58 loc) · 1.42 KB
/
NoteView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "NoteView.h"
#include "ModifyDialog.h"
#include "AddDialog.h"
NoteView::NoteView( QWidget *parent,
NoteController* controller, NoteModel* model )
: QWidget(parent), Observer( model )
{
ui.setupUi(this);
_controller = controller;
}
NoteView::~NoteView()
{
}
void NoteView::update()
{
showNotes();
}
void NoteView::showNotes()
{
ui.noteList->clear();
unsigned int i = 0;
while( _controller->getNoteName( i ) != "" )
{
QString string(_controller->getNoteName(i).c_str());
ui.noteList->addItem( string );
i++;
}
}
void NoteView::addClicked()
{
AddDialog dialog;
if( dialog.exec() )
{
Note note( dialog.getNoteNameEdit().toStdString(), dialog.getNoteTextEdit().toStdString() );
_controller->addNote( note );
}
}
void NoteView::deleteClicked()
{
if( ui.noteList->isItemSelected( ui.noteList->currentItem() ))
_controller->removeNote( ui.noteList->currentItem()->text().toStdString() );
}
void NoteView::modifyClicked()
{
ModifyDialog dialog;
QString name = ui.noteList->currentItem()->text();
string text = _controller->getNoteText( name.toStdString() );
if( name != "" )
dialog.setNoteName( name );
if( text != "" ) {
QString string(text.c_str());
dialog.setNoteText( string );
}
if( dialog.exec() )
{
_controller->modifyNote( name.toStdString(), dialog.getNoteName().toStdString(), dialog.getNoteText().toStdString() );
}
}