From 85b88eb24d58fd9720e7c2fac4206cb8bf9ea736 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Fri, 20 Apr 2018 12:09:15 +0200 Subject: [PATCH] . --- ccharacter.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ ccharacter.h | 2 ++ cmainwindow.cpp | 8 ++++-- cmainwindow.h | 1 + cmainwindow.ui | 46 ++++++++++++++++++++++++++-------- cstorybook.cpp | 46 ++++++++++++++++++++++++++++++++++ cstorybook.h | 4 +++ 7 files changed, 160 insertions(+), 12 deletions(-) diff --git a/ccharacter.cpp b/ccharacter.cpp index 6f0883e..8011b7e 100644 --- a/ccharacter.cpp +++ b/ccharacter.cpp @@ -1,5 +1,10 @@ #include "ccharacter.h" +#include "common.h" + +#include +#include + cCharacter::cCharacter(qint32 iID, QObject *parent) : QObject(parent), @@ -122,6 +127,29 @@ QString cCharacter::nickName() return(m_szNickName); } +QString cCharacter::name() +{ + QString szName(""); + + if(!m_szFirstName.isEmpty()) + szName.append(m_szFirstName); + + if(!m_szMiddleName.isEmpty()) + { + if(!szName.isEmpty()) + szName.append(" "); + szName.append(m_szMiddleName); + } + + if(!m_szLastName.isEmpty()) + { + if(!szName.isEmpty()) + szName.append(" "); + szName.append(m_szLastName); + } + return(szName); +} + void cCharacter::setHeight(qreal dHeight) { m_dHeight = dHeight; @@ -318,6 +346,43 @@ cCharacter* cCharacterList::find(const qint32& iID) bool cCharacterList::load() { + QSqlQuery query; + + query.prepare("SELECT id, mainCharacter, gender, title, firstName, middleName, lastName, height, weight, dateOfBirth, placeOfBirth, dateOfDeath, placeOfDeath, hairColor, hairCut, hairLength, figure, nature, spokenLanguages, skin, school, job, description FROM character ORDER BY mainCharacter DESC, lastName, middleName, firstName;"); + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + while(query.next()) + { + cCharacter* lpCharacter = add(query.value("id").toInt()); + + lpCharacter->setMainCharacter(query.value("mainCharacter").toBool()); + lpCharacter->setGender((cCharacter::GENDER)query.value("gender").toInt()); + lpCharacter->setTitle(query.value("title").toString()); + lpCharacter->setFirstName(query.value("firstName").toString()); + lpCharacter->setMiddleName(query.value("middleName").toString()); + lpCharacter->setLastName(query.value("lastName").toString()); + lpCharacter->setHeight(query.value("height").toDouble()); + lpCharacter->setWeight(query.value("weight").toDouble()); + lpCharacter->setDateOfBirth(query.value("dateOfBirth").toDate()); + lpCharacter->setPlaceOfBirth(query.value("placeOfBirth").toString()); + lpCharacter->setDateOfDeath(query.value("dateOfDeath").toDate()); + lpCharacter->setPlaceOfDeath(query.value("placeOfBirth").toString()); + lpCharacter->setHairColor(query.value("hairColor").toString()); + lpCharacter->setHairCut(query.value("hairCut").toString()); + lpCharacter->setHairLength(query.value("hairLength").toString()); + lpCharacter->setFigure(query.value("figure").toString()); + lpCharacter->setNature(query.value("nature").toString()); + lpCharacter->setSpokenLanguages(query.value("spokenLanguages").toString()); + lpCharacter->setSkin(query.value("skin").toString()); + lpCharacter->setSchool(query.value("school").toString()); + lpCharacter->setJob(query.value("job").toString()); + lpCharacter->setDescription(query.value("description").toString()); + } + return(true); } diff --git a/ccharacter.h b/ccharacter.h index 0c3ee09..bfbf783 100644 --- a/ccharacter.h +++ b/ccharacter.h @@ -47,6 +47,8 @@ public: void setLastName(const QString& szLastName); QString lastName(); + QString name(); + void setNickName(const QString& szNickName); QString nickName(); diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 9478c3d..72dc014 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -30,7 +30,8 @@ cMainWindow::cMainWindow(QWidget *parent) : QString szPath = QDir::homePath() + QDir::separator() + "OneDrive - WINDESIGN" + QDir::separator() + "__BOOKS__" + QDir::separator() + "qtStoryWriter" + QDir::separator() + "DerAdler"; m_lpStoryBook = new cStoryBook(szPath); - m_lpStoryBook->fillOutlineList(ui->m_lpOutline); + m_lpStoryBook->fillOutlineList(ui->m_lpOutlineList); + m_lpStoryBook->fillCharacterList(ui->m_lpCharacterList); updateWindowTitle(); @@ -78,7 +79,10 @@ void cMainWindow::initUI() ui->setupUi(this); m_lpOutlineModel = new QStandardItemModel(0, 1); - ui->m_lpOutline->setModel(m_lpOutlineModel); + ui->m_lpOutlineList->setModel(m_lpOutlineModel); + + m_lpCharacterModel = new QStandardItemModel(0, 1); + ui->m_lpCharacterList->setModel(m_lpCharacterModel); QSettings settings; qint16 iX = settings.value("main/x", QVariant::fromValue(-1)).toInt(); diff --git a/cmainwindow.h b/cmainwindow.h index c48883c..737c81e 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -34,6 +34,7 @@ private slots: private: Ui::cMainWindow* ui; QStandardItemModel* m_lpOutlineModel; + QStandardItemModel* m_lpCharacterModel; bool m_bUpdatingTab; cStoryBook* m_lpStoryBook; diff --git a/cmainwindow.ui b/cmainwindow.ui index d068b0c..c031aad 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -28,15 +28,15 @@ QFrame::Sunken - 0 + 4 0 0 - 147 - 477 + 89 + 433 @@ -44,7 +44,7 @@ - + QAbstractItemView::NoEditTriggers @@ -69,21 +69,42 @@ 0 0 - 147 - 477 + 89 + 433 Character + + + + + QAbstractItemView::NoEditTriggers + + + true + + + true + + + false + + + true + + + + 0 0 - 147 - 477 + 79 + 450 @@ -95,8 +116,8 @@ 0 0 - 147 - 477 + 79 + 450 @@ -104,6 +125,11 @@ + + + Recherche + + diff --git a/cstorybook.cpp b/cstorybook.cpp index 4939f41..9bc4e6d 100644 --- a/cstorybook.cpp +++ b/cstorybook.cpp @@ -38,6 +38,9 @@ cStoryBook::cStoryBook(const QString &szProjectPath, QObject *parent) : if(!loadSceneList()) return; + if(!loadCharacterList()) + return; + m_bIsOpen = true; } @@ -335,6 +338,11 @@ bool cStoryBook::loadSceneList() return(m_sceneList.load(&m_chapterList)); } +bool cStoryBook::loadCharacterList() +{ + return(m_characterList.load()); +} + QString cStoryBook::title() { if(!m_bIsOpen) @@ -438,3 +446,41 @@ bool cStoryBook::fillOutlineList(QTreeView* lpView) return(true); } + +bool cStoryBook::fillCharacterList(QTreeView* lpView) +{ + QStandardItemModel* lpModel = (QStandardItemModel*)lpView->model(); + QStandardItem* lpRootItem = lpModel->invisibleRootItem(); + QFont fontMainCharacter = lpRootItem->font(); + QFont fontNonMainCharacter = lpRootItem->font(); + + lpModel->clear(); + + QStringList headerLabels = QStringList() << tr("name"); + lpModel->setHorizontalHeaderLabels(headerLabels); + + fontMainCharacter.setBold(true); + fontNonMainCharacter.setItalic(true); + + for(int x = 0;x < m_characterList.count();x++) + { + cCharacter* lpCharacter = m_characterList.at(x); + QStandardItem* lpItem = new QStandardItem(lpCharacter->name()); + lpItem->setData(QVariant::fromValue(lpCharacter)); + + if(lpCharacter->mainCharacter()) + lpItem->setFont(fontMainCharacter); + else + lpItem->setFont(fontNonMainCharacter); + +// lpItem->setToolTip(lpPart->description()); + lpModel->appendRow(lpItem); + } + + lpView->header()->setStretchLastSection(true); + + lpView->expandAll(); + lpView->resizeColumnToContents(0); + + return(true); +} diff --git a/cstorybook.h b/cstorybook.h index 636b681..2b8b69a 100644 --- a/cstorybook.h +++ b/cstorybook.h @@ -6,6 +6,7 @@ #include "cpart.h" #include "cchapter.h" #include "cscene.h" +#include "ccharacter.h" #include #include @@ -30,6 +31,7 @@ public: QString author(); bool fillOutlineList(QTreeView* lpView); + bool fillCharacterList(QTreeView* lpView); private: QString m_szProjectPath; bool m_bIsOpen; @@ -38,6 +40,7 @@ private: cPartList m_partList; cChapterList m_chapterList; cSceneList m_sceneList; + cCharacterList m_characterList; bool createDatabase(); bool updateDatabase(); @@ -47,6 +50,7 @@ private: bool loadPartList(); bool loadChapterList(); bool loadSceneList(); + bool loadCharacterList(); }; #endif // CSTORYBOOK_H