]> khamidou — GitHub mirrors - st.git/commitdiff
making the big switch to webkit master
authorkhamidou <khamidou@gmail.com>
Fri, 29 Jul 2011 11:57:47 +0000 (13:57 +0200)
committerkhamidou <khamidou@gmail.com>
Fri, 29 Jul 2011 11:57:47 +0000 (13:57 +0200)
main.cpp
mainwindow.cpp
mainwindow.h
st.pro
summarylist.cpp
summarylist.h
tasklist.cpp
tasklist.h
tests/first.xml
tests/second.xml

index 6e7efd975207b7f21796a1a9ed8eece2592f4c6c..ffc55cb3b95c2aeb0e1fd4ee745c24de2b5299b2 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+    qRegisterMetaType<Task>("Task");
     QApplication a(argc, argv);
     MainWindow w;
     w.show();
index 99411c3e6c509318960a6e1cff149757561b2ec7..2d222e2fd6c156c0af3b2448c371f7ea29d0b645 100644 (file)
@@ -35,6 +35,7 @@ MainWindow::MainWindow(QWidget *parent)
     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);
@@ -61,3 +62,13 @@ void MainWindow::changeTaskList(const QModelIndex &index)
     delete oldModel;
 
 }
+
+void MainWindow::createNewList()
+{
+    QString title = newListField->text();
+    if (title == "")
+       return;
+
+    SummaryList * model = (SummaryList *) summaryView->model();
+    model->createNewList(title);
+}
index 5d2c7e2d8cdff26f2142f137743c234e5e9757fd..7875977b6d6989a5781ed7107bbd08e119453e64 100644 (file)
@@ -17,6 +17,7 @@ public:
 
 public slots:
     void changeTaskList(const QModelIndex & index);
+    void createNewList(void);
 
 private:
     QListView *summaryView;
diff --git a/st.pro b/st.pro
index 6dbab7b64046f48de8f185ef6b0c8b9f1cad1799..f3bc10aba5f5f35f8cf6f27ed9618611b5358ba4 100644 (file)
--- a/st.pro
+++ b/st.pro
@@ -8,8 +8,10 @@ TEMPLATE = app
 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
index e3a2686128f2c224d4fcb91ed2d3dd7e6211cb63..d2d615f9fa70d72e3675e4debc27027237e34345 100644 (file)
@@ -26,8 +26,8 @@ QVariant SummaryList::data ( const QModelIndex & index, int role) const
        /* 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());
     }
@@ -44,3 +44,10 @@ QString SummaryList::fileNameAt(const QModelIndex &index)
 {
     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;
+}
index 593818f1283a65dabe8970df053b00d542bed28e..9f38c5f2e89b02e88544092e0edf75ad516ff24a 100644 (file)
@@ -18,6 +18,7 @@ public:
     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
index 2253f319885c589efeaa49dfe3674fab2abd051e..04145cf331f2b536250b3eab9f0176a1942cc6ed 100644 (file)
@@ -9,25 +9,44 @@ Task::Task(QDomElement &root)
 
     _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;
@@ -45,20 +64,19 @@ TaskList::TaskList(QFile &f)
        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");
+    }
 
 }
 
@@ -88,3 +106,8 @@ int TaskList::rowCount (const QModelIndex & parent) const
 {
     return _taskList.length();
 }
+
+int TaskList::columnCount( const QModelIndex & parent = QModelIndex() ) const
+{
+    return 1;
+}
index b6a15883b812a6459838c4d5db6375b341d8e125..6366b8789a5d74fec8c618373c66df70ae4176b3 100644 (file)
@@ -6,27 +6,30 @@
 #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>
@@ -40,21 +43,22 @@ class TaskList : QAbstractListModel
                    </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
index acd170d5438dd7dbfa7c207d1585075190e8cd5e..db0509a07e97f9ea2142b0ce6e4a168aac028234 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<session name="Work #1">
+<todolist name="Work #1">
     <task>
        <title>Scale exercises</title>
        <length>
@@ -34,4 +34,4 @@
        </elapsed>
      </task>
 
-</session>
+</todolist>
index a2b033f96204ae4c97a05dadd0b44969f9c83d23..30a5ef86da12df0e7df99e6dbc60faffac8a2d60 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<session name="Work #2">
+<todolist name="Work #2">
     <task>
        <title>Melodic exercises</title>
        <length>
@@ -34,4 +34,4 @@
        </elapsed>
      </task>
 
-</session>
+</todolist>