int main(int argc, char *argv[])
{
+ qRegisterMetaType<Task>("Task");
QApplication a(argc, argv);
MainWindow w;
w.show();
taskView->setModel((QAbstractItemModel *) tasks);
connect(summaryView, SIGNAL(clicked(QModelIndex)), this, SLOT(changeTaskList(QModelIndex)));
+ connect(newListButton, SIGNAL(clicked()), this, SLOT(createNewList()));
frame->setLayout(gridLayout);
setCentralWidget(frame);
delete oldModel;
}
+
+void MainWindow::createNewList()
+{
+ QString title = newListField->text();
+ if (title == "")
+ return;
+
+ SummaryList * model = (SummaryList *) summaryView->model();
+ model->createNewList(title);
+}
public slots:
void changeTaskList(const QModelIndex & index);
+ void createNewList(void);
private:
QListView *summaryView;
SOURCES += main.cpp \
mainwindow.cpp \
tasklist.cpp \
- summarylist.cpp
+ summarylist.cpp \
+ taskdelegate.cpp
HEADERS += mainwindow.h \
tasklist.h \
- summarylist.h
+ summarylist.h \
+ taskdelegate.h
OTHER_FILES += README.txt
/* otherwise, open the file and get the session name */
TaskList t(f);
- if(t.sessionName() != "")
- return t.sessionName();
+ if(t.todoListName() != "")
+ return t.todoListName();
else
return _directory.entryList().at(index.row());
}
{
return _directory.absoluteFilePath(_directory.entryList().at(index.row()));
}
+
+bool SummaryList::createNewList(QString listName)
+{
+ TaskList l(listName);
+ emit QAbstractItemModel::dataChanged(index(0), index(rowCount()));
+ return true;
+}
QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
int rowCount (const QModelIndex & parent = QModelIndex() ) const;
QString fileNameAt(const QModelIndex &index);
+ bool createNewList(QString listName);
};
#endif // SummaryList_H
_title = titleElement.text();
- QDomElement length = titleElement.nextSiblingElement();
+ QDomElement length = titleElement.nextSiblingElement("length");
QDomElement hours = length.firstChildElement("hours");
int hour = hours.text().toInt();
- QDomElement minutes = hours.nextSiblingElement();
+ QDomElement minutes = hours.nextSiblingElement("minutes");
int minute = minutes.text().toInt();
_taskLength = QTime(hour, minute, 0);
- QDomElement remaining = length.nextSiblingElement();
+ QDomElement remaining = length.nextSiblingElement("remaining");
hours = remaining.firstChildElement("hours");
hour = hours.text().toInt();
- minutes = hours.nextSiblingElement();
+ minutes = hours.nextSiblingElement("minutes");
minute = minutes.text().toInt();
_timeRemaining = QTime(hour, minute, 0);
}
+TaskList::TaskList(QString listName)
+{
+ QDomDocument doc;
+ QDomElement root = doc.createElement("todolist");
+ doc.appendChild(root);
+ root.setAttribute("name", listName);
+
+ QFile file("./tests/" + listName + ".xml");
+ if(!file.open(QIODevice::WriteOnly | QFile::Truncate)) {
+ QMessageBox::critical(0, tr("Unable to create Todo List"),
+ tr("An error happened while creating the list file : ") + file.errorString());
+ return;
+ }
+
+ QTextStream stream(&file);
+ doc.save(stream, 4);
+ stream.flush();
+}
+
TaskList::TaskList(QFile &f)
{
QDomDocument doc;
return;
}
- _sessionName = doc.firstChildElement().attribute("name");
- QDomElement child = doc.firstChildElement("session").firstChildElement();
-
+ _todoListName = doc.firstChildElement("todolist").attribute("name");
+ QDomElement child = doc.firstChildElement("todolist").firstChildElement("task");
- if (child.isNull()) {
+ if (doc.firstChildElement("todolist").isNull()) {
QMessageBox::critical(0, "Critical error !", "The Document doesn't have a root tag");
return;
}
- do {
+ while(!child.isNull()) {
Task *t = new Task(child);
_taskList.append(t);
- child = child.nextSiblingElement();
- } while(!child.isNull());
+ child = child.nextSiblingElement("task");
+ }
}
{
return _taskList.length();
}
+
+int TaskList::columnCount( const QModelIndex & parent = QModelIndex() ) const
+{
+ return 1;
+}
#include <QtXml>
#include <QAbstractListModel>
-class Task : public QObject
+class Task //: public QObject
{
/** this class models a task, which is a portion of a session */
- Q_OBJECT
+// Q_OBJECT
QString _title;
QTime _taskLength;
QTime _timeRemaining;
public:
+ Task() : _title("Unnamed task"), _taskLength(), _timeRemaining() { };
Task(QString title, QTime taskLength) : _title(title), _taskLength(taskLength), _timeRemaining() { };
Task(QDomElement& root);
QString title(void) { return _title; };
QTime taskLength(void) { return _taskLength; }
};
+Q_DECLARE_METATYPE(Task)
-class TaskList : QAbstractListModel
+class TaskList : QAbstractItemModel
{
+
/** TaskList is our model class. It loads and saves tasks from an xml file.
Format of the xml file :
- <session name="Work #1">
+ <todolist name="Work #1">
<task>
<title>Task 1</title>
<length>
</task>
<task>
...
- </session>
+ </todolist>
*/
QList <Task *> _taskList;
-QString _sessionName;
+QString _todoListName;
public:
TaskList(QFile& f);
+ TaskList(QString listName);
~TaskList();
QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
int rowCount (const QModelIndex & parent = QModelIndex() ) const;
-
+ int columnCount( const QModelIndex & parent = QModelIndex() ) const;
+ QModelIndex parent ( const QModelIndex & index ) const { return QModelIndex(); };
/* accessors */
- QString sessionName() { return _sessionName; };
+ QString todoListName() { return _todoListName; };
};
-
#endif // TASKLIST_H
<?xml version="1.0" encoding="utf-8"?>
-<session name="Work #1">
+<todolist name="Work #1">
<task>
<title>Scale exercises</title>
<length>
</elapsed>
</task>
-</session>
+</todolist>
<?xml version="1.0" encoding="utf-8"?>
-<session name="Work #2">
+<todolist name="Work #2">
<task>
<title>Melodic exercises</title>
<length>
</elapsed>
</task>
-</session>
+</todolist>