From: khamidou Date: Thu, 28 Jul 2011 17:51:33 +0000 (+0200) Subject: a couple renames bc I'm repurposing the whole thing X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=155a5e25680ee25d6da65a425a7d79a82cf2f107;p=st.git a couple renames bc I'm repurposing the whole thing --- diff --git a/mainwindow.cpp b/mainwindow.cpp index 355cd73..99411c3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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)) diff --git a/mainwindow.h b/mainwindow.h index b08d5c2..5d2c7e2 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,7 +3,7 @@ #include #include -#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 30e3211..6dbab7b 100644 --- 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 index 0000000..e3a2686 --- /dev/null +++ b/summarylist.cpp @@ -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 index 0000000..593818f --- /dev/null +++ b/summarylist.h @@ -0,0 +1,23 @@ +#ifndef SummaryList_H +#define SummaryList_H + +#include +#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