add, edit and remove persons
This commit is contained in:
@@ -26,7 +26,7 @@ bool cFlag::toDB()
|
|||||||
|
|
||||||
if(m_iID != -1)
|
if(m_iID != -1)
|
||||||
{
|
{
|
||||||
query.prepare("SELECT id FROM flags WHERE id=:id;");
|
query.prepare("SELECT id FROM flag WHERE id=:id;");
|
||||||
query.bindValue(":id", m_iID);
|
query.bindValue(":id", m_iID);
|
||||||
if(!query.exec())
|
if(!query.exec())
|
||||||
{
|
{
|
||||||
@@ -35,12 +35,12 @@ bool cFlag::toDB()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!query.next())
|
if(!query.next())
|
||||||
query.prepare("INSERT INTO flags (name) VALUES (:name);");
|
query.prepare("INSERT INTO flag (name) VALUES (:name);");
|
||||||
else
|
else
|
||||||
query.prepare("UPDATE flags SET name=:name WHERE id=:id;");
|
query.prepare("UPDATE flag SET name=:name WHERE id=:id;");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
query.prepare("INSERT INTO flags (name) VALUES (:name);");
|
query.prepare("INSERT INTO flag (name) VALUES (:name);");
|
||||||
|
|
||||||
|
|
||||||
query.bindValue(":id", m_iID);
|
query.bindValue(":id", m_iID);
|
||||||
@@ -54,7 +54,7 @@ bool cFlag::toDB()
|
|||||||
|
|
||||||
if(m_iID == -1)
|
if(m_iID == -1)
|
||||||
{
|
{
|
||||||
query.prepare("SELECT id FROM flags WHERE _rowid_=(SELECT MAX(_rowid_) FROM flags);");
|
query.prepare("SELECT id FROM flag WHERE _rowid_=(SELECT MAX(_rowid_) FROM flag);");
|
||||||
if(!query.exec())
|
if(!query.exec())
|
||||||
{
|
{
|
||||||
myDebug << query.lastError().text();
|
myDebug << query.lastError().text();
|
||||||
@@ -129,7 +129,7 @@ bool cFlagList::load(cSplashScreen *lpSplashScreen, QProgressBar *lpProgressBar)
|
|||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
|
||||||
query.prepare("SELECT COUNT(1) cnt FROM flags;");
|
query.prepare("SELECT COUNT(1) cnt FROM flag;");
|
||||||
|
|
||||||
if(!query.exec())
|
if(!query.exec())
|
||||||
{
|
{
|
||||||
@@ -147,7 +147,7 @@ bool cFlagList::load(cSplashScreen *lpSplashScreen, QProgressBar *lpProgressBar)
|
|||||||
|
|
||||||
query.prepare("SELECT id, "
|
query.prepare("SELECT id, "
|
||||||
" name "
|
" name "
|
||||||
"FROM flags "
|
"FROM flag "
|
||||||
"ORDER BY UPPER(name);");
|
"ORDER BY UPPER(name);");
|
||||||
|
|
||||||
if(!query.exec())
|
if(!query.exec())
|
||||||
@@ -164,8 +164,8 @@ bool cFlagList::load(cSplashScreen *lpSplashScreen, QProgressBar *lpProgressBar)
|
|||||||
|
|
||||||
while(query.next())
|
while(query.next())
|
||||||
{
|
{
|
||||||
cFlag* lpFlags = add(query.value("id").toInt(), true);
|
cFlag* lpFlag = add(query.value("id").toInt(), true);
|
||||||
lpFlags->setName(query.value("name").toString());
|
lpFlag->setName(query.value("name").toString());
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
if(!(count % step))
|
if(!(count % step))
|
||||||
@@ -194,18 +194,18 @@ cFlag* cFlagList::add(qint32 iID, bool bNoCheck)
|
|||||||
return(lpNew);
|
return(lpNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cFlagList::add(cFlag* lpFlags, bool bNoCheck)
|
bool cFlagList::add(cFlag* lpFlag, bool bNoCheck)
|
||||||
{
|
{
|
||||||
if(bNoCheck)
|
if(bNoCheck)
|
||||||
{
|
{
|
||||||
append(lpFlags);
|
append(lpFlag);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(contains(lpFlags))
|
if(contains(lpFlag))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
append(lpFlags);
|
append(lpFlag);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,11 +219,11 @@ cFlag* cFlagList::find(qint32 iID)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
cFlag* cFlagList::find(cFlag* lpFlags)
|
cFlag* cFlagList::find(cFlag* lpFlag)
|
||||||
{
|
{
|
||||||
for(cFlagList::iterator i = begin(); i != end(); i++)
|
for(cFlagList::iterator i = begin(); i != end(); i++)
|
||||||
{
|
{
|
||||||
if(*lpFlags == (**i))
|
if(*lpFlag == (**i))
|
||||||
return(*i);
|
return(*i);
|
||||||
}
|
}
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
@@ -231,12 +231,12 @@ cFlag* cFlagList::find(cFlag* lpFlags)
|
|||||||
|
|
||||||
QStringList cFlagList::flagList()
|
QStringList cFlagList::flagList()
|
||||||
{
|
{
|
||||||
QStringList szFlagsList;
|
QStringList szFlagList;
|
||||||
|
|
||||||
for(cFlagList::iterator i = begin(); i != end();i++)
|
for(cFlagList::iterator i = begin(); i != end();i++)
|
||||||
szFlagsList.append((*i)->name());
|
szFlagList.append((*i)->name());
|
||||||
|
|
||||||
szFlagsList.removeDuplicates();
|
szFlagList.removeDuplicates();
|
||||||
szFlagsList.sort(Qt::CaseInsensitive);
|
szFlagList.sort(Qt::CaseInsensitive);
|
||||||
return(szFlagsList);
|
return(szFlagList);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ public:
|
|||||||
\param bNoCheck
|
\param bNoCheck
|
||||||
\return bool
|
\return bool
|
||||||
*/
|
*/
|
||||||
bool add(cFlag* lpFlags, bool bNoCheck = false);
|
bool add(cFlag* lpFlag, bool bNoCheck = false);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief
|
\brief
|
||||||
@@ -180,7 +180,7 @@ public:
|
|||||||
\param iID
|
\param iID
|
||||||
\return cFlag
|
\return cFlag
|
||||||
*/
|
*/
|
||||||
cFlag* find(cFlag* lpFlags);
|
cFlag* find(cFlag* lpFlag);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief
|
\brief
|
||||||
|
|||||||
@@ -12,6 +12,10 @@
|
|||||||
#include "cdatetimepicker.h"
|
#include "cdatetimepicker.h"
|
||||||
#include "ccombopicker.h"
|
#include "ccombopicker.h"
|
||||||
|
|
||||||
|
#include "cimage.h"
|
||||||
|
|
||||||
|
#include "cimageviewer.h"
|
||||||
|
|
||||||
#include "ui_cmainwindow.h"
|
#include "ui_cmainwindow.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -114,6 +118,8 @@ void cMainWindow::createActions()
|
|||||||
connect(ui->m_lpFolderView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cMainWindow::onFolderSelected);
|
connect(ui->m_lpFolderView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cMainWindow::onFolderSelected);
|
||||||
|
|
||||||
connect(ui->m_lpThumbnailView, &QListView::customContextMenuRequested, this, &cMainWindow::onThumbnailViewContextMenu);
|
connect(ui->m_lpThumbnailView, &QListView::customContextMenuRequested, this, &cMainWindow::onThumbnailViewContextMenu);
|
||||||
|
|
||||||
|
connect(ui->m_lpThumbnailView, &QListView::doubleClicked, this, &cMainWindow::onThumbnailDoubleClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cMainWindow::createContextActions()
|
void cMainWindow::createContextActions()
|
||||||
@@ -360,6 +366,28 @@ void cMainWindow::onThumbnailSelected(const QItemSelection& /*selection*/, const
|
|||||||
ui->m_lpToolBoxPerson->setPicture(pictureList);
|
ui->m_lpToolBoxPerson->setPicture(pictureList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cMainWindow::onThumbnailDoubleClicked(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
if(!index.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
cPicture* lpPicture = m_lpThumbnailSortFilterProxyModel->data(index, Qt::UserRole+1).value<cPicture*>();
|
||||||
|
QFile file(m_pictureLibrary.rootPath() + "/" + lpPicture->filePath() + "/" + lpPicture->fileName());
|
||||||
|
|
||||||
|
if(!file.exists())
|
||||||
|
return;
|
||||||
|
|
||||||
|
cImageViewer imageViewer(this);
|
||||||
|
// imageViewer.showMaximized();
|
||||||
|
|
||||||
|
cImage image(file.fileName());
|
||||||
|
if(image.isNull())
|
||||||
|
return;
|
||||||
|
|
||||||
|
imageViewer.setImage(&image);
|
||||||
|
imageViewer.exec();
|
||||||
|
}
|
||||||
|
|
||||||
void cMainWindow::onFolderSelected(const QItemSelection& /*selection*/, const QItemSelection& /*previous*/)
|
void cMainWindow::onFolderSelected(const QItemSelection& /*selection*/, const QItemSelection& /*previous*/)
|
||||||
{
|
{
|
||||||
if(m_bLoading)
|
if(m_bLoading)
|
||||||
|
|||||||
@@ -182,6 +182,14 @@ private slots:
|
|||||||
\param previous
|
\param previous
|
||||||
*/
|
*/
|
||||||
void onThumbnailSelected(const QItemSelection& selection, const QItemSelection& previous);
|
void onThumbnailSelected(const QItemSelection& selection, const QItemSelection& previous);
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn onThumbnailDoubleClicked
|
||||||
|
\param index
|
||||||
|
*/
|
||||||
|
void onThumbnailDoubleClicked(const QModelIndex& index);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief
|
\brief
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -132,7 +132,7 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="label">
|
<attribute name="label">
|
||||||
<string>People</string>
|
<string>Person</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="m_lpToolBoxFlags">
|
<widget class="QWidget" name="m_lpToolBoxFlags">
|
||||||
|
|||||||
+41
-2
@@ -24,6 +24,14 @@ bool cPerson::toDB()
|
|||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
|
||||||
|
query.prepare("SELECT id FROM person WHERE UPPER(name)=UPPER(:name);");
|
||||||
|
query.bindValue(":name", m_szName);
|
||||||
|
if(query.exec())
|
||||||
|
{
|
||||||
|
if(query.next())
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
if(m_iID != -1)
|
if(m_iID != -1)
|
||||||
{
|
{
|
||||||
query.prepare("SELECT id FROM person WHERE id=:id;");
|
query.prepare("SELECT id FROM person WHERE id=:id;");
|
||||||
@@ -219,16 +227,47 @@ cPerson* cPersonList::find(qint32 iID)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
cPerson* cPersonList::find(cPerson* lpFlags)
|
cPerson* cPersonList::find(cPerson* lpPerson)
|
||||||
{
|
{
|
||||||
for(cPersonList::iterator i = begin(); i != end(); i++)
|
for(cPersonList::iterator i = begin(); i != end(); i++)
|
||||||
{
|
{
|
||||||
if(*lpFlags == (**i))
|
if(*lpPerson == (**i))
|
||||||
return(*i);
|
return(*i);
|
||||||
}
|
}
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cPersonList::remove(cPerson* lpPerson)
|
||||||
|
{
|
||||||
|
if(!find(lpPerson))
|
||||||
|
return(true);
|
||||||
|
|
||||||
|
QSqlQuery query;
|
||||||
|
|
||||||
|
query.prepare("SELECT COUNT(1) cnt FROM picture_person WHERE personID=:id;");
|
||||||
|
query.bindValue(":id", lpPerson->id());
|
||||||
|
|
||||||
|
if(!query.exec())
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!query.next())
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(query.value("cnt").toInt() != 0)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
query.prepare("DELETE FROM person WHERE id=:id;");
|
||||||
|
query.bindValue(":id", lpPerson->id());
|
||||||
|
|
||||||
|
if(!query.exec())
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
this->removeOne(lpPerson);
|
||||||
|
delete lpPerson;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList cPersonList::personList()
|
QStringList cPersonList::personList()
|
||||||
{
|
{
|
||||||
QStringList szPersonList;
|
QStringList szPersonList;
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ public:
|
|||||||
\param bNoCheck
|
\param bNoCheck
|
||||||
\return bool
|
\return bool
|
||||||
*/
|
*/
|
||||||
bool add(cPerson* lpPersons, bool bNoCheck = false);
|
bool add(cPerson* lpPerson, bool bNoCheck = false);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief
|
\brief
|
||||||
@@ -180,7 +180,15 @@ public:
|
|||||||
\param iID
|
\param iID
|
||||||
\return cPerson
|
\return cPerson
|
||||||
*/
|
*/
|
||||||
cPerson* find(cPerson* lpPersons);
|
cPerson* find(cPerson* lpPerson);
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn remove
|
||||||
|
\param lpPerson
|
||||||
|
\return bool
|
||||||
|
*/
|
||||||
|
bool remove(cPerson* lpPerson);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief
|
\brief
|
||||||
|
|||||||
+180
-4
@@ -1,23 +1,62 @@
|
|||||||
#include "ctoolboxperson.h"
|
#include "ctoolboxperson.h"
|
||||||
#include "ui_ctoolboxperson.h"
|
#include "ui_ctoolboxperson.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
|
#include <QInputDialog>
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
|
||||||
cToolBoxPerson::cToolBoxPerson(QWidget *parent) :
|
cToolBoxPerson::cToolBoxPerson(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::cToolBoxPerson),
|
ui(new Ui::cToolBoxPerson),
|
||||||
m_bLoading(true)
|
m_bLoading(true),
|
||||||
|
m_bEditing(false)
|
||||||
|
{
|
||||||
|
initUI();
|
||||||
|
createActions();
|
||||||
|
}
|
||||||
|
|
||||||
|
cToolBoxPerson::~cToolBoxPerson()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cToolBoxPerson::initUI()
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
m_lpPersonListModel = new QStandardItemModel;
|
m_lpPersonListModel = new QStandardItemModel;
|
||||||
ui->m_lpPersonList->setModel(m_lpPersonListModel);
|
ui->m_lpPersonList->setModel(m_lpPersonListModel);
|
||||||
|
|
||||||
connect(m_lpPersonListModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), SLOT(personChanged(QModelIndex, QModelIndex, QVector<int>)));
|
ui->m_lpEdit->setEnabled(false);
|
||||||
|
ui->m_lpDelete->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
cToolBoxPerson::~cToolBoxPerson()
|
void cToolBoxPerson::createActions()
|
||||||
{
|
{
|
||||||
delete ui;
|
m_lpPersonAddAction = new QAction(tr("add person"), this);
|
||||||
|
m_lpPersonAddAction->setStatusTip(tr("add a new person"));
|
||||||
|
connect(m_lpPersonAddAction, &QAction::triggered, this, &cToolBoxPerson::onPersonAdd);
|
||||||
|
connect(ui->m_lpAdd, &QPushButton::clicked, this, &cToolBoxPerson::onPersonAdd);
|
||||||
|
|
||||||
|
m_lpPersonEditAction = new QAction(tr("edit person"), this);
|
||||||
|
m_lpPersonEditAction->setStatusTip(tr("edit this person"));
|
||||||
|
connect(m_lpPersonEditAction, &QAction::triggered, this, &cToolBoxPerson::onPersonEdit);
|
||||||
|
connect(ui->m_lpEdit, &QPushButton::clicked, this, &cToolBoxPerson::onPersonEdit);
|
||||||
|
|
||||||
|
m_lpPersonDeleteAction = new QAction(tr("delete person"), this);
|
||||||
|
m_lpPersonDeleteAction->setStatusTip(tr("delete this person"));
|
||||||
|
connect(m_lpPersonDeleteAction, &QAction::triggered, this, &cToolBoxPerson::onPersonDelete);
|
||||||
|
connect(ui->m_lpDelete, &QPushButton::clicked, this, &cToolBoxPerson::onPersonDelete);
|
||||||
|
|
||||||
|
connect(ui->m_lpPersonList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cToolBoxPerson::onPersonSelected);
|
||||||
|
|
||||||
|
connect(m_lpPersonListModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), SLOT(personChanged(QModelIndex, QModelIndex, QVector<int>)));
|
||||||
|
connect(ui->m_lpPersonList, &QTreeView::customContextMenuRequested, this, &cToolBoxPerson::onPersonViewContextMenu);
|
||||||
|
connect(m_lpPersonListModel, &QStandardItemModel::itemChanged, this, &cToolBoxPerson::onPersonChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cToolBoxPerson::setPersonList(cPersonList* lpPersonList)
|
void cToolBoxPerson::setPersonList(cPersonList* lpPersonList)
|
||||||
@@ -88,6 +127,20 @@ void cToolBoxPerson::setPicture(cPictureList& pictureList)
|
|||||||
m_bLoading = false;
|
m_bLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cToolBoxPerson::onPersonSelected(const QItemSelection& /*selection*/, const QItemSelection& /*previous*/)
|
||||||
|
{
|
||||||
|
if(ui->m_lpPersonList->selectionModel()->selectedIndexes().count() == 1)
|
||||||
|
{
|
||||||
|
ui->m_lpEdit->setEnabled(true);
|
||||||
|
ui->m_lpDelete->setEnabled(true);
|
||||||
|
}
|
||||||
|
else if(ui->m_lpPersonList->selectionModel()->selectedIndexes().count() > 1)
|
||||||
|
{
|
||||||
|
ui->m_lpEdit->setEnabled(false);
|
||||||
|
ui->m_lpDelete->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void cToolBoxPerson::personChanged(const QModelIndex& /*topLeft*/, const QModelIndex& /*bottomright*/, const QVector<int>& /*roles*/)
|
void cToolBoxPerson::personChanged(const QModelIndex& /*topLeft*/, const QModelIndex& /*bottomright*/, const QVector<int>& /*roles*/)
|
||||||
{
|
{
|
||||||
if(!m_pictureList.count())
|
if(!m_pictureList.count())
|
||||||
@@ -119,3 +172,126 @@ void cToolBoxPerson::personChanged(const QModelIndex& /*topLeft*/, const QModelI
|
|||||||
for(cPictureList::iterator i = m_pictureList.begin();i != m_pictureList.end();i++)
|
for(cPictureList::iterator i = m_pictureList.begin();i != m_pictureList.end();i++)
|
||||||
(*i)->toDB();
|
(*i)->toDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cToolBoxPerson::onPersonAdd()
|
||||||
|
{
|
||||||
|
QInputDialog input(this);
|
||||||
|
|
||||||
|
input.setLabelText(tr("name:"));
|
||||||
|
input.setWindowTitle(tr("New Person"));
|
||||||
|
if(input.exec() == QDialog::Rejected)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(input.textValue().isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
cPerson* lpPerson = new cPerson;
|
||||||
|
lpPerson->setName(input.textValue());
|
||||||
|
if(!lpPerson->toDB())
|
||||||
|
{
|
||||||
|
delete lpPerson;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lpPersonList->add(lpPerson);
|
||||||
|
|
||||||
|
m_bLoading = true;
|
||||||
|
|
||||||
|
QStandardItem* lpItem = new QStandardItem(lpPerson->name());
|
||||||
|
lpItem->setData(QVariant::fromValue(lpPerson), Qt::UserRole+1);
|
||||||
|
lpItem->setCheckable(true);
|
||||||
|
m_lpPersonListModel->appendRow(lpItem);
|
||||||
|
m_lpPersonListModel->sort(0);
|
||||||
|
|
||||||
|
m_bLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cToolBoxPerson::onPersonEdit()
|
||||||
|
{
|
||||||
|
if(ui->m_lpPersonList->selectionModel()->selectedIndexes().count() != 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QStandardItem* lpItem = m_lpPersonListModel->itemFromIndex(ui->m_lpPersonList->selectionModel()->selectedIndexes()[0]);
|
||||||
|
if(!lpItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cPerson* lpPerson = lpItem->data(Qt::UserRole+1).value<cPerson*>();
|
||||||
|
if(!lpPerson)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QInputDialog input(this);
|
||||||
|
|
||||||
|
input.setLabelText(tr("name:"));
|
||||||
|
input.setWindowTitle(tr("Edit Person"));
|
||||||
|
input.setTextValue(lpPerson->name());
|
||||||
|
|
||||||
|
if(input.exec() == QDialog::Rejected)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(input.textValue().isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
lpItem->setText(input.textValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
void cToolBoxPerson::onPersonDelete()
|
||||||
|
{
|
||||||
|
for(int x = ui->m_lpPersonList->selectionModel()->selectedIndexes().count()-1;x >= 0; x--)
|
||||||
|
{
|
||||||
|
QModelIndex index = ui->m_lpPersonList->selectionModel()->selectedIndexes()[x];
|
||||||
|
QStandardItem* lpItem = m_lpPersonListModel->itemFromIndex(index);
|
||||||
|
if(lpItem)
|
||||||
|
{
|
||||||
|
cPerson* lpPerson = lpItem->data(Qt::UserRole+1).value<cPerson*>();
|
||||||
|
if(lpPerson)
|
||||||
|
{
|
||||||
|
if(QMessageBox::question(this, tr("Delete Person"), QString(tr("Are you sure you want to delete %1?")).arg(lpPerson->name())) == QMessageBox::Yes)
|
||||||
|
{
|
||||||
|
if(!m_lpPersonList->remove(lpPerson))
|
||||||
|
QMessageBox::critical(this, tr("Delete Person"), QString(tr("%1 is in use and can't be deleted!")).arg(lpPerson->name()));
|
||||||
|
else
|
||||||
|
m_lpPersonListModel->removeRow(index.row());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void cToolBoxPerson::onPersonViewContextMenu(const QPoint& pos)
|
||||||
|
{
|
||||||
|
QMenu menu(this);
|
||||||
|
|
||||||
|
menu.addAction(m_lpPersonAddAction);
|
||||||
|
|
||||||
|
if(ui->m_lpPersonList->selectionModel()->selectedIndexes().count() == 1)
|
||||||
|
menu.addAction(m_lpPersonEditAction);
|
||||||
|
if(ui->m_lpPersonList->selectionModel()->selectedIndexes().count() >= 1)
|
||||||
|
menu.addAction(m_lpPersonDeleteAction);
|
||||||
|
|
||||||
|
menu.exec(ui->m_lpPersonList->mapToGlobal(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
void cToolBoxPerson::onPersonChanged(QStandardItem* lpItem)
|
||||||
|
{
|
||||||
|
if(m_bEditing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cPerson* lpPerson = lpItem->data(Qt::UserRole+1).value<cPerson*>();
|
||||||
|
if(!lpPerson)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(lpItem->text() == lpPerson->name())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString szOldName = lpPerson->name();
|
||||||
|
lpPerson->setName(lpItem->text());
|
||||||
|
if(!lpPerson->toDB())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("ERROR"), QString(tr("%1 already exists.").arg(lpItem->text())));
|
||||||
|
m_bEditing = true;
|
||||||
|
lpItem->setText(szOldName);
|
||||||
|
lpPerson->setName(szOldName);
|
||||||
|
m_bEditing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
|
#include <QItemSelection>
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@@ -64,7 +65,34 @@ private:
|
|||||||
cPictureList m_pictureList; /*!< TODO: describe */
|
cPictureList m_pictureList; /*!< TODO: describe */
|
||||||
bool m_bLoading; /*!< TODO: describe */
|
bool m_bLoading; /*!< TODO: describe */
|
||||||
|
|
||||||
|
QAction* m_lpPersonAddAction; /*!< TODO: describe */
|
||||||
|
QAction* m_lpPersonEditAction; /*!< TODO: describe */
|
||||||
|
QAction* m_lpPersonDeleteAction; /*!< TODO: describe */
|
||||||
|
|
||||||
|
bool m_bEditing; /*!< TODO: describe */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn initUI
|
||||||
|
*/
|
||||||
|
void initUI();
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn createActions
|
||||||
|
*/
|
||||||
|
void createActions();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn onPersonSelected
|
||||||
|
\param selection
|
||||||
|
\param previous
|
||||||
|
*/
|
||||||
|
void onPersonSelected(const QItemSelection& selection, const QItemSelection& previous);
|
||||||
/*!
|
/*!
|
||||||
\brief
|
\brief
|
||||||
|
|
||||||
@@ -74,6 +102,40 @@ private slots:
|
|||||||
\param roles
|
\param roles
|
||||||
*/
|
*/
|
||||||
void personChanged(const QModelIndex& topLeft, const QModelIndex& bottomright, const QVector<int>& roles);
|
void personChanged(const QModelIndex& topLeft, const QModelIndex& bottomright, const QVector<int>& roles);
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn onPersonAdd
|
||||||
|
*/
|
||||||
|
void onPersonAdd();
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn onPersonEdit
|
||||||
|
*/
|
||||||
|
void onPersonEdit();
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn onPersonDelete
|
||||||
|
*/
|
||||||
|
void onPersonDelete();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn onPersonViewContextMenu
|
||||||
|
\param pos
|
||||||
|
*/
|
||||||
|
void onPersonViewContextMenu(const QPoint& pos);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
|
||||||
|
\fn onPersonChanged
|
||||||
|
\param lpItem
|
||||||
|
*/
|
||||||
|
void onPersonChanged(QStandardItem* lpItem);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CTOOLBOXPERSON_H
|
#endif // CTOOLBOXPERSON_H
|
||||||
|
|||||||
+7
-1
@@ -18,12 +18,18 @@
|
|||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="m_lpPersonList">
|
<widget class="QTreeView" name="m_lpPersonList">
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::CustomContextMenu</enum>
|
||||||
|
</property>
|
||||||
<property name="editTriggers">
|
<property name="editTriggers">
|
||||||
<set>QAbstractItemView::NoEditTriggers</set>
|
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
|
</property>
|
||||||
<property name="rootIsDecorated">
|
<property name="rootIsDecorated">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
+8
-3
@@ -71,7 +71,9 @@ SOURCES += \
|
|||||||
ccombopicker.cpp \
|
ccombopicker.cpp \
|
||||||
cflag.cpp \
|
cflag.cpp \
|
||||||
cperson.cpp \
|
cperson.cpp \
|
||||||
ctoolboxperson.cpp
|
ctoolboxperson.cpp \
|
||||||
|
clabel.cpp \
|
||||||
|
cimageviewer.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
cmainwindow.h \
|
cmainwindow.h \
|
||||||
@@ -91,7 +93,9 @@ HEADERS += \
|
|||||||
ccombopicker.h \
|
ccombopicker.h \
|
||||||
cflag.h \
|
cflag.h \
|
||||||
cperson.h \
|
cperson.h \
|
||||||
ctoolboxperson.h
|
ctoolboxperson.h \
|
||||||
|
clabel.h \
|
||||||
|
cimageviewer.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
cmainwindow.ui \
|
cmainwindow.ui \
|
||||||
@@ -100,7 +104,8 @@ FORMS += \
|
|||||||
cdatetimepicker.ui \
|
cdatetimepicker.ui \
|
||||||
cdatepicker.ui \
|
cdatepicker.ui \
|
||||||
ccombopicker.ui \
|
ccombopicker.ui \
|
||||||
ctoolboxperson.ui
|
ctoolboxperson.ui \
|
||||||
|
cimageviewer.ui
|
||||||
|
|
||||||
# Default rules for deployment.
|
# Default rules for deployment.
|
||||||
qnx: target.path = /tmp/$${TARGET}/bin
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
|
|||||||
Reference in New Issue
Block a user