From: Akos Polster Date: Mon, 19 Jul 2010 12:37:21 +0000 (+0200) Subject: Pass model test. X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=aaf934b35d8ebc8044c501c4106579a2982730b9;p=dorian Pass model test. --- diff --git a/book.cpp b/book.cpp index 2aff091..bd96c45 100644 --- a/book.cpp +++ b/book.cpp @@ -304,3 +304,12 @@ QString Book::rootPath() const { return mRootPath; } + +QString Book::name() const +{ + if (title != "") { + return title; + } else { + return path(); + } +} diff --git a/book.h b/book.h index cdfd60f..974b7c7 100644 --- a/book.h +++ b/book.h @@ -80,6 +80,12 @@ public: /** List bookmarks. */ QList bookmarks() const; + /** + * Get friendly name. + * @return @see title or path name if title is not available yet. + */ + QString name() const; + QString title; //< Book title from EPUB. QStringList toc; //< Table of contents from EPUB. QHash content; //< Content items from EPUB. diff --git a/dorian.pro b/dorian.pro index 4db48ad..276d007 100644 --- a/dorian.pro +++ b/dorian.pro @@ -64,11 +64,13 @@ OTHER_FILES += \ styles/day.js DEFINES += \ - USE_FILE32API + USE_FILE32API \ + DORIAN_TEST_MODEL + +include(modeltest/modeltest.pri) unix { LIBS += -lz - include(modeltest/modeltest.pri) } windows { # FIXME: Build zlib, too diff --git a/library.cpp b/library.cpp index 96a2344..ca21725 100644 --- a/library.cpp +++ b/library.cpp @@ -27,15 +27,24 @@ Library *Library::instance() int Library::rowCount(const QModelIndex &parent) const { - Q_UNUSED(parent); - return mBooks.size(); + if (parent.isValid()) { + return 0; + } else { + return mBooks.size(); + } } QVariant Library::data(const QModelIndex &index, int role) const { + qDebug() << "Library::data, row" << index.row() << "role" << role; + + if (!index.isValid()) { + return QVariant(); + } + switch (role) { case Qt::DisplayRole: - return mBooks[index.row()]->title; + return mBooks[index.row()]->name(); case BookRole: return QVariant::fromValue(*mBooks[index.row()]); default: @@ -96,7 +105,7 @@ bool Library::add(QString path) } int size = mBooks.size(); Book *book = new Book(path); - beginInsertRows(QModelIndex(), size - 1, size); + beginInsertRows(QModelIndex(), size, size); mBooks.append(book); save(); endInsertRows(); @@ -105,11 +114,14 @@ bool Library::add(QString path) void Library::remove(const QModelIndex &index) { + if (!index.isValid()) { + return; + } int row = index.row(); if ((row < 0) || (row >= mBooks.size())) { return; } - beginRemoveRows(QModelIndex(), row, row + 1); + beginRemoveRows(QModelIndex(), row, row); Book *book = mBooks[row]; mBooks.removeAt(row); save(); diff --git a/librarydialog.cpp b/librarydialog.cpp index 9d2cc03..dfae909 100644 --- a/librarydialog.cpp +++ b/librarydialog.cpp @@ -138,7 +138,7 @@ void LibraryDialog::onRemove() if (current.isValid()) { Book currentBook = Library::instance()->data(current, Library::BookRole).value(); - QString title = currentBook.title; + QString title = currentBook.name(); if (QMessageBox::Yes == QMessageBox::question(this, "Delete book", "Delete book \"" + title + "\"?", diff --git a/mainwindow.cpp b/mainwindow.cpp index e1fbf6b..5c5aeaf 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -19,6 +19,10 @@ #include "bookmarksdialog.h" #include "settings.h" +#ifdef DORIAN_TEST_MODEL +#include "modeltest.h" +#endif + #ifdef Q_WS_MAC # define ICON_PREFIX ":/icons/mac/" #else @@ -113,6 +117,10 @@ MainWindow::MainWindow(QWidget *parent): // Handle loading chapters connect(view, SIGNAL(chapterLoaded(int)), this, SLOT(onChapterLoaded(int))); + +#ifdef DORIAN_TEST_MODEL + (void)new ModelTest(Library::instance(), this); +#endif } void MainWindow::onCurrentBookChanged() diff --git a/modeltest/modeltest.pro b/modeltest/modeltest.pro deleted file mode 100644 index 6f991dd..0000000 --- a/modeltest/modeltest.pro +++ /dev/null @@ -1,4 +0,0 @@ -include(modeltest.pri) - -OTHER_FILES += \ - README