From 0f915c02d69f29cd671cc0abab4bbbe363b80d28 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Tue, 29 May 2018 15:00:11 +0200 Subject: [PATCH] added functionality to add characters, objects and places to recherche and scene --- cmainwindow.cpp | 4 +- cobjectselectdialog.cpp | 89 ++++++++ cobjectselectdialog.h | 70 +++++++ cobjectselectdialog.ui | 67 ++++++ common.cpp | 1 + cplaceselectdialog.cpp | 90 ++++++++ cplaceselectdialog.h | 70 +++++++ cplaceselectdialog.ui | 67 ++++++ crecherche.cpp | 71 ++++--- crecherche.h | 65 ++++-- crecherchewindow.cpp | 445 +++++++++++++++++++++++++++------------- crecherchewindow.h | 134 +++++++++--- crecherchewindow.ui | 148 ++++++++++--- cscene.cpp | 56 +++-- cscene.h | 17 +- cscenewindow.cpp | 276 +++++++++++++++---------- cscenewindow.h | 23 +++ storyWriter.pro | 12 +- 18 files changed, 1319 insertions(+), 386 deletions(-) create mode 100644 cobjectselectdialog.cpp create mode 100644 cobjectselectdialog.h create mode 100644 cobjectselectdialog.ui create mode 100644 cplaceselectdialog.cpp create mode 100644 cplaceselectdialog.h create mode 100644 cplaceselectdialog.ui diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 084e4f2..0ecfe8e 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -1066,8 +1066,8 @@ void cMainWindow::onShowRechercheWindow(cRecherche* lpRecherche) } } - cRechercheWindow* lpRechercheWindow = new cRechercheWindow(this); - lpRechercheWindow->setRecherche(lpRecherche); + cRechercheWindow* lpRechercheWindow = new cRechercheWindow(this); + lpRechercheWindow->setRecherche(lpRecherche, m_lpStoryBook->characterList(), m_lpStoryBook->placeList(), m_lpStoryBook->objectList()); cWidget* lpWidget1 = new cWidget(lpRechercheWindow); lpWidget1->setWindow(ui->m_lpMdiArea->addSubWindow(lpRechercheWindow)); ui->m_lpMainTab->addTab((QWidget*)lpWidget1, lpRechercheWindow->windowTitle()); diff --git a/cobjectselectdialog.cpp b/cobjectselectdialog.cpp new file mode 100644 index 0000000..683a85d --- /dev/null +++ b/cobjectselectdialog.cpp @@ -0,0 +1,89 @@ +#include "cobjectselectdialog.h" +#include "ui_cobjectselectdialog.h" + + +cObjectSelectDialog::cObjectSelectDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::cObjectSelectDialog) +{ + ui->setupUi(this); + + m_lpObjectListModel = new QStandardItemModel(0, 1); + ui->m_lpObjectList->setModel(m_lpObjectListModel); + + connect(ui->m_lpObjectList, &QTreeView::doubleClicked, this, &cObjectSelectDialog::onObjectDoubleClicked); +} + +cObjectSelectDialog::~cObjectSelectDialog() +{ + delete ui; +} + +void cObjectSelectDialog::setObjectList(cObjectList* lpObjectList, QList objectDescriptionList) +{ + QStandardItemModel* lpModel = m_lpObjectListModel; + + lpModel->clear(); + + QStringList headerLabels = QStringList() << tr("name") << tr("type"); + m_lpObjectListModel->setHorizontalHeaderLabels(headerLabels); + + for(int x = 0;x < lpObjectList->count();x++) + { + bool bFound = false; + cObject* lpObject = lpObjectList->at(x); + + for(int y = 0;y < objectDescriptionList.count();y++) + { + if(lpObject == objectDescriptionList.at(y)->object()) + { + bFound = true; + break; + } + } + + if(bFound) + continue; + + QList lpItems; + + lpItems.append(new QStandardItem(lpObject->name())); + lpItems.append(new QStandardItem(lpObject->type())); + + for(int i = 0;i < headerLabels.count();i++) + { + lpItems[i]->setData(QVariant::fromValue(lpObject)); + + if(lpObject->description()) + lpItems[i]->setToolTip(lpObject->description()->toPlainText()); + } + + m_lpObjectListModel->appendRow(lpItems); + } + + ui->m_lpObjectList->header()->setStretchLastSection(true); + + ui->m_lpObjectList->expandAll(); + + for(int i = 0;i < headerLabels.count();i++) + ui->m_lpObjectList->resizeColumnToContents(i); + + ui->m_lpObjectList->setCurrentIndex(m_lpObjectListModel->index(0, 0)); +} + +void cObjectSelectDialog::onObjectDoubleClicked(const QModelIndex& /*index*/) +{ + this->accept(); +} + +cObject* cObjectSelectDialog::selected() +{ + if(!ui->m_lpObjectList->currentIndex().isValid()) + return(0); + + QStandardItem* lpItem = m_lpObjectListModel->itemFromIndex(ui->m_lpObjectList->currentIndex()); + if(!lpItem) + return(0); + + return(qvariant_cast(lpItem->data())); +} diff --git a/cobjectselectdialog.h b/cobjectselectdialog.h new file mode 100644 index 0000000..8b69532 --- /dev/null +++ b/cobjectselectdialog.h @@ -0,0 +1,70 @@ +#ifndef COBJECTSELECTDIALOG_H +#define COBJECTSELECTDIALOG_H + + +#include "cobject.h" + +#include +#include +#include + + +namespace Ui { +class cObjectSelectDialog; +} + +/*! + \brief + + \class cObjectSelectDialog cobjectselectdialog.h "cobjectselectdialog.h" +*/ +class cObjectSelectDialog : public QDialog +{ + Q_OBJECT + +public: + /*! + \brief + + \fn cObjectSelectDialog + \param parent + */ + explicit cObjectSelectDialog(QWidget *parent = 0); + /*! + \brief + + \fn ~cObjectSelectDialog + */ + ~cObjectSelectDialog(); + + /*! + \brief + + \fn setObjectList + \param lpObjectList + \param objectDescriptionList + */ + void setObjectList(cObjectList* lpObjectList, QList objectDescriptionList); + /*! + \brief + + \fn selected + \return cObject + */ + cObject* selected(); + +private: + Ui::cObjectSelectDialog* ui; /*!< TODO: describe */ + QStandardItemModel* m_lpObjectListModel; /*!< TODO: describe */ + +private slots: + /*! + \brief + + \fn onObjectDoubleClicked + \param index + */ + void onObjectDoubleClicked(const QModelIndex& index); +}; + +#endif // COBJECTSELECTDIALOG_H diff --git a/cobjectselectdialog.ui b/cobjectselectdialog.ui new file mode 100644 index 0000000..1cf0f9a --- /dev/null +++ b/cobjectselectdialog.ui @@ -0,0 +1,67 @@ + + + cObjectSelectDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + cObjectSelectDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + cObjectSelectDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/common.cpp b/common.cpp index d490ff4..bd2320d 100644 --- a/common.cpp +++ b/common.cpp @@ -40,5 +40,6 @@ QByteArray textDocument2Blob(cTextDocument* lpTextDocument) return(ba); ba = compressText(lpTextDocument->toHtml()); + return(ba); } diff --git a/cplaceselectdialog.cpp b/cplaceselectdialog.cpp new file mode 100644 index 0000000..f24e373 --- /dev/null +++ b/cplaceselectdialog.cpp @@ -0,0 +1,90 @@ +#include "cplaceselectdialog.h" +#include "ui_cplaceselectdialog.h" + + +cPlaceSelectDialog::cPlaceSelectDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::cPlaceSelectDialog) +{ + ui->setupUi(this); + + m_lpPlaceListModel = new QStandardItemModel(0, 1); + ui->m_lpPlaceList->setModel(m_lpPlaceListModel); + + connect(ui->m_lpPlaceList, &QTreeView::doubleClicked, this, &cPlaceSelectDialog::onPlaceDoubleClicked); +} + +cPlaceSelectDialog::~cPlaceSelectDialog() +{ + delete ui; +} + +void cPlaceSelectDialog::setPlaceList(cPlaceList* lpPlaceList, QList placeDescriptionList) +{ + QStandardItemModel* lpModel = m_lpPlaceListModel; + + lpModel->clear(); + + QStringList headerLabels = QStringList() << tr("name") << tr("location") << tr("type"); + m_lpPlaceListModel->setHorizontalHeaderLabels(headerLabels); + + for(int x = 0;x < lpPlaceList->count();x++) + { + bool bFound = false; + cPlace* lpPlace = lpPlaceList->at(x); + + for(int y = 0;y < placeDescriptionList.count();y++) + { + if(lpPlace == placeDescriptionList.at(y)->place()) + { + bFound = true; + break; + } + } + + if(bFound) + continue; + + QList lpItems; + + lpItems.append(new QStandardItem(lpPlace->name())); + lpItems.append(new QStandardItem(lpPlace->location())); + lpItems.append(new QStandardItem(lpPlace->type())); + + for(int i = 0;i < headerLabels.count();i++) + { + lpItems[i]->setData(QVariant::fromValue(lpPlace)); + + if(lpPlace->description()) + lpItems[i]->setToolTip(lpPlace->description()->toPlainText()); + } + + m_lpPlaceListModel->appendRow(lpItems); + } + + ui->m_lpPlaceList->header()->setStretchLastSection(true); + + ui->m_lpPlaceList->expandAll(); + + for(int i = 0;i < headerLabels.count();i++) + ui->m_lpPlaceList->resizeColumnToContents(i); + + ui->m_lpPlaceList->setCurrentIndex(m_lpPlaceListModel->index(0, 0)); +} + +void cPlaceSelectDialog::onPlaceDoubleClicked(const QModelIndex& /*index*/) +{ + this->accept(); +} + +cPlace* cPlaceSelectDialog::selected() +{ + if(!ui->m_lpPlaceList->currentIndex().isValid()) + return(0); + + QStandardItem* lpItem = m_lpPlaceListModel->itemFromIndex(ui->m_lpPlaceList->currentIndex()); + if(!lpItem) + return(0); + + return(qvariant_cast(lpItem->data())); +} diff --git a/cplaceselectdialog.h b/cplaceselectdialog.h new file mode 100644 index 0000000..6ba1215 --- /dev/null +++ b/cplaceselectdialog.h @@ -0,0 +1,70 @@ +#ifndef CPLACESELECTDIALOG_H +#define CPLACESELECTDIALOG_H + + +#include "cplace.h" + +#include +#include +#include + + +namespace Ui { +class cPlaceSelectDialog; +} + +/*! + \brief + + \class cPlaceSelectDialog cplaceselectdialog.h "cplaceselectdialog.h" +*/ +class cPlaceSelectDialog : public QDialog +{ + Q_OBJECT + +public: + /*! + \brief + + \fn cPlaceSelectDialog + \param parent + */ + explicit cPlaceSelectDialog(QWidget *parent = 0); + /*! + \brief + + \fn ~cPlaceSelectDialog + */ + ~cPlaceSelectDialog(); + + /*! + \brief + + \fn setPlaceList + \param lpPlaceList + \param placeDescriptionList + */ + void setPlaceList(cPlaceList* lpPlaceList, QList placeDescriptionList); + /*! + \brief + + \fn selected + \return cPlace + */ + cPlace* selected(); + +private: + Ui::cPlaceSelectDialog* ui; /*!< TODO: describe */ + QStandardItemModel* m_lpPlaceListModel; /*!< TODO: describe */ + +private slots: + /*! + \brief + + \fn onPlaceDoubleClicked + \param index + */ + void onPlaceDoubleClicked(const QModelIndex& index); +}; + +#endif // CPLACESELECTDIALOG_H diff --git a/cplaceselectdialog.ui b/cplaceselectdialog.ui new file mode 100644 index 0000000..ad7a547 --- /dev/null +++ b/cplaceselectdialog.ui @@ -0,0 +1,67 @@ + + + cPlaceSelectDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + cPlaceSelectDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + cPlaceSelectDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/crecherche.cpp b/crecherche.cpp index 6a4ba41..88fe63d 100644 --- a/crecherche.cpp +++ b/crecherche.cpp @@ -91,16 +91,31 @@ void cRecherche::addCharacter(cCharacter* lpCharacter, cTextDocument* lpDescript m_characterList.append(new cCharacterDescription(lpCharacter, lpDescription)); } +void cRecherche::removeCharacter(cCharacterDescription* lpCharacter) +{ + m_characterList.removeOne(lpCharacter); +} + void cRecherche::addObject(cObject* lpObject, cTextDocument* lpDescription) { m_objectList.append(new cObjectDescription(lpObject, lpDescription)); } +void cRecherche::removeObject(cObjectDescription* lpObject) +{ + m_objectList.removeOne(lpObject); +} + void cRecherche::addPlace(cPlace* lpPlace, cTextDocument* lpDescription) { m_placeList.append(new cPlaceDescription(lpPlace, lpDescription)); } +void cRecherche::removePlace(cPlaceDescription* lpPlace) +{ + m_placeList.removeOne(lpPlace); +} + QList cRecherche::images() { return(m_imageList); @@ -340,6 +355,34 @@ bool cRechercheList::save() { cRecherche* lpRecherche = at(x); + imageDelete.bindValue(":rechercheID", lpRecherche->id()); + if(!imageDelete.exec()) + { + myDebug << imageDelete.lastError().text(); + return(false); + } + + characterDelete.bindValue(":rechercheID", lpRecherche->id()); + if(!characterDelete.exec()) + { + myDebug << characterDelete.lastError().text(); + return(false); + } + + objectDelete.bindValue(":rechercheID", lpRecherche->id()); + if(!objectDelete.exec()) + { + myDebug << objectDelete.lastError().text(); + return(false); + } + + placeDelete.bindValue(":rechercheID", lpRecherche->id()); + if(!placeDelete.exec()) + { + myDebug << placeDelete.lastError().text(); + return(false); + } + if(lpRecherche->deleted()) { queryDelete.bindValue(":id", lpRecherche->id()); @@ -385,34 +428,6 @@ bool cRechercheList::save() lpRecherche->setID(querySelect.value("id").toInt()); } - imageDelete.bindValue(":rechercheID", lpRecherche->id()); - if(!imageDelete.exec()) - { - myDebug << imageDelete.lastError().text(); - return(false); - } - - characterDelete.bindValue(":rechercheID", lpRecherche->id()); - if(!imageDelete.exec()) - { - myDebug << characterDelete.lastError().text(); - return(false); - } - - objectDelete.bindValue(":rechercheID", lpRecherche->id()); - if(!imageDelete.exec()) - { - myDebug << objectDelete.lastError().text(); - return(false); - } - - placeDelete.bindValue(":rechercheID", lpRecherche->id()); - if(!imageDelete.exec()) - { - myDebug << placeDelete.lastError().text(); - return(false); - } - QList images = lpRecherche->images(); for(int x = 0;x < images.count();x++) diff --git a/crecherche.h b/crecherche.h index 483a2c4..b45b835 100644 --- a/crecherche.h +++ b/crecherche.h @@ -115,6 +115,21 @@ public: \param lpDescription */ void addCharacter(cCharacter* lpCharacter, cTextDocument* lpDescription); + /*! + \brief + + \fn removeCharacter + \param lpCharacter + */ + void removeCharacter(cCharacterDescription* lpCharacter); + /*! + \brief + + \fn characterList + \return QList + */ + QList characterList(); + /*! \brief @@ -123,6 +138,21 @@ public: \param lpDescription */ void addObject(cObject* lpObject, cTextDocument* lpDescription); + /*! + \brief + + \fn removeObject + \param lpObject + */ + void removeObject(cObjectDescription* lpObject); + /*! + \brief + + \fn objectList + \return QList + */ + QList objectList(); + /*! \brief @@ -131,6 +161,20 @@ public: \param lpDescription */ void addPlace(cPlace* lpPlace, cTextDocument* lpDescription); + /*! + \brief + + \fn removePlace + \param lpPlace + */ + void removePlace(cPlaceDescription* lpPlace); + /*! + \brief + + \fn placeList + \return QList + */ + QList placeList(); /*! \brief @@ -139,27 +183,6 @@ public: \return QList */ QList images(); - /*! - \brief - - \fn characterList - \return QList - */ - QList characterList(); - /*! - \brief - - \fn objectList - \return QList - */ - QList objectList(); - /*! - \brief - - \fn placeList - \return QList - */ - QList placeList(); /*! \brief diff --git a/crecherchewindow.cpp b/crecherchewindow.cpp index 3073ee5..4d52d22 100644 --- a/crecherchewindow.cpp +++ b/crecherchewindow.cpp @@ -10,52 +10,55 @@ #include "cmainwindow.h" +#include "ccharacterselectdialog.h" +#include "cplaceselectdialog.h" +#include "cobjectselectdialog.h" + #include "common.h" #include - +#include cRechercheWindow::cRechercheWindow(QWidget *parent) : cMDISubWindow(parent), ui(new Ui::cRechercheWindow), m_lpMainWindow((cMainWindow*)parent), - m_lpRecherche(0) + m_lpRecherche(0), + m_lpCharacterList(0), + m_lpPlaceList(0), + m_lpObjectList(0) { ui->setupUi(this); ui->m_lpTab->setCurrentIndex(0); - m_lpCharacterModel = new QStandardItemModel(0, 1); - ui->m_lpCharacterList->setModel(m_lpCharacterModel); + connect(ui->m_lpName, &cLineEdit::gotFocus, (cMainWindow*)parent, &cMainWindow::onLineEditGotFocus); + connect(ui->m_lpName, &cLineEdit::lostFocus, (cMainWindow*)parent, &cMainWindow::onLineEditLostFocus); - m_lpPlaceModel = new QStandardItemModel(0, 1); - ui->m_lpPlaceList->setModel(m_lpPlaceModel); + connect(ui->m_lpLink, &cLineEdit::gotFocus, (cMainWindow*)parent, &cMainWindow::onLineEditGotFocus); + connect(ui->m_lpLink, &cLineEdit::lostFocus, (cMainWindow*)parent, &cMainWindow::onLineEditLostFocus); - m_lpObjectModel = new QStandardItemModel(0, 1); - ui->m_lpObjectList->setModel(m_lpObjectModel); + connect(ui->m_lpDescription, &cTextEdit::gotFocus, (cMainWindow*)parent, &cMainWindow::onTextEditGotFocus); + connect(ui->m_lpDescription, &cTextEdit::lostFocus, (cMainWindow*)parent, &cMainWindow::onTextEditLostFocus); - connect(ui->m_lpCharacterList, &cTreeView::doubleClicked, this, &cRechercheWindow::onCharacterDoubleClicked); - connect(ui->m_lpPlaceList, &cTreeView::doubleClicked, this, &cRechercheWindow::onPlaceDoubleClicked); - connect(ui->m_lpObjectList, &cTreeView::doubleClicked, this, &cRechercheWindow::onObjectDoubleClicked); + connect(ui->m_lpCharacterList, &cComboBox::gotFocus, (cMainWindow*)parent, &cMainWindow::onComboBoxGotFocus); + connect(ui->m_lpCharacterList, &cComboBox::lostFocus, (cMainWindow*)parent, &cMainWindow::onComboBoxLostFocus); - connect(ui->m_lpName, &cLineEdit::gotFocus, (cMainWindow*)parent, &cMainWindow::onLineEditGotFocus); - connect(ui->m_lpName, &cLineEdit::lostFocus, (cMainWindow*)parent, &cMainWindow::onLineEditLostFocus); + connect(ui->m_lpPlaceList, &cComboBox::gotFocus, (cMainWindow*)parent, &cMainWindow::onComboBoxGotFocus); + connect(ui->m_lpPlaceList, &cComboBox::lostFocus, (cMainWindow*)parent, &cMainWindow::onComboBoxLostFocus); - connect(ui->m_lpLink, &cLineEdit::gotFocus, (cMainWindow*)parent, &cMainWindow::onLineEditGotFocus); - connect(ui->m_lpLink, &cLineEdit::lostFocus, (cMainWindow*)parent, &cMainWindow::onLineEditLostFocus); + connect(ui->m_lpObjectList, &cComboBox::gotFocus, (cMainWindow*)parent, &cMainWindow::onComboBoxGotFocus); + connect(ui->m_lpObjectList, &cComboBox::lostFocus, (cMainWindow*)parent, &cMainWindow::onComboBoxLostFocus); - connect(ui->m_lpDescription, &cTextEdit::gotFocus, (cMainWindow*)parent, &cMainWindow::onTextEditGotFocus); - connect(ui->m_lpDescription, &cTextEdit::lostFocus, (cMainWindow*)parent, &cMainWindow::onTextEditLostFocus); + connect(ui->m_lpCaracterAdd, &QPushButton::clicked, this, &cRechercheWindow::onAddCharacterToList); + connect(ui->m_lpCharacterRemove, &QPushButton::clicked, this, &cRechercheWindow::onRemoveCharacterFromList); - connect(ui->m_lpCharacterList, &cTreeView::gotFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewGotFocus); - connect(ui->m_lpCharacterList, &cTreeView::lostFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewLostFocus); + connect(ui->m_lpPlaceAdd, &QPushButton::clicked, this, &cRechercheWindow::onAddPlaceToList); + connect(ui->m_lpPlaceRemove, &QPushButton::clicked, this, &cRechercheWindow::onRemovePlaceFromList); - connect(ui->m_lpObjectList, &cTreeView::gotFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewGotFocus); - connect(ui->m_lpObjectList, &cTreeView::lostFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewLostFocus); - - connect(ui->m_lpPlaceList, &cTreeView::gotFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewGotFocus); - connect(ui->m_lpPlaceList, &cTreeView::lostFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewLostFocus); + connect(ui->m_lpObjectAdd, &QPushButton::clicked, this, &cRechercheWindow::onAddObjectToList); + connect(ui->m_lpObjectRemove, &QPushButton::clicked, this, &cRechercheWindow::onRemoveObjectFromList); } cRechercheWindow::~cRechercheWindow() @@ -63,9 +66,12 @@ cRechercheWindow::~cRechercheWindow() delete ui; } -void cRechercheWindow::setRecherche(cRecherche* lpRecherche) +void cRechercheWindow::setRecherche(cRecherche* lpRecherche, cCharacterList* lpCharacterList, cPlaceList* lpPlaceList, cObjectList* lpObjectList) { - m_lpRecherche = lpRecherche; + m_lpRecherche = lpRecherche; + m_lpCharacterList = lpCharacterList; + m_lpPlaceList = lpPlaceList; + m_lpObjectList = lpObjectList; ui->m_lpName->setText(lpRecherche->name()); ui->m_lpLink->setText(lpRecherche->link()); @@ -83,101 +89,13 @@ void cRechercheWindow::setRecherche(cRecherche* lpRecherche) ui->m_lpLayout->addWidget(lpImageWidget); } - QSpacerItem* lpSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); - ui->m_lpLayout->addItem(lpSpacer); + fillCharacterList(); + fillPlaceList(); + fillObjectList(); - QList characterList = lpRecherche->characterList(); - QList placeList = lpRecherche->placeList(); - QList objectList = lpRecherche->objectList(); - - QStringList headerLabels; - - headerLabels = QStringList() << tr("name") << tr("creature") << tr("gender") << tr("title"); - m_lpCharacterModel->setHorizontalHeaderLabels(headerLabels); - for(int x = 0;x < characterList.count();x++) - { - cCharacterDescription* lpCharacterDescription = characterList[x]; - cCharacter* lpCharacter = lpCharacterDescription->character(); - QList items; - - items.append(new QStandardItem(lpCharacter->name())); - items.append(new QStandardItem(lpCharacter->creature())); - items.append(new QStandardItem(lpCharacter->genderText())); - items.append(new QStandardItem(lpCharacter->title())); - - if(lpCharacter->mainCharacter()) - { - QFont font = items[0]->font(); - font.setBold(true); - - for(int y = 0;y < headerLabels.count();y++) - items[y]->setFont(font); - } - - for(int y = 0;y < headerLabels.count();y++) - { - items[y]->setData(QVariant::fromValue(lpCharacter)); - items[y]->setToolTip(lpCharacter->description()->toPlainText()); - } - - m_lpCharacterModel->appendRow(items); - } - - ui->m_lpCharacterList->header()->setStretchLastSection(true); - - for(int i = 0;i < headerLabels.count();i++) - ui->m_lpCharacterList->resizeColumnToContents(i); - - headerLabels = QStringList() << tr("name") << tr("location") << tr("type"); - m_lpPlaceModel->setHorizontalHeaderLabels(headerLabels); - for(int x = 0;x < placeList.count();x++) - { - cPlaceDescription* lpPlaceDescription = placeList[x]; - cPlace* lpPlace = lpPlaceDescription->place(); - QList items; - - items.append(new QStandardItem(lpPlace->name())); - items.append(new QStandardItem(lpPlace->location())); - items.append(new QStandardItem(lpPlace->type())); - - for(int y = 0;y < headerLabels.count();y++) - { - items[y]->setData(QVariant::fromValue(lpPlace)); - items[y]->setToolTip(lpPlace->description()->toPlainText()); - } - - m_lpPlaceModel->appendRow(items); - } - - ui->m_lpPlaceList->header()->setStretchLastSection(true); - - for(int i = 0;i < headerLabels.count();i++) - ui->m_lpPlaceList->resizeColumnToContents(i); - - headerLabels = QStringList() << tr("name") << tr("type"); - m_lpObjectModel->setHorizontalHeaderLabels(headerLabels); - for(int x = 0;x < objectList.count();x++) - { - cObjectDescription* lpObjectDescription = objectList[x]; - cObject* lpObject = lpObjectDescription->object(); - QList items; - - items.append(new QStandardItem(lpObject->name())); - items.append(new QStandardItem(lpObject->type())); - - for(int y = 0;y < headerLabels.count();y++) - { - items[y]->setData(QVariant::fromValue(lpObject)); - items[y]->setToolTip(lpObject->description()->toPlainText()); - } - - m_lpObjectModel->appendRow(items); - } - - ui->m_lpObjectList->header()->setStretchLastSection(true); - - for(int i = 0;i < headerLabels.count();i++) - ui->m_lpObjectList->resizeColumnToContents(i); + connect(ui->m_lpCharacterList, QOverload::of(&cComboBox::currentIndexChanged), this, &cRechercheWindow::onCharacterIndexChanged); + connect(ui->m_lpPlaceList, QOverload::of(&cComboBox::currentIndexChanged), this, &cRechercheWindow::onPlaceIndexChanged); + connect(ui->m_lpObjectList, QOverload::of(&cComboBox::currentIndexChanged), this, &cRechercheWindow::onObjectIndexChanged); setWindowTitle(tr("[recherche] - ") + lpRecherche->name()); @@ -191,30 +109,6 @@ cRecherche* cRechercheWindow::recherche() return(m_lpRecherche); } -void cRechercheWindow::onCharacterDoubleClicked(const QModelIndex& index) -{ - QStandardItem* lpItem = m_lpCharacterModel->itemFromIndex(index); - cCharacter* lpCharacter = qvariant_cast(lpItem->data()); - if(lpCharacter) - showCharacterWindow(lpCharacter); -} - -void cRechercheWindow::onPlaceDoubleClicked(const QModelIndex& index) -{ - QStandardItem* lpItem = m_lpPlaceModel->itemFromIndex(index); - cPlace* lpPlace = qvariant_cast(lpItem->data()); - if(lpPlace) - showPlaceWindow(lpPlace); -} - -void cRechercheWindow::onObjectDoubleClicked(const QModelIndex& index) -{ - QStandardItem* lpItem = m_lpObjectModel->itemFromIndex(index); - cObject* lpObject = qvariant_cast(lpItem->data()); - if(lpObject) - showObjectWindow(lpObject); -} - void cRechercheWindow::onNameChanged(const QString& szName) { m_lpRecherche->setName(szName); @@ -243,3 +137,266 @@ void cRechercheWindow::onDescriptionChanged() { m_lpMainWindow->somethingChanged(); } + +void cRechercheWindow::onCharacterIndexChanged(int index) +{ + ui->m_lpCharacterDetails->setCurrentIndex(index); +} + +void cRechercheWindow::onPlaceIndexChanged(int index) +{ + ui->m_lpPlaceDetails->setCurrentIndex(index); +} + +void cRechercheWindow::onObjectIndexChanged(int index) +{ + ui->m_lpObjectDetails->setCurrentIndex(index); +} + +void cRechercheWindow::onCharacterDescriptionChanged() +{ + m_lpMainWindow->somethingChanged(); +} + +void cRechercheWindow::onPlaceDescriptionChanged() +{ + m_lpMainWindow->somethingChanged(); +} + +void cRechercheWindow::onObjectDescriptionChanged() +{ + m_lpMainWindow->somethingChanged(); +} + +void cRechercheWindow::onAddCharacterToList() +{ + cCharacterSelectDialog* lpDialog = new cCharacterSelectDialog(this); + lpDialog->setCharacterList(m_lpCharacterList, m_lpRecherche->characterList()); + + if(lpDialog->exec() == QDialog::Rejected) + { + delete lpDialog; + return; + } + + cCharacter* lpCharacterNew = lpDialog->selected(); + delete lpDialog; + + if(!lpCharacterNew) + return; + + m_lpRecherche->addCharacter(lpCharacterNew, new cTextDocument); + + fillCharacterList(lpCharacterNew); + + m_lpMainWindow->somethingChanged(); +} + +void cRechercheWindow::onRemoveCharacterFromList() +{ + cCharacterDescription* lpCharacterDescription = qvariant_cast(ui->m_lpCharacterList->currentData()); + + if(!lpCharacterDescription) + return; + + if(QMessageBox::question(this, "Scene", QString(tr("Do you want to delete \"%1\" from list?")).arg(lpCharacterDescription->character()->name())) == QMessageBox::No) + return; + + m_lpRecherche->removeCharacter(lpCharacterDescription); + + fillCharacterList(); + + m_lpMainWindow->somethingChanged(); +} + +void cRechercheWindow::onAddPlaceToList() +{ + cPlaceSelectDialog* lpDialog = new cPlaceSelectDialog(this); + lpDialog->setPlaceList(m_lpPlaceList, m_lpRecherche->placeList()); + + if(lpDialog->exec() == QDialog::Rejected) + { + delete lpDialog; + return; + } + + cPlace* lpPlaceNew = lpDialog->selected(); + delete lpDialog; + + if(!lpPlaceNew) + return; + + m_lpRecherche->addPlace(lpPlaceNew, new cTextDocument); + + fillPlaceList(lpPlaceNew); + + m_lpMainWindow->somethingChanged(); +} + +void cRechercheWindow::onRemovePlaceFromList() +{ + cPlaceDescription* lpPlaceDescription = qvariant_cast(ui->m_lpPlaceList->currentData()); + + if(!lpPlaceDescription) + return; + + if(QMessageBox::question(this, "Scene", QString(tr("Do you want to delete \"%1\" from list?")).arg(lpPlaceDescription->place()->name())) == QMessageBox::No) + return; + + m_lpRecherche->removePlace(lpPlaceDescription); + + fillPlaceList(); + + m_lpMainWindow->somethingChanged(); +} + +void cRechercheWindow::onAddObjectToList() +{ + cObjectSelectDialog* lpDialog = new cObjectSelectDialog(this); + lpDialog->setObjectList(m_lpObjectList, m_lpRecherche->objectList()); + + if(lpDialog->exec() == QDialog::Rejected) + { + delete lpDialog; + return; + } + + cObject* lpObjectNew = lpDialog->selected(); + delete lpDialog; + + if(!lpObjectNew) + return; + + m_lpRecherche->addObject(lpObjectNew, new cTextDocument); + + fillObjectList(lpObjectNew); + + m_lpMainWindow->somethingChanged(); +} + +void cRechercheWindow::onRemoveObjectFromList() +{ + cObjectDescription* lpObjectDescription = qvariant_cast(ui->m_lpObjectList->currentData()); + + if(!lpObjectDescription) + return; + + if(QMessageBox::question(this, "Scene", QString(tr("Do you want to delete \"%1\" from list?")).arg(lpObjectDescription->object()->name())) == QMessageBox::No) + return; + + m_lpRecherche->removeObject(lpObjectDescription); + + fillObjectList(); + + m_lpMainWindow->somethingChanged(); +} + +void cRechercheWindow::fillCharacterList(cCharacter* lpCharacterNew) +{ + QList characterList = m_lpRecherche->characterList(); + + ui->m_lpCharacterList->clear(); + + for(int x = ui->m_lpCharacterDetails->count()-1;x >= 0;x--) + ui->m_lpCharacterDetails->removeWidget(ui->m_lpCharacterDetails->widget(x)); + + qint16 index = 0; + + for(int x = 0;x < characterList.count();x++) + { + cCharacterDescription* lpCharacterDescription = characterList[x]; + cCharacter* lpCharacter = lpCharacterDescription->character(); + + ui->m_lpCharacterList->addItem(lpCharacter->name(), QVariant::fromValue(lpCharacterDescription)); + cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpCharacterDetails); + lpTextEdit->setDocument(lpCharacterDescription->description()); + ui->m_lpCharacterDetails->addWidget(lpTextEdit); + + connect(lpTextEdit, &cTextEdit::gotFocus, m_lpMainWindow, &cMainWindow::onTextEditGotFocus); + connect(lpTextEdit, &cTextEdit::lostFocus, m_lpMainWindow, &cMainWindow::onTextEditLostFocus); + + connect(lpTextEdit, &cTextEdit::textChanged, this, &cRechercheWindow::onCharacterDescriptionChanged); + + if(lpCharacter == lpCharacterNew) + index = x; + } + + ui->m_lpCharacterList->setCurrentIndex(index); + ui->m_lpCharacterDetails->setCurrentIndex(index); + + ui->m_lpCharacterRemove->setEnabled((ui->m_lpCharacterList->count() > 0)); + ui->m_lpCharacterShowDetails->setEnabled((ui->m_lpCharacterList->count() > 0)); +} + +void cRechercheWindow::fillPlaceList(cPlace* lpPlaceNew) +{ + QList placeList = m_lpRecherche->placeList(); + + ui->m_lpPlaceList->clear(); + + for(int x = ui->m_lpPlaceDetails->count()-1;x >= 0;x--) + ui->m_lpPlaceDetails->removeWidget(ui->m_lpPlaceDetails->widget(x)); + + qint16 index = 0; + + for(int x = 0;x < placeList.count();x++) + { + cPlaceDescription* lpPlaceDescription = placeList[x]; + cPlace* lpPlace = lpPlaceDescription->place(); + + ui->m_lpPlaceList->addItem(lpPlace->name(), QVariant::fromValue(lpPlaceDescription)); + cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpPlaceDetails); + lpTextEdit->setDocument(lpPlaceDescription->description()); + ui->m_lpPlaceDetails->addWidget(lpTextEdit); + + connect(lpTextEdit, &cTextEdit::gotFocus, m_lpMainWindow, &cMainWindow::onTextEditGotFocus); + connect(lpTextEdit, &cTextEdit::lostFocus, m_lpMainWindow, &cMainWindow::onTextEditLostFocus); + + connect(lpTextEdit, &cTextEdit::textChanged, this, &cRechercheWindow::onPlaceDescriptionChanged); + + if(lpPlace == lpPlaceNew) + index = x; + } + + ui->m_lpPlaceList->setCurrentIndex(index); + ui->m_lpPlaceDetails->setCurrentIndex(index); + + ui->m_lpPlaceRemove->setEnabled((ui->m_lpPlaceList->count() > 0)); + ui->m_lpPlaceShowDetails->setEnabled((ui->m_lpPlaceList->count() > 0)); +} + +void cRechercheWindow::fillObjectList(cObject* lpObjectNew) +{ + QList objectList = m_lpRecherche->objectList(); + + ui->m_lpObjectList->clear(); + + for(int x = ui->m_lpObjectDetails->count()-1;x >= 0;x--) + ui->m_lpObjectDetails->removeWidget(ui->m_lpObjectDetails->widget(x)); + + qint16 index = 0; + + for(int x = 0;x < objectList.count();x++) + { + cObjectDescription* lpObjectDescription = objectList[x]; + cObject* lpObject = lpObjectDescription->object(); + + ui->m_lpObjectList->addItem(lpObject->name(), QVariant::fromValue(lpObjectDescription)); + cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpObjectDetails); + lpTextEdit->setDocument(lpObjectDescription->description()); + ui->m_lpObjectDetails->addWidget(lpTextEdit); + + connect(lpTextEdit, &cTextEdit::gotFocus, m_lpMainWindow, &cMainWindow::onTextEditGotFocus); + connect(lpTextEdit, &cTextEdit::lostFocus, m_lpMainWindow, &cMainWindow::onTextEditLostFocus); + + connect(lpTextEdit, &cTextEdit::textChanged, this, &cRechercheWindow::onObjectDescriptionChanged); + + if(lpObject == lpObjectNew) + index = x; + } + ui->m_lpObjectList->setCurrentIndex(index); + ui->m_lpObjectDetails->setCurrentIndex(index); + + ui->m_lpObjectRemove->setEnabled((ui->m_lpObjectList->count() > 0)); + ui->m_lpObjectShowDetails->setEnabled((ui->m_lpObjectList->count() > 0)); +} diff --git a/crecherchewindow.h b/crecherchewindow.h index aeee27c..5c84676 100644 --- a/crecherchewindow.h +++ b/crecherchewindow.h @@ -45,7 +45,7 @@ public: \fn setRecherche \param lpRecherche */ - void setRecherche(cRecherche* lpRecherche); + void setRecherche(cRecherche* lpRecherche, cCharacterList* lpCharacterList, cPlaceList* lpPlaceList, cObjectList* lpObjectList); /*! \brief @@ -54,28 +54,30 @@ public: */ cRecherche* recherche(); +private: + /*! + \brief + + \fn fillCharacterList + \param bSelectFirst + */ + void fillCharacterList(cCharacter* lpCharacterNew = 0); + /*! + \brief + + \fn fillPlaceList + \param bSelectFirst + */ + void fillPlaceList(cPlace* lpPlaceNew = 0); + /*! + \brief + + \fn fillObjectList + \param bSelectFirst + */ + void fillObjectList(cObject* lpObjectNew = 0); + private slots: - /*! - \brief - - \fn onCharacterDoubleClicked - \param index - */ - void onCharacterDoubleClicked(const QModelIndex& index); - /*! - \brief - - \fn onPlaceDoubleClicked - \param index - */ - void onPlaceDoubleClicked(const QModelIndex& index); - /*! - \brief - - \fn onObjectDoubleClicked - \param index - */ - void onObjectDoubleClicked(const QModelIndex& index); /*! \brief @@ -98,6 +100,88 @@ private slots: */ void onDescriptionChanged(); + /*! + \brief + + \fn onCharacterDescriptionChanged + */ + void onCharacterDescriptionChanged(); + + /*! + \brief + + \fn onPlaceDescriptionChanged + */ + void onPlaceDescriptionChanged(); + + /*! + \brief + + \fn onPlaceDescriptionChanged + */ + void onObjectDescriptionChanged(); + + /*! + \brief + + \fn onCharacterIndexChanged + \param index + */ + void onCharacterIndexChanged(int index); + /*! + \brief + + \fn onPlaceIndexChanged + \param index + */ + void onPlaceIndexChanged(int index); + /*! + \brief + + \fn onObjectIndexChanged + \param index + */ + void onObjectIndexChanged(int index); + + /*! + \brief + + \fn onAddCharacterToList + */ + void onAddCharacterToList(); + /*! + \brief + + \fn onRemoveCharacterFromList + */ + void onRemoveCharacterFromList(); + + /*! + \brief + + \fn onAddPlaceToList + */ + void onAddPlaceToList(); + /*! + \brief + + \fn onRemovePlaceFromList + */ + void onRemovePlaceFromList(); + + /*! + \brief + + \fn onAddObjectToList + */ + void onAddObjectToList(); + /*! + \brief + + \fn onRemoveObjectFromList + */ + void onRemoveObjectFromList(); + signals: /*! \brief @@ -124,10 +208,10 @@ signals: private: Ui::cRechercheWindow* ui; /*!< TODO: describe */ cMainWindow* m_lpMainWindow; /*!< TODO: describe */ - QStandardItemModel* m_lpCharacterModel; /*!< TODO: describe */ - QStandardItemModel* m_lpPlaceModel; /*!< TODO: describe */ - QStandardItemModel* m_lpObjectModel; /*!< TODO: describe */ cRecherche* m_lpRecherche; /*!< TODO: describe */ + cCharacterList* m_lpCharacterList; /*!< TODO: describe */ + cPlaceList* m_lpPlaceList; /*!< TODO: describe */ + cObjectList* m_lpObjectList; /*!< TODO: describe */ }; #endif // CRECHERCHEWINDOW_H diff --git a/crecherchewindow.ui b/crecherchewindow.ui index 572ba3f..85b097a 100644 --- a/crecherchewindow.ui +++ b/crecherchewindow.ui @@ -17,7 +17,7 @@ - 0 + 2 @@ -117,25 +117,43 @@ - - - QAbstractItemView::NoEditTriggers - - - - - - - - Object - - - - - - QAbstractItemView::NoEditTriggers - - + + + + + + + + + + details... + + + + + + + add... + + + + + + + remove + + + + + + + + + -1 + + + + @@ -145,11 +163,85 @@ - - - QAbstractItemView::NoEditTriggers - - + + + + + + + + + + details... + + + + + + + add... + + + + + + + remove + + + + + + + + + -1 + + + + + + + + + + Object + + + + + + + + + + + + + details... + + + + + + + add... + + + + + + + remove + + + + + + + + + @@ -169,9 +261,9 @@
clineedit.h
- cTreeView - QTreeView -
ctreeview.h
+ cComboBox + QComboBox +
ccombobox.h
diff --git a/cscene.cpp b/cscene.cpp index bc88573..25e2cb7 100644 --- a/cscene.cpp +++ b/cscene.cpp @@ -146,6 +146,11 @@ void cScene::addObject(cObject* lpObject, cTextDocument* lpDescription) m_objectList.append(new cObjectDescription(lpObject, lpDescription)); } +void cScene::removeObject(cObjectDescription* lpObject) +{ + m_objectList.removeOne(lpObject); +} + QList cScene::objectList() { return(m_objectList); @@ -156,6 +161,11 @@ void cScene::addPlace(cPlace* lpPlace, cTextDocument* lpDescription) m_placeList.append(new cPlaceDescription(lpPlace, lpDescription)); } +void cScene::removePlace(cPlaceDescription* lpPlace) +{ + m_placeList.removeOne(lpPlace); +} + QList cScene::placeList() { return(m_placeList); @@ -461,10 +471,32 @@ bool cSceneList::save() objectDelete.prepare("DELETE FROM sceneObject WHERE sceneID=:sceneID;"); objectAdd.prepare("INSERT INTO sceneObject (sceneID, objectID, description) VALUES (:sceneID, :objectID, :description);"); + myDebug; for(int x = 0;x < count();x++) { cScene* lpScene = at(x); + characterDelete.bindValue(":sceneID", lpScene->id()); + if(!characterDelete.exec()) + { + myDebug << characterDelete.lastError().text(); + return(false); + } + + placeDelete.bindValue(":sceneID", lpScene->id()); + if(!placeDelete.exec()) + { + myDebug << placeDelete.lastError().text(); + return(false); + } + + objectDelete.bindValue(":sceneID", lpScene->id()); + if(!objectDelete.exec()) + { + myDebug << objectDelete.lastError().text(); + return(false); + } + if(lpScene->deleted()) { queryDelete.bindValue(":id", lpScene->id()); @@ -522,13 +554,6 @@ bool cSceneList::save() lpScene->setID(querySelect.value("id").toInt()); } - characterDelete.bindValue(":sceneID", lpScene->id()); - if(!characterDelete.exec()) - { - myDebug << characterDelete.lastError().text(); - return(false); - } - QList character = lpScene->characterList(); for(int x = 0;x < character.count();x++) @@ -538,6 +563,7 @@ bool cSceneList::save() characterAdd.bindValue(":sceneID", lpScene->id()); characterAdd.bindValue(":characterID", lpCharacter->character()->id()); characterAdd.bindValue(":description", textDocument2Blob(lpCharacter->description())); + if(!characterAdd.exec()) { myDebug << characterAdd.lastError().text(); @@ -545,13 +571,6 @@ bool cSceneList::save() } } - placeDelete.bindValue(":sceneID", lpScene->id()); - if(!placeDelete.exec()) - { - myDebug << placeDelete.lastError().text(); - return(false); - } - QList place = lpScene->placeList(); for(int x = 0;x < place.count();x++) @@ -561,6 +580,7 @@ bool cSceneList::save() placeAdd.bindValue(":sceneID", lpScene->id()); placeAdd.bindValue(":placeID", lpPlace->place()->id()); placeAdd.bindValue(":description", textDocument2Blob(lpPlace->description())); + if(!placeAdd.exec()) { myDebug << placeAdd.lastError().text(); @@ -568,13 +588,6 @@ bool cSceneList::save() } } - objectDelete.bindValue(":sceneID", lpScene->id()); - if(!objectDelete.exec()) - { - myDebug << objectDelete.lastError().text(); - return(false); - } - QList object = lpScene->objectList(); for(int x = 0;x < object.count();x++) @@ -584,6 +597,7 @@ bool cSceneList::save() objectAdd.bindValue(":sceneID", lpScene->id()); objectAdd.bindValue(":objectID", lpObject->object()->id()); objectAdd.bindValue(":description", textDocument2Blob(lpObject->description())); + if(!objectAdd.exec()) { myDebug << objectAdd.lastError().text(); diff --git a/cscene.h b/cscene.h index 015a324..6ea21fa 100644 --- a/cscene.h +++ b/cscene.h @@ -215,9 +215,8 @@ public: /*! \brief - \fn addCharacter + \fn removeCharacter \param lpCharacter - \param lpDescription */ void removeCharacter(cCharacterDescription* lpCharacter); /*! @@ -239,6 +238,13 @@ public: /*! \brief + \fn removeObject + \param lpObject + */ + void removeObject(cObjectDescription* lpObject); + /*! + \brief + \fn objectList \return QList */ @@ -255,6 +261,13 @@ public: /*! \brief + \fn removePlace + \param lpPlace + */ + void removePlace(cPlaceDescription* lpPlace); + /*! + \brief + \fn placeList \return QList */ diff --git a/cscenewindow.cpp b/cscenewindow.cpp index 0f4eda8..6b99b91 100644 --- a/cscenewindow.cpp +++ b/cscenewindow.cpp @@ -7,6 +7,8 @@ #include "ui_cscenewindow.h" #include "ccharacterselectdialog.h" +#include "cplaceselectdialog.h" +#include "cobjectselectdialog.h" #include "cmainwindow.h" @@ -127,72 +129,9 @@ void cSceneWindow::setScene(cScene* lpScene, cCharacterList* lpCharacterList, cP ui->m_lpTargetDate->setDateTime(lpScene->targetDate()); ui->m_lpText->setDocument(lpScene->text()); - QList characterList = lpScene->characterList(); - QList placeList = lpScene->placeList(); - QList objectList = lpScene->objectList(); - - for(int x = 0;x < characterList.count();x++) - { - cCharacterDescription* lpCharacterDescription = characterList[x]; - cCharacter* lpCharacter = lpCharacterDescription->character(); - - ui->m_lpCharacterList->addItem(lpCharacter->name(), QVariant::fromValue(lpCharacterDescription)); - cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpCharacterDetails); - lpTextEdit->setDocument(lpCharacterDescription->description()); - ui->m_lpCharacterDetails->addWidget(lpTextEdit); - - connect(lpTextEdit, &cTextEdit::gotFocus, m_lpMainWindow, &cMainWindow::onTextEditGotFocus); - connect(lpTextEdit, &cTextEdit::lostFocus, m_lpMainWindow, &cMainWindow::onTextEditLostFocus); - - connect(lpTextEdit, &cTextEdit::textChanged, this, &cSceneWindow::onCharacterDescriptionChanged); - } - ui->m_lpCharacterList->setCurrentText(0); - ui->m_lpCharacterDetails->setCurrentIndex(0); - - ui->m_lpCharacterRemove->setEnabled((characterList.count() > 0)); - ui->m_lpCharacterShowDetails->setEnabled((characterList.count() > 0)); - - for(int x = 0;x < placeList.count();x++) - { - cPlaceDescription* lpPlaceDescription = placeList[x]; - cPlace* lpPlace = lpPlaceDescription->place(); - - ui->m_lpPlaceList->addItem(lpPlace->name(), QVariant::fromValue(lpPlaceDescription)); - cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpPlaceDetails); - lpTextEdit->setDocument(lpPlaceDescription->description()); - ui->m_lpPlaceDetails->addWidget(lpTextEdit); - - connect(lpTextEdit, &cTextEdit::gotFocus, m_lpMainWindow, &cMainWindow::onTextEditGotFocus); - connect(lpTextEdit, &cTextEdit::lostFocus, m_lpMainWindow, &cMainWindow::onTextEditLostFocus); - - connect(lpTextEdit, &cTextEdit::textChanged, this, &cSceneWindow::onPlaceDescriptionChanged); - } - ui->m_lpPlaceList->setCurrentText(0); - ui->m_lpPlaceDetails->setCurrentIndex(0); - - ui->m_lpPlaceRemove->setEnabled((characterList.count() > 0)); - ui->m_lpPlaceShowDetails->setEnabled((characterList.count() > 0)); - - for(int x = 0;x < objectList.count();x++) - { - cObjectDescription* lpObjectDescription = objectList[x]; - cObject* lpObject = lpObjectDescription->object(); - - ui->m_lpObjectList->addItem(lpObject->name(), QVariant::fromValue(lpObjectDescription)); - cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpObjectDetails); - lpTextEdit->setDocument(lpObjectDescription->description()); - ui->m_lpObjectDetails->addWidget(lpTextEdit); - - connect(lpTextEdit, &cTextEdit::gotFocus, m_lpMainWindow, &cMainWindow::onTextEditGotFocus); - connect(lpTextEdit, &cTextEdit::lostFocus, m_lpMainWindow, &cMainWindow::onTextEditLostFocus); - - connect(lpTextEdit, &cTextEdit::textChanged, this, &cSceneWindow::onObjectDescriptionChanged); - } - ui->m_lpObjectList->setCurrentText(0); - ui->m_lpObjectDetails->setCurrentIndex(0); - - ui->m_lpObjectRemove->setEnabled((characterList.count() > 0)); - ui->m_lpObjectShowDetails->setEnabled((characterList.count() > 0)); + fillCharacterList(); + fillPlaceList(); + fillObjectList(); connect(ui->m_lpCharacterList, QOverload::of(&cComboBox::currentIndexChanged), this, &cSceneWindow::onCharacterIndexChanged); connect(ui->m_lpPlaceList, QOverload::of(&cComboBox::currentIndexChanged), this, &cSceneWindow::onPlaceIndexChanged); @@ -360,8 +299,116 @@ void cSceneWindow::onAddCharacterToList() if(!lpCharacterNew) return; - m_lpScene->addCharacter(lpCharacterNew, new cTextDocument(this)); + m_lpScene->addCharacter(lpCharacterNew, new cTextDocument); + fillCharacterList(lpCharacterNew); + + m_lpMainWindow->somethingChanged(); +} + +void cSceneWindow::onRemoveCharacterFromList() +{ + cCharacterDescription* lpCharacterDescription = qvariant_cast(ui->m_lpCharacterList->currentData()); + + if(!lpCharacterDescription) + return; + + if(QMessageBox::question(this, "Scene", QString(tr("Do you want to delete \"%1\" from list?")).arg(lpCharacterDescription->character()->name())) == QMessageBox::No) + return; + + m_lpScene->removeCharacter(lpCharacterDescription); + + fillCharacterList(); + + m_lpMainWindow->somethingChanged(); +} + +void cSceneWindow::onAddPlaceToList() +{ + cPlaceSelectDialog* lpDialog = new cPlaceSelectDialog(this); + lpDialog->setPlaceList(m_lpPlaceList, m_lpScene->placeList()); + + if(lpDialog->exec() == QDialog::Rejected) + { + delete lpDialog; + return; + } + + cPlace* lpPlaceNew = lpDialog->selected(); + delete lpDialog; + + if(!lpPlaceNew) + return; + + m_lpScene->addPlace(lpPlaceNew, new cTextDocument); + + fillPlaceList(lpPlaceNew); + + m_lpMainWindow->somethingChanged(); +} + +void cSceneWindow::onRemovePlaceFromList() +{ + cPlaceDescription* lpPlaceDescription = qvariant_cast(ui->m_lpPlaceList->currentData()); + + if(!lpPlaceDescription) + return; + + if(QMessageBox::question(this, "Scene", QString(tr("Do you want to delete \"%1\" from list?")).arg(lpPlaceDescription->place()->name())) == QMessageBox::No) + return; + + m_lpScene->removePlace(lpPlaceDescription); + + QList placeList = m_lpScene->placeList(); + + fillPlaceList(); + + m_lpMainWindow->somethingChanged(); +} + +void cSceneWindow::onAddObjectToList() +{ + cObjectSelectDialog* lpDialog = new cObjectSelectDialog(this); + lpDialog->setObjectList(m_lpObjectList, m_lpScene->objectList()); + + if(lpDialog->exec() == QDialog::Rejected) + { + delete lpDialog; + return; + } + + cObject* lpObjectNew = lpDialog->selected(); + delete lpDialog; + + if(!lpObjectNew) + return; + + m_lpScene->addObject(lpObjectNew, new cTextDocument); + + fillObjectList(lpObjectNew); + + m_lpMainWindow->somethingChanged(); +} + +void cSceneWindow::onRemoveObjectFromList() +{ + cObjectDescription* lpObjectDescription = qvariant_cast(ui->m_lpObjectList->currentData()); + + if(!lpObjectDescription) + return; + + if(QMessageBox::question(this, "Scene", QString(tr("Do you want to delete \"%1\" from list?")).arg(lpObjectDescription->object()->name())) == QMessageBox::No) + return; + + m_lpScene->removeObject(lpObjectDescription); + + fillObjectList(); + + m_lpMainWindow->somethingChanged(); +} + +void cSceneWindow::fillCharacterList(cCharacter* lpCharacterNew) +{ QList characterList = m_lpScene->characterList(); ui->m_lpCharacterList->clear(); @@ -389,78 +436,83 @@ void cSceneWindow::onAddCharacterToList() if(lpCharacter == lpCharacterNew) index = x; } + ui->m_lpCharacterList->setCurrentIndex(index); ui->m_lpCharacterDetails->setCurrentIndex(index); ui->m_lpCharacterRemove->setEnabled((ui->m_lpCharacterList->count() > 0)); ui->m_lpCharacterShowDetails->setEnabled((ui->m_lpCharacterList->count() > 0)); - - m_lpMainWindow->somethingChanged(); } -void cSceneWindow::onRemoveCharacterFromList() +void cSceneWindow::fillPlaceList(cPlace* lpPlaceNew) { - cCharacterDescription* lpCharacterDescription = qvariant_cast(ui->m_lpCharacterList->currentData()); + QList placeList = m_lpScene->placeList(); - if(!lpCharacterDescription) - return; + ui->m_lpPlaceList->clear(); - if(QMessageBox::question(this, "Scene", QString(tr("Do you want to delete \"%1\" from list?")).arg(lpCharacterDescription->character()->name())) == QMessageBox::No) - return; + for(int x = ui->m_lpPlaceDetails->count()-1;x >= 0;x--) + ui->m_lpPlaceDetails->removeWidget(ui->m_lpPlaceDetails->widget(x)); - m_lpScene->removeCharacter(lpCharacterDescription); + qint16 index = 0; - QList characterList = m_lpScene->characterList(); - - ui->m_lpCharacterList->clear(); - - for(int x = ui->m_lpCharacterDetails->count()-1;x >= 0;x--) - ui->m_lpCharacterDetails->removeWidget(ui->m_lpCharacterDetails->widget(x)); - - for(int x = 0;x < characterList.count();x++) + for(int x = 0;x < placeList.count();x++) { - cCharacterDescription* lpCharacterDescription = characterList[x]; - cCharacter* lpCharacter = lpCharacterDescription->character(); + cPlaceDescription* lpPlaceDescription = placeList[x]; + cPlace* lpPlace = lpPlaceDescription->place(); - ui->m_lpCharacterList->addItem(lpCharacter->name(), QVariant::fromValue(lpCharacterDescription)); - cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpCharacterDetails); - lpTextEdit->setDocument(lpCharacterDescription->description()); - ui->m_lpCharacterDetails->addWidget(lpTextEdit); + ui->m_lpPlaceList->addItem(lpPlace->name(), QVariant::fromValue(lpPlaceDescription)); + cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpPlaceDetails); + lpTextEdit->setDocument(lpPlaceDescription->description()); + ui->m_lpPlaceDetails->addWidget(lpTextEdit); connect(lpTextEdit, &cTextEdit::gotFocus, m_lpMainWindow, &cMainWindow::onTextEditGotFocus); connect(lpTextEdit, &cTextEdit::lostFocus, m_lpMainWindow, &cMainWindow::onTextEditLostFocus); - connect(lpTextEdit, &cTextEdit::textChanged, this, &cSceneWindow::onCharacterDescriptionChanged); + connect(lpTextEdit, &cTextEdit::textChanged, this, &cSceneWindow::onPlaceDescriptionChanged); + + if(lpPlace == lpPlaceNew) + index = x; } - ui->m_lpCharacterList->setCurrentIndex(0); - ui->m_lpCharacterDetails->setCurrentIndex(0); - ui->m_lpCharacterRemove->setEnabled((ui->m_lpCharacterList->count() > 0)); - ui->m_lpCharacterShowDetails->setEnabled((ui->m_lpCharacterList->count() > 0)); + ui->m_lpPlaceList->setCurrentIndex(index); + ui->m_lpPlaceDetails->setCurrentIndex(index); - m_lpMainWindow->somethingChanged(); -} - -void cSceneWindow::onAddPlaceToList() -{ ui->m_lpPlaceRemove->setEnabled((ui->m_lpPlaceList->count() > 0)); ui->m_lpPlaceShowDetails->setEnabled((ui->m_lpPlaceList->count() > 0)); } -void cSceneWindow::onRemovePlaceFromList() +void cSceneWindow::fillObjectList(cObject* lpObjectNew) { - ui->m_lpPlaceRemove->setEnabled((ui->m_lpPlaceList->count() > 0)); - ui->m_lpPlaceShowDetails->setEnabled((ui->m_lpPlaceList->count() > 0)); -} + QList objectList = m_lpScene->objectList(); + + ui->m_lpObjectList->clear(); + + for(int x = ui->m_lpObjectDetails->count()-1;x >= 0;x--) + ui->m_lpObjectDetails->removeWidget(ui->m_lpObjectDetails->widget(x)); + + qint16 index = 0; + + for(int x = 0;x < objectList.count();x++) + { + cObjectDescription* lpObjectDescription = objectList[x]; + cObject* lpObject = lpObjectDescription->object(); + + ui->m_lpObjectList->addItem(lpObject->name(), QVariant::fromValue(lpObjectDescription)); + cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpObjectDetails); + lpTextEdit->setDocument(lpObjectDescription->description()); + ui->m_lpObjectDetails->addWidget(lpTextEdit); + + connect(lpTextEdit, &cTextEdit::gotFocus, m_lpMainWindow, &cMainWindow::onTextEditGotFocus); + connect(lpTextEdit, &cTextEdit::lostFocus, m_lpMainWindow, &cMainWindow::onTextEditLostFocus); + + connect(lpTextEdit, &cTextEdit::textChanged, this, &cSceneWindow::onObjectDescriptionChanged); + + if(lpObject == lpObjectNew) + index = x; + } + ui->m_lpObjectList->setCurrentIndex(index); + ui->m_lpObjectDetails->setCurrentIndex(index); -void cSceneWindow::onAddObjectToList() -{ - ui->m_lpObjectRemove->setEnabled((ui->m_lpObjectList->count() > 0)); - ui->m_lpObjectShowDetails->setEnabled((ui->m_lpObjectList->count() > 0)); -} - -void cSceneWindow::onRemoveObjectFromList() -{ ui->m_lpObjectRemove->setEnabled((ui->m_lpObjectList->count() > 0)); ui->m_lpObjectShowDetails->setEnabled((ui->m_lpObjectList->count() > 0)); } diff --git a/cscenewindow.h b/cscenewindow.h index a571df3..236fb3c 100644 --- a/cscenewindow.h +++ b/cscenewindow.h @@ -56,6 +56,29 @@ public: */ cScene* scene(); +private: + /*! + \brief + + \fn fillCharacterList + \param bSelectFirst + */ + void fillCharacterList(cCharacter* lpCharacterNew = 0); + /*! + \brief + + \fn fillPlaceList + \param bSelectFirst + */ + void fillPlaceList(cPlace* lpPlaceNew = 0); + /*! + \brief + + \fn fillObjectList + \param bSelectFirst + */ + void fillObjectList(cObject* lpObjectNew = 0); + private slots: /*! \brief diff --git a/storyWriter.pro b/storyWriter.pro index 132353d..eb77b60 100644 --- a/storyWriter.pro +++ b/storyWriter.pro @@ -76,7 +76,9 @@ SOURCES += \ cdatetimeedit.cpp \ cpropertieswindow.cpp \ ccharacterselectdialog.cpp \ - csplashscreen.cpp + csplashscreen.cpp \ + cplaceselectdialog.cpp \ + cobjectselectdialog.cpp HEADERS += \ cmainwindow.h \ @@ -114,7 +116,9 @@ HEADERS += \ cdatetimeedit.h \ cpropertieswindow.h \ ccharacterselectdialog.h \ - csplashscreen.h + csplashscreen.h \ + cplaceselectdialog.h \ + cobjectselectdialog.h FORMS += \ cmainwindow.ui \ @@ -127,7 +131,9 @@ FORMS += \ cplacewindow.ui \ crecherchewindow.ui \ cpropertieswindow.ui \ - ccharacterselectdialog.ui + ccharacterselectdialog.ui \ + cplaceselectdialog.ui \ + cobjectselectdialog.ui DISTFILES += \ Doxyfile \