Added function to delete recherches
This commit is contained in:
+111
@@ -1805,6 +1805,43 @@ void cMainWindow::onEditPlace()
|
||||
|
||||
void cMainWindow::onDeletePlace()
|
||||
{
|
||||
QStandardItem* lpItem = m_lpPlaceModel->itemFromIndex(ui->m_lpPlaceList->currentIndex());
|
||||
if(!lpItem)
|
||||
return;
|
||||
|
||||
cPlace* lpPlace = qvariant_cast<cPlace*>(lpItem->data());
|
||||
|
||||
if(!lpPlace)
|
||||
return;
|
||||
|
||||
if(m_lpStoryBook->placeInUse(lpPlace))
|
||||
{
|
||||
QMessageBox::critical(this, "Delete Place", tr("This place is still in use.\nPlease delete the usage before deleting the place."));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(QMessageBox::question(this, "Delete Place", tr("Are you sure you want to delete this place:<br>") + "<b>" + lpPlace->name() + "</b>?") != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
lpPlace->setDeleted(true);
|
||||
m_lpStoryBook->fillPlaceList(ui->m_lpPlaceList);
|
||||
m_bSomethingChanged = true;
|
||||
updateWindowTitle();
|
||||
|
||||
for(int x = 0;x < ui->m_lpMainTab->count();x++)
|
||||
{
|
||||
cWidget* lpWidget = (cWidget*)ui->m_lpMainTab->widget(x);
|
||||
if(lpWidget->type() == cWidget::TYPE_place)
|
||||
{
|
||||
cPlaceWindow* lpPlaceWindow = (cPlaceWindow*)lpWidget->widget();
|
||||
if(lpPlaceWindow->place() == lpPlace)
|
||||
{
|
||||
onMainTabTabCloseRequested(x);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cMainWindow::onAddObject()
|
||||
@@ -1857,6 +1894,43 @@ void cMainWindow::onEditObject()
|
||||
|
||||
void cMainWindow::onDeleteObject()
|
||||
{
|
||||
QStandardItem* lpItem = m_lpObjectModel->itemFromIndex(ui->m_lpObjectList->currentIndex());
|
||||
if(!lpItem)
|
||||
return;
|
||||
|
||||
cObject* lpObject = qvariant_cast<cObject*>(lpItem->data());
|
||||
|
||||
if(!lpObject)
|
||||
return;
|
||||
|
||||
if(m_lpStoryBook->objectInUse(lpObject))
|
||||
{
|
||||
QMessageBox::critical(this, "Delete Object", tr("This object is still in use.\nPlease delete the usage before deleting the object."));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(QMessageBox::question(this, "Delete Object", tr("Are you sure you want to delete this object:<br>") + "<b>" + lpObject->name() + "</b>?") != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
lpObject->setDeleted(true);
|
||||
m_lpStoryBook->fillObjectList(ui->m_lpObjectList);
|
||||
m_bSomethingChanged = true;
|
||||
updateWindowTitle();
|
||||
|
||||
for(int x = 0;x < ui->m_lpMainTab->count();x++)
|
||||
{
|
||||
cWidget* lpWidget = (cWidget*)ui->m_lpMainTab->widget(x);
|
||||
if(lpWidget->type() == cWidget::TYPE_object)
|
||||
{
|
||||
cObjectWindow* lpObjectWindow = (cObjectWindow*)lpWidget->widget();
|
||||
if(lpObjectWindow->object() == lpObject)
|
||||
{
|
||||
onMainTabTabCloseRequested(x);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cMainWindow::onAddRecherche()
|
||||
@@ -1909,6 +1983,43 @@ void cMainWindow::onEditRecherche()
|
||||
|
||||
void cMainWindow::onDeleteRecherche()
|
||||
{
|
||||
QStandardItem* lpItem = m_lpRechercheModel->itemFromIndex(ui->m_lpRechercheList->currentIndex());
|
||||
if(!lpItem)
|
||||
return;
|
||||
|
||||
cRecherche* lpRecherche = qvariant_cast<cRecherche*>(lpItem->data());
|
||||
|
||||
if(!lpRecherche)
|
||||
return;
|
||||
|
||||
if(m_lpStoryBook->rechercheInUse(lpRecherche))
|
||||
{
|
||||
QMessageBox::critical(this, "Delete Recherche", tr("This recherche is still in use.\nPlease delete the usage before deleting the recherche."));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(QMessageBox::question(this, "Delete Recherche", tr("Are you sure you want to delete this recherche:<br>") + "<b>" + lpRecherche->name() + "</b>?") != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
lpRecherche->setDeleted(true);
|
||||
m_lpStoryBook->fillRechercheList(ui->m_lpRechercheList);
|
||||
m_bSomethingChanged = true;
|
||||
updateWindowTitle();
|
||||
|
||||
for(int x = 0;x < ui->m_lpMainTab->count();x++)
|
||||
{
|
||||
cWidget* lpWidget = (cWidget*)ui->m_lpMainTab->widget(x);
|
||||
if(lpWidget->type() == cWidget::TYPE_recherche)
|
||||
{
|
||||
cRechercheWindow* lpRechercheWindow = (cRechercheWindow*)lpWidget->widget();
|
||||
if(lpRechercheWindow->recherche() == lpRecherche)
|
||||
{
|
||||
onMainTabTabCloseRequested(x);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString cMainWindow::getProjectLoadName()
|
||||
|
||||
+67
-2
@@ -16,7 +16,8 @@ cRecherche::cRecherche(qint32 iID, QObject *parent) :
|
||||
m_iID(iID),
|
||||
m_szName(""),
|
||||
m_szLink(""),
|
||||
m_lpDescription(0)
|
||||
m_lpDescription(0),
|
||||
m_bDeleted(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -60,6 +61,16 @@ cTextDocument* cRecherche::description()
|
||||
return(m_lpDescription);
|
||||
}
|
||||
|
||||
void cRecherche::setDeleted(bool bDeleted)
|
||||
{
|
||||
m_bDeleted = bDeleted;
|
||||
}
|
||||
|
||||
bool cRecherche::deleted()
|
||||
{
|
||||
return(m_bDeleted);
|
||||
}
|
||||
|
||||
void cRecherche::addImage(cImage* lpImage, cTextDocument* lpDescription)
|
||||
{
|
||||
m_imageList.append(new cImageDescription(lpImage, lpDescription));
|
||||
@@ -147,6 +158,46 @@ QList<cRecherche*> cRechercheList::find(cCharacter* lpCharacter)
|
||||
return(rechercheList);
|
||||
}
|
||||
|
||||
QList<cRecherche*> cRechercheList::find(cPlace* lpPlace)
|
||||
{
|
||||
QList<cRecherche*> rechercheList;
|
||||
|
||||
for(int x = 0;x < count();x++)
|
||||
{
|
||||
QList<cPlaceDescription*> list = at(x)->placeList();
|
||||
|
||||
for(int y = 0;y < list.count();y++)
|
||||
{
|
||||
if(list.at(y)->place() == lpPlace)
|
||||
{
|
||||
rechercheList.append(at(x));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(rechercheList);
|
||||
}
|
||||
|
||||
QList<cRecherche*> cRechercheList::find(cObject* lpObject)
|
||||
{
|
||||
QList<cRecherche*> rechercheList;
|
||||
|
||||
for(int x = 0;x < count();x++)
|
||||
{
|
||||
QList<cObjectDescription*> list = at(x)->objectList();
|
||||
|
||||
for(int y = 0;y < list.count();y++)
|
||||
{
|
||||
if(list.at(y)->object() == lpObject)
|
||||
{
|
||||
rechercheList.append(at(x));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(rechercheList);
|
||||
}
|
||||
|
||||
bool cRechercheList::load(cImageList *lpImageList, cCharacterList *lpCharacterList, cObjectList *lpObjectList, cPlaceList *lpPlaceList)
|
||||
{
|
||||
QSqlQuery query;
|
||||
@@ -247,13 +298,16 @@ bool cRechercheList::save()
|
||||
QSqlQuery queryUpdate;
|
||||
QSqlQuery queryInsert;
|
||||
QSqlQuery querySelect;
|
||||
QSqlQuery queryDelete;
|
||||
|
||||
queryUpdate.prepare("UPDATE recherche SET name=:name, description=:description, link=:link WHERE id=:id;");
|
||||
queryInsert.prepare("INSERT INTO recherche (name, description, link) VALUES (:name, :description, :link);");
|
||||
querySelect.prepare("SELECT id FROM recherche WHERE _rowid_=(SELECT MAX(_rowid_) FROM recherche);");
|
||||
queryDelete.prepare("DELETE FROM recherche WHERE id=:id;");
|
||||
|
||||
QSqlQuery imageDelete;
|
||||
QSqlQuery imageAdd;
|
||||
|
||||
imageDelete.prepare("DELETE FROM rechercheImage WHERE rechercheID=:rechercheID;");
|
||||
imageAdd.prepare("INSERT INTO rechercheImage (rechercheID, imageID, description) VALUES (:rechercheID, :imageID, :description);");
|
||||
|
||||
@@ -276,7 +330,18 @@ bool cRechercheList::save()
|
||||
{
|
||||
cRecherche* lpRecherche = at(x);
|
||||
|
||||
if(lpRecherche->id() != -1)
|
||||
if(lpRecherche->deleted())
|
||||
{
|
||||
queryDelete.bindValue(":id", lpRecherche->id());
|
||||
|
||||
if(!queryDelete.exec())
|
||||
{
|
||||
myDebug << queryDelete.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
this->removeOne(lpRecherche);
|
||||
}
|
||||
else if(lpRecherche->id() != -1)
|
||||
{
|
||||
queryUpdate.bindValue(":id", lpRecherche->id());
|
||||
queryUpdate.bindValue(":name", lpRecherche->name());
|
||||
|
||||
@@ -159,6 +159,21 @@ public:
|
||||
*/
|
||||
QList<cPlaceDescription*> placeList();
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn setDeleted
|
||||
\param bDeleted
|
||||
*/
|
||||
void setDeleted(bool bDeleted);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn deleted
|
||||
\return bool
|
||||
*/
|
||||
bool deleted();
|
||||
|
||||
private:
|
||||
qint32 m_iID; /*!< TODO: describe */
|
||||
QString m_szName; /*!< TODO: describe */
|
||||
@@ -168,6 +183,7 @@ private:
|
||||
QList<cCharacterDescription*> m_characterList; /*!< TODO: describe */
|
||||
QList<cObjectDescription*> m_objectList; /*!< TODO: describe */
|
||||
QList<cPlaceDescription*> m_placeList; /*!< TODO: describe */
|
||||
bool m_bDeleted; /*!< TODO: describe */
|
||||
|
||||
signals:
|
||||
|
||||
@@ -228,6 +244,24 @@ public:
|
||||
\return QList<cCharacter *>
|
||||
*/
|
||||
QList<cRecherche *> find(cCharacter* lpCharacter);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn find
|
||||
\param lpPlace
|
||||
\return QList<cScene *>
|
||||
*/
|
||||
QList<cRecherche *> find(cPlace* lpPlace);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn find
|
||||
\param lpObject
|
||||
\return QList<cScene *>
|
||||
*/
|
||||
QList<cRecherche *> find(cObject* lpObject);
|
||||
};
|
||||
|
||||
#endif // CRECHERCHE_H
|
||||
|
||||
@@ -677,6 +677,33 @@ bool cStoryBook::characterInUse(cCharacter* lpCharacter)
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool cStoryBook::placeInUse(cPlace* lpPlace)
|
||||
{
|
||||
if(m_sceneList.find(lpPlace).count() > 0)
|
||||
return(true);
|
||||
|
||||
if(m_rechercheList.find(lpPlace).count() > 0)
|
||||
return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool cStoryBook::objectInUse(cObject* lpObject)
|
||||
{
|
||||
if(m_sceneList.find(lpObject).count() > 0)
|
||||
return(true);
|
||||
|
||||
if(m_rechercheList.find(lpObject).count() > 0)
|
||||
return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool cStoryBook::rechercheInUse(cRecherche* /*lpRecherche*/)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool cStoryBook::fillOutlineList(QTreeView* lpView)
|
||||
{
|
||||
QMap<qint32, QStandardItem*> part;
|
||||
@@ -854,6 +881,9 @@ bool cStoryBook::fillPlaceList(QTreeView* lpView)
|
||||
cPlace* lpPlace = m_placeList.at(x);
|
||||
QList<QStandardItem*> lpItems;
|
||||
|
||||
if(lpPlace->deleted())
|
||||
continue;
|
||||
|
||||
lpItems.append(new QStandardItem(lpPlace->name()));
|
||||
lpItems.append(new QStandardItem(lpPlace->location()));
|
||||
lpItems.append(new QStandardItem(lpPlace->type()));
|
||||
@@ -892,6 +922,9 @@ bool cStoryBook::fillObjectList(QTreeView* lpView)
|
||||
cObject* lpObject = m_objectList.at(x);
|
||||
QList<QStandardItem*> lpItems;
|
||||
|
||||
if(lpObject->deleted())
|
||||
continue;
|
||||
|
||||
lpItems.append(new QStandardItem(lpObject->name()));
|
||||
lpItems.append(new QStandardItem(lpObject->type()));
|
||||
|
||||
@@ -929,6 +962,9 @@ bool cStoryBook::fillRechercheList(QTreeView* lpView)
|
||||
cRecherche* lpRecherche = m_rechercheList.at(x);
|
||||
QList<QStandardItem*> lpItems;
|
||||
|
||||
if(lpRecherche->deleted())
|
||||
continue;
|
||||
|
||||
lpItems.append(new QStandardItem(lpRecherche->name()));
|
||||
lpItems.append(new QStandardItem(lpRecherche->link()));
|
||||
|
||||
|
||||
@@ -286,6 +286,33 @@ public:
|
||||
*/
|
||||
bool characterInUse(cCharacter* lpCharacter);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn placeInUse
|
||||
\param lpPlace
|
||||
\return bool
|
||||
*/
|
||||
bool placeInUse(cPlace* lpPlace);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn objectInUse
|
||||
\param lpObject
|
||||
\return bool
|
||||
*/
|
||||
bool objectInUse(cObject* lpObject);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn rechercheInUse
|
||||
\param lpRecherche
|
||||
\return bool
|
||||
*/
|
||||
bool rechercheInUse(cRecherche* lpRecherche);
|
||||
|
||||
private:
|
||||
QString m_szProject; /*!< TODO: describe */
|
||||
bool m_bIsOpen; /*!< TODO: describe */
|
||||
|
||||
Reference in New Issue
Block a user