From 3f1d27e95fbe037540eb6e52d3695b4b8c77735d Mon Sep 17 00:00:00 2001 From: khamidou Date: Thu, 28 Jul 2011 13:50:50 +0200 Subject: [PATCH] implemented the main data structures --- mainwindow.cpp | 40 ++++++++++++++++++++++++++++++++++++---- mainwindow.h | 6 ++++++ st.pro | 6 ++++-- tasklist.cpp | 4 ++-- tasklist.h | 6 +++++- tests/first.xml | 2 +- tests/second.xml | 37 +++++++++++++++++++++++++++++++++++++ 7 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 tests/second.xml diff --git a/mainwindow.cpp b/mainwindow.cpp index 76f146e..355cd73 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,19 +3,51 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { + sessionView = new QListView(); + taskView = new QListView(); + QFrame *frame = new QFrame(); - sessionView = new QListView(this); - QFile fd(tr("tests/first.xml")); + QGridLayout *gridLayout = new QGridLayout(); + gridLayout->addWidget(sessionView, 0, 0); + gridLayout->addWidget(taskView, 0, 1); + + + QFile fd(tr("tests/first.xml")); if(!fd.open(QIODevice::ReadOnly)) return; + QDir d(tr("./tests")); + tasks = new TaskList(fd); - sessionView->setModel((QAbstractItemModel *) tasks); - setCentralWidget(sessionView); + sList = new SessionList(d); + + sessionView->setModel((QAbstractItemModel *) sList); + taskView->setModel((QAbstractItemModel *) tasks); + connect(sessionView, SIGNAL(clicked(QModelIndex)), this, SLOT(changeTaskList(QModelIndex))); + + frame->setLayout(gridLayout); + setCentralWidget(frame); + setWindowTitle(tr("Session Tracker")); + resize(440, 350); } MainWindow::~MainWindow() { } + +void MainWindow::changeTaskList(const QModelIndex &index) +{ + QString filename = ((SessionList*) sessionView->model())->fileNameAt(index); + + QFile fd(filename); + if(!fd.open(QIODevice::ReadOnly)) + return; + + TaskList *oldModel = (TaskList *) taskView->model(); + TaskList *newModel = new TaskList(fd); + taskView->setModel((QAbstractItemModel *) newModel); + delete oldModel; + +} diff --git a/mainwindow.h b/mainwindow.h index da45e3e..b08d5c2 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,6 +3,7 @@ #include #include +#include "sessionlist.h" #include "tasklist.h" @@ -14,8 +15,13 @@ public: MainWindow(QWidget *parent = 0); ~MainWindow(); +public slots: + void changeTaskList(const QModelIndex & index); + private: QListView *sessionView; + QListView *taskView; + SessionList *sList; TaskList *tasks; }; diff --git a/st.pro b/st.pro index 0ef79c2..30e3211 100644 --- a/st.pro +++ b/st.pro @@ -7,7 +7,9 @@ TARGET = st TEMPLATE = app SOURCES += main.cpp \ mainwindow.cpp \ - tasklist.cpp + tasklist.cpp \ + sessionlist.cpp HEADERS += mainwindow.h \ - tasklist.h + tasklist.h \ + sessionlist.h OTHER_FILES += README.txt diff --git a/tasklist.cpp b/tasklist.cpp index 74c3b89..2253f31 100644 --- a/tasklist.cpp +++ b/tasklist.cpp @@ -26,7 +26,6 @@ Task::Task(QDomElement &root) minute = minutes.text().toInt(); _timeRemaining = QTime(hour, minute, 0); - qDebug() << minute << " " << hour; } TaskList::TaskList(QFile &f) @@ -46,8 +45,10 @@ TaskList::TaskList(QFile &f) return; } + _sessionName = doc.firstChildElement().attribute("name"); QDomElement child = doc.firstChildElement("session").firstChildElement(); + if (child.isNull()) { QMessageBox::critical(0, "Critical error !", "The Document doesn't have a root tag"); return; @@ -55,7 +56,6 @@ TaskList::TaskList(QFile &f) do { Task *t = new Task(child); - qDebug() << child.tagName(); _taskList.append(t); child = child.nextSiblingElement(); } while(!child.isNull()); diff --git a/tasklist.h b/tasklist.h index e9e64b9..b6a1588 100644 --- a/tasklist.h +++ b/tasklist.h @@ -26,7 +26,7 @@ class TaskList : QAbstractListModel { /** TaskList is our model class. It loads and saves tasks from an xml file. Format of the xml file : - + Task 1 @@ -44,6 +44,8 @@ class TaskList : QAbstractListModel */ QList _taskList; +QString _sessionName; + public: TaskList(QFile& f); ~TaskList(); @@ -51,6 +53,8 @@ public: QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const; int rowCount (const QModelIndex & parent = QModelIndex() ) const; + /* accessors */ + QString sessionName() { return _sessionName; }; }; #endif // TASKLIST_H diff --git a/tests/first.xml b/tests/first.xml index c8901d0..acd170d 100644 --- a/tests/first.xml +++ b/tests/first.xml @@ -1,5 +1,5 @@ - + Scale exercises diff --git a/tests/second.xml b/tests/second.xml new file mode 100644 index 0000000..a2b033f --- /dev/null +++ b/tests/second.xml @@ -0,0 +1,37 @@ + + + + Melodic exercises + + 3 + 5 + + + 3 + 5 + + + + Rhythm practice + + 3 + 5 + + + 3 + 5 + + + + Song practice + + 3 + 5 + + + 3 + 5 + + + + -- 2.43.0