From: khamidou Date: Thu, 14 Jul 2011 09:33:46 +0000 (+0200) Subject: initial commit X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=8be6d7c685a71b80ca872a6d986051ac786edd53;p=tt.git initial commit --- 8be6d7c685a71b80ca872a6d986051ac786edd53 diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..59874e8 --- /dev/null +++ b/README.txt @@ -0,0 +1 @@ +This is the README for Task Tracker (tt). diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..6e7efd9 --- /dev/null +++ b/main.cpp @@ -0,0 +1,10 @@ +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..6470dfa --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,36 @@ +#include "mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent) +{ + //tab = new TabView(this); + tabWidget = new QTabWidget(this); + setWindowTitle(tr("Task Tracker")); + setMinimumSize(640, 480); + + table = new TaskModel(); + tableView = new QTableView(); + QPushButton *button = new QPushButton("yop"); + + tabWidget->addTab(tableView, tr("Tasks")); + tabWidget->addTab(button, tr("Stats")); + + + tableView->setModel(table); + tableView->setItemDelegate(new TableDelegate()); + + tableView->resizeColumnsToContents(); + tableView->adjustSize(); + tableView->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); + tableView->horizontalHeader()->setStretchLastSection(true); + + //tableView->setIndexWidget(); + setCentralWidget(tabWidget); + + +} + +MainWindow::~MainWindow() +{ + +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..ede8501 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,30 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include "taskmodel.h" +#include "tabledelegate.h" + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow { + Q_OBJECT +public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; + QTabWidget *tabWidget; + TaskModel *table; + QTableView *tableView; +}; + +#endif // MAINWINDOW_H diff --git a/tabledelegate.cpp b/tabledelegate.cpp new file mode 100644 index 0000000..739b57d --- /dev/null +++ b/tabledelegate.cpp @@ -0,0 +1,48 @@ +#include "tabledelegate.h" +#include + +TableDelegate::TableDelegate(QWidget *parent) : + QStyledItemDelegate(parent) +{ + map = new QSignalMapper(this); +} + +QWidget *TableDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem &option, + const QModelIndex &index) const + +{ + std::cout << index.column(); + if (index.column() == 2) { + QComboBox *lWidget = new QComboBox(parent); + lWidget->addItem("lololol"); + lWidget->addItem("jkj"); + lWidget->addItem("lodslolol"); + lWidget->addItem("dflol"); + + + connect(lWidget, SIGNAL(editingFinished()), + this, SLOT(commitAndCloseEditor())); + + return lWidget; + } else { + return QStyledItemDelegate::createEditor(parent, option, index); + } +} + +/* FIXME: rendre propre +void TableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + +} +*/ + +QSize TableDelegate::sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const { } + +void TableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {} +void TableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const { } + +void TableDelegate::commitAndCloseEditor() { } diff --git a/tabledelegate.h b/tabledelegate.h new file mode 100644 index 0000000..3d5760b --- /dev/null +++ b/tabledelegate.h @@ -0,0 +1,34 @@ +#ifndef TABLEDELEGATE_H +#define TABLEDELEGATE_H + +#include +#include +#include +#include + + +class TableDelegate : public QStyledItemDelegate +{ + Q_OBJECT + + public: + TableDelegate(QWidget *parent = 0); + + /* void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const; */ + QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const; + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + + private slots: + void commitAndCloseEditor(); + + private: + QSignalMapper *map; /* On en a besoin pour les boutons et les combobox */ + }; + +#endif // TABLEDELEGATE_H diff --git a/taskmodel.cpp b/taskmodel.cpp new file mode 100644 index 0000000..86a63c1 --- /dev/null +++ b/taskmodel.cpp @@ -0,0 +1,54 @@ +#include "taskmodel.h" + +TaskModel::TaskModel(QObject *parent) : QAbstractTableModel(parent) +{ + +} + +QVariant TaskModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() >= 4 || index.row() < 0) + return QVariant(); + + if (role == Qt::DisplayRole) { + if (index.column() == 0) + return tr("gerard"); + else if (index.column() == 1) + return tr("ho"); + else if (index.column() == 2) + return tr("paf"); + else if (index.column() == 3) + return tr("paf"); + } + return QVariant(); +} + +QVariant TaskModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Horizontal) { + switch (section) { + case 0: + return tr("Task"); + + case 1: + return tr("Total time spent on this task"); + + case 2: + return tr("Start counting"); + + case 3: + return tr("Category"); + + + default: + return QVariant(); + } + } + return QVariant(); +} diff --git a/taskmodel.h b/taskmodel.h new file mode 100644 index 0000000..a307ab6 --- /dev/null +++ b/taskmodel.h @@ -0,0 +1,31 @@ +#ifndef TASKMODEL_H +#define TASKMODEL_H + +#include + +class TaskModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + TaskModel(QObject *parent=0); + + int rowCount(const QModelIndex &parent) const { return 2; }; + int columnCount(const QModelIndex &parent) const { return 4; }; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const { + if (!index.isValid()) + return Qt::ItemIsEnabled; + + return QAbstractTableModel::flags(index) | Qt::ItemIsEditable; }; + + bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) { return false; }; + bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex()) { return false; }; + bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex()) {return false; }; + +private: + QList< QPair > listOfPairs; +}; + +#endif // TASKMODEL_H diff --git a/tt.pro b/tt.pro new file mode 100644 index 0000000..fcd5b5b --- /dev/null +++ b/tt.pro @@ -0,0 +1,16 @@ +# ------------------------------------------------- +# Project created by QtCreator 2011-06-25T14:16:34 +# ------------------------------------------------- +QT += network \ + xml +TARGET = tt +TEMPLATE = app +SOURCES += main.cpp \ + mainwindow.cpp \ + taskmodel.cpp \ + tabledelegate.cpp +HEADERS += mainwindow.h \ + taskmodel.h \ + tabledelegate.h +FORMS += +OTHER_FILES += README.txt