]> khamidou — GitHub mirrors - st.git/commitdiff
a couple renames bc I'm repurposing the whole thing
authorkhamidou <khamidou@gmail.com>
Thu, 28 Jul 2011 17:51:33 +0000 (19:51 +0200)
committerkhamidou <khamidou@gmail.com>
Thu, 28 Jul 2011 17:51:33 +0000 (19:51 +0200)
mainwindow.cpp
mainwindow.h
st.pro
summarylist.cpp [new file with mode: 0644]
summarylist.h [new file with mode: 0644]

index 355cd73fffd043eaeaccbc7d578bdb28de627609..99411c3e6c509318960a6e1cff149757561b2ec7 100644 (file)
@@ -3,13 +3,23 @@
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
 {
-    sessionView = new QListView();
+    summaryView = new QListView();
     taskView = new QListView();
+
+
+    /* FIXME: use setPlaceholderText when I'll have QT 4.7 */
+    QHBoxLayout *newListHBox = new QHBoxLayout();
+    newListField = new QLineEdit();
+    newListButton = new QPushButton("Create a new list");
+    newListHBox->addWidget(newListField);
+    newListHBox->addWidget(newListButton);
+
     QFrame *frame = new QFrame();
 
     QGridLayout *gridLayout = new QGridLayout();
-    gridLayout->addWidget(sessionView, 0, 0);
+    gridLayout->addWidget(summaryView, 0, 0);
     gridLayout->addWidget(taskView, 0, 1);
+    gridLayout->addLayout(newListHBox, 1, 0);
 
 
     QFile fd(tr("tests/first.xml"));    
@@ -19,17 +29,17 @@ MainWindow::MainWindow(QWidget *parent)
     QDir d(tr("./tests"));
 
     tasks = new TaskList(fd);
-    sList = new SessionList(d);
+    sList = new SummaryList(d);
 
-    sessionView->setModel((QAbstractItemModel *) sList);
+    summaryView->setModel((QAbstractItemModel *) sList);
     taskView->setModel((QAbstractItemModel *) tasks);
 
-    connect(sessionView, SIGNAL(clicked(QModelIndex)), this, SLOT(changeTaskList(QModelIndex)));
+    connect(summaryView, SIGNAL(clicked(QModelIndex)), this, SLOT(changeTaskList(QModelIndex)));
 
     frame->setLayout(gridLayout);
     setCentralWidget(frame);
-    setWindowTitle(tr("Session Tracker"));
-    resize(440, 350);
+    setWindowTitle(tr("A Faire"));
+    resize(640, 350);
 }
 
 MainWindow::~MainWindow()
@@ -39,7 +49,7 @@ MainWindow::~MainWindow()
 
 void MainWindow::changeTaskList(const QModelIndex &index)
 {
-    QString filename = ((SessionList*) sessionView->model())->fileNameAt(index);
+    QString filename = ((SummaryList*) summaryView->model())->fileNameAt(index);
 
     QFile fd(filename);
     if(!fd.open(QIODevice::ReadOnly))
index b08d5c23cd64a32cb72955cc72e1660bffeeeaec..5d2c7e2d8cdff26f2142f137743c234e5e9757fd 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <QtCore>
 #include <QtGui>
-#include "sessionlist.h"
+#include "summarylist.h"
 #include "tasklist.h"
 
 
@@ -19,9 +19,12 @@ public slots:
     void changeTaskList(const QModelIndex & index);
 
 private:
-    QListView *sessionView;
+    QListView *summaryView;
     QListView *taskView;
-    SessionList *sList;
+    QLineEdit *newListField;
+    QPushButton *newListButton;
+
+    SummaryList *sList;
     TaskList *tasks;
 };
 
diff --git a/st.pro b/st.pro
index 30e321129f07a5c5c4dd856447e685f659adef99..6dbab7b64046f48de8f185ef6b0c8b9f1cad1799 100644 (file)
--- a/st.pro
+++ b/st.pro
@@ -8,8 +8,8 @@ TEMPLATE = app
 SOURCES += main.cpp \
     mainwindow.cpp \
     tasklist.cpp \
-    sessionlist.cpp
+    summarylist.cpp
 HEADERS += mainwindow.h \
     tasklist.h \
-    sessionlist.h
+    summarylist.h
 OTHER_FILES += README.txt
diff --git a/summarylist.cpp b/summarylist.cpp
new file mode 100644 (file)
index 0000000..e3a2686
--- /dev/null
@@ -0,0 +1,46 @@
+#include "summarylist.h"
+
+SummaryList::SummaryList(QDir& d)
+{
+    _directory = d;
+    _directory.setFilter(QDir::Files | QDir::NoSymLinks);
+}
+
+SummaryList::~SummaryList()
+{
+
+}
+
+QVariant SummaryList::data ( const QModelIndex & index, int role) const
+{
+    if (role == Qt::DisplayRole) {
+       /* Open the file and get its session name */
+       QString filePath = _directory.absoluteFilePath(_directory.entryList().at(index.row()));
+       QFile f(filePath);
+
+       if (!f.open(QIODevice::ReadOnly)) {
+         // fail silently
+         return QVariant();
+       }
+
+       /* otherwise, open the file and get the session name */
+       TaskList t(f);
+
+       if(t.sessionName() != "")
+           return t.sessionName();
+       else
+           return _directory.entryList().at(index.row());
+    }
+
+    return QVariant();
+}
+
+int SummaryList::rowCount (const QModelIndex & parent) const
+{
+    return _directory.entryList().size();
+}
+
+QString SummaryList::fileNameAt(const QModelIndex &index)
+{
+    return _directory.absoluteFilePath(_directory.entryList().at(index.row()));
+}
diff --git a/summarylist.h b/summarylist.h
new file mode 100644 (file)
index 0000000..593818f
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef SummaryList_H
+#define SummaryList_H
+
+#include <QtCore>
+#include "tasklist.h"
+
+class SummaryList : QAbstractListModel
+{
+    /**        This class represents the list of training sessions the user has created.
+ */
+
+    QDir    _directory;
+    
+public:
+    SummaryList(QDir& d);
+    ~SummaryList();
+
+    QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
+    int rowCount (const QModelIndex & parent = QModelIndex() ) const;
+    QString fileNameAt(const QModelIndex &index);
+};
+
+#endif // SummaryList_H