diff options
author | Arno <am@disconnect.de> | 2012-09-30 04:34:22 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2012-09-30 04:34:22 +0200 |
commit | 887c2cd696c54af0cd6fdd54950d006626afeacc (patch) | |
tree | 2ad296208a7d8e44ac249612dfcd09919e7ba07d /pictureswidget.cpp | |
parent | 5addc8a8ec89c1e354949bcf5c3152fea4fe44b9 (diff) | |
download | SheMov-887c2cd696c54af0cd6fdd54950d006626afeacc.tar.gz SheMov-887c2cd696c54af0cd6fdd54950d006626afeacc.tar.bz2 SheMov-887c2cd696c54af0cd6fdd54950d006626afeacc.zip |
Foremost a fix for SmTreeModel
Not working again, but I eventually have to commit the changes. Fixes to
SmTreeModel:
* Fix SmTreeModel::index(). The previous comment was quite valid. I'm
surprised that it worked at all. I have no clue why to return an invalid
QModelIndex if the column isn't 0. Now an index with any valid column
number can be created.
* Fix SmTreeModel::parent(). Again, why shouldn't we create a parent
index with a column other than 0? No idea...
* Fix SmTreeModel::headerData(). Add some sanity checks.
* Fix SmTreeModel::findRecursive(). Well, what is there to say. It never
worked for models with a depth > 1, but obviously it didn't really
matter until now. To make it work I had to change SmTreeItem as well.
SmTreeItem::next() returns the next valid parent/sibling, or 0 if there
isn't one.
There may be some fallout from these changes, but they're yet to be
seen.
Changes to PictureView:
* fix selecting an item according to the new datasbase layout
* same goes for editing items. If an update actually works has to be
checked.
Overall, it's an intermediate commit that should have been a sane series
of commits. Can't be changed now...
Diffstat (limited to 'pictureswidget.cpp')
-rw-r--r-- | pictureswidget.cpp | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/pictureswidget.cpp b/pictureswidget.cpp index d5caa76..bc4b143 100644 --- a/pictureswidget.cpp +++ b/pictureswidget.cpp @@ -72,8 +72,13 @@ void PicturesWidget::readSettings(){ } void PicturesWidget::editMappings(){ - QList<int> currentMappings = mPictureView->fileMappings(); - mEditDialog->editWidget()->setMappings(currentMappings); + QModelIndexList selectedFids = mPictureView->selectionModel()->selectedRows(PicFilesModel::Id); + QList<int> fileIds; + foreach(QModelIndex idx, selectedFids){ + fileIds << idx.data().toInt(); + } + QList<MappingData> mappings = mPictureView->filesModel()->mappingDataFromFiles(fileIds); + mEditDialog->editWidget()->setMappings(mappings); int retval = mEditDialog->exec(); if(retval == QDialog::Accepted){ QList<int> selMappings = mEditDialog->editWidget()->mappingIds(); @@ -272,12 +277,14 @@ PicFilesModel::PicFilesModel(const QStringList &headers, QObject *parent) : SmTr //setup database mDb = QSqlDatabase::database("treedb"); mPopulateQS = QString("SELECT DISTINCT(pics.ipicsid), pics.tfilename, pics.isize, pics.tformat, pics.dtadded, pics.cmd5sum FROM pics, pics_mappings2 WHERE pics_mappings2.imappings_parents_id IN (%1) AND pics_mappings2.ipics_id = pics.ipicsid ORDER BY pics.tfilename"); + mMappingsQS = QString("SELECT DISTINCT(pics_mappings2.imappings_parents_id) FROM pics_mappings2, pics WHERE pics_mappings2.ipics_id IN (%1)"); mDeleteFileQ = new QSqlQuery(mDb); mDeleteFileQ->prepare("DELETE FROM pics WHERE ipicsid = :id"); mDeleteMappingsQ = new QSqlQuery(mDb); - mDeleteMappingsQ->prepare("DELETE FROM pics_mappings WHERE ipics_id = :id"); + mDeleteMappingsQ->prepare("DELETE FROM pics_mappings2 WHERE ipics_id = :id"); mAddMappingsQ = new QSqlQuery(mDb); - mAddMappingsQ->prepare("INSERT INTO pics_mappings(ipics_id, imapping_id) VALUES(:pid, :id)"); + mAddMappingsQ->prepare("INSERT INTO pics_mappings2(ipics_id, imapping_id) VALUES(:pid, :id)"); + } PicFilesModel::~PicFilesModel(){ @@ -399,6 +406,40 @@ bool PicFilesModel::changeMappings(const QList<int> &fileIds, const QList<int> & return false; } +QList<MappingData> PicFilesModel::mappingDataFromFiles(const QList<int> fileIds) const{ + QList<int> parentIds = mappingPIdsFromFiles(fileIds); + if(parentIds.isEmpty()){ + return QList<MappingData>(); + } + QList<MappingData> retval; + foreach(int pId, parentIds){ + QModelIndex curIdx = mMappingTreeModel->findRecursive(pId, MappingTreeModel::MapParentId, mMappingTreeModel->rootIndex()); + MappingData curData; + curData.id = curIdx.data(MappingTreeModel::IdRole).toInt(); + curData.name = curIdx.data(MappingTreeModel::NameRole).toString(); + curData.path = mMappingTreeModel->path(curIdx); + retval << curData; + } + return retval; +} + +QList<int> PicFilesModel::mappingPIdsFromFiles(QList<int> fileIds) const{ + if(fileIds.isEmpty()){ + return QList<int>(); + } + QStringList idList; + foreach(int id, fileIds){ + idList << QString::number(id); + } + QString query = mMappingsQS.arg(idList.join(",")); + QSqlQuery q(query, mDb); + QList<int> retval; + while(q.next()){ + retval << q.value(0).toInt(); + } + return retval; +} + void PicFilesModel::populate(){ SmTreeItem *root = new SmTreeItem(NumFields); QStringList idList; |