improvements on multiple selected documents handling

preferencesAboutTextFull
Clément Fauconnier 6 years ago
parent 570b575579
commit 5f27f42429
  1. 7
      src/document/UBDocumentContainer.cpp
  2. 161
      src/document/UBDocumentController.cpp
  3. 2
      src/document/UBDocumentController.h

@ -136,10 +136,17 @@ void UBDocumentContainer::deleteThumbPage(int index)
} }
void UBDocumentContainer::updateThumbPage(int index) void UBDocumentContainer::updateThumbPage(int index)
{
if (mDocumentThumbs.size() > index)
{ {
mDocumentThumbs[index] = UBThumbnailAdaptor::get(mCurrentDocument, index); mDocumentThumbs[index] = UBThumbnailAdaptor::get(mCurrentDocument, index);
emit documentPageUpdated(index); emit documentPageUpdated(index);
} }
else
{
qDebug() << "error [updateThumbPage] : index > mDocumentThumbs' size.";
}
}
void UBDocumentContainer::insertThumbPage(int index) void UBDocumentContainer::insertThumbPage(int index)
{ {

@ -1803,36 +1803,18 @@ void UBDocumentController::TreeViewSelectionChanged(const QItemSelection &select
int nbIndexes = selected.indexes().count(); int nbIndexes = selected.indexes().count();
if (nbIndexes) { if (nbIndexes) {
//N/C - NNE - 20140408
QModelIndexList list = mDocumentUI->documentTreeView->selectionModel()->selectedRows(); QModelIndexList list = mDocumentUI->documentTreeView->selectionModel()->selectedRows();
//if multi-selection //if multi-selection
if(list.count() > 1){ if(list.count() > 1)
//selectOnlyTopLevelItems(mDocumentUI->documentTreeView->selectionModel()->selectedRows()); {
for (int i=0; i < list.count() ; i++)
//check if the selection is in the same top-level folder {
QModelIndex sourceIndex1 = mapIndexToSource(list.at(list.count()-1)); QModelIndex newSelectedRow = list.at(i);
QModelIndex sourceIndex2 = mapIndexToSource(list.at(list.count()-2));
UBDocumentTreeModel *model = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel;
bool sameFolder = (model->inTrash(sourceIndex1) && model->inTrash(sourceIndex2));
sameFolder |= (model->inMyDocuments(sourceIndex1) && model->inMyDocuments(sourceIndex2));
if(!sameFolder){
mDocumentUI->documentTreeView->clearSelection();
mDocumentUI->documentTreeView->selectionModel()->select(list.at(list.count()-1), QItemSelectionModel::Select | QItemSelectionModel::Rows);
}
}
//N/C - NNE - 20140408 : END
//if the parent has been already select, don't select its children
QModelIndex newSelectedRow = selected.indexes().first();
QModelIndex parent = newSelectedRow.parent(); QModelIndex parent = newSelectedRow.parent();
bool isParentIsSelected = false; bool isParentIsSelected = false;
while(parent.isValid()){ while(parent.isValid())
{
isParentIsSelected |= (list.indexOf(parent) != -1); isParentIsSelected |= (list.indexOf(parent) != -1);
if(isParentIsSelected) if(isParentIsSelected)
@ -1846,30 +1828,12 @@ void UBDocumentController::TreeViewSelectionChanged(const QItemSelection &select
else else
mDocumentUI->documentTreeView->selectionModel()->select(newSelectedRow, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); mDocumentUI->documentTreeView->selectionModel()->select(newSelectedRow, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
//if he newSelectedRow have children deselect them
/*
UBDocumentTreeModel *model = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel;
if(model->rowCount(newSelectedRow) > 0){
QModelIndexList children;
QModelIndex parent = newSelectedRow;
//init children list
for(int i = 0; i < model->rowCount(parent); i++){
children.push_back(parent.child(i, 0));
}
for(int i = 0; i < children.size(); i++){
//deselect the element
mDocumentUI->documentTreeView->selectionModel()->select(children.at(0), QItemSelectionModel::Deselect);
//add its children if any
for(int k = 0; k < model->rowCount(children.at(i)); k++){
children.push_back(children.at(i).child(k, 0));
} }
} }
else
{
TreeViewSelectionChanged(selected.indexes().at(0), QModelIndex());
} }
*/
} }
} }
@ -2229,19 +2193,98 @@ void UBDocumentController::deleteSelectedItem()
if (!UBApplication::mainWindow->yesNoQuestion(tr("Remove Item"), tr("Are you sure you want to remove the selected item(s) ?"))) if (!UBApplication::mainWindow->yesNoQuestion(tr("Remove Item"), tr("Are you sure you want to remove the selected item(s) ?")))
return; return;
//we iterate in backward because if we iterate in normal order, if (indexes.size() > 1)
//indexes are invalid after the first deletion {
for(int i = indexes.size()-1; i >= 0; i--){ deleteMultipleItems(indexes, docModel);
QModelIndex currentIndex = indexes.at(i); }
DeletionType deletionForSelection = deletionTypeForSelection(mSelectionType, currentIndex, docModel); else
{
deleteSingleItem(indexes.at(0), docModel);
}
updateActions();
}
void UBDocumentController::deleteMultipleItems(QModelIndexList indexes, UBDocumentTreeModel* docModel)
{
DeletionType deletionForSelection = deletionTypeForSelection(mSelectionType, indexes.at(0), docModel);
//N/C - NNE - 20140408 : if parent is selected, continue, because it will be deleted when the parent will be deleted switch (deletionForSelection)
if(mDocumentUI->documentTreeView->selectionModel()->isSelected(currentIndex.parent())){ {
case DeletePage:
{
deletePages(mDocumentUI->thumbnailWidget->selectedItems());
break;
}
case MoveToTrash:
{
moveIndexesToTrash(indexes, docModel);
break;
}
case CompleteDelete:
{
for (int i =0; i < indexes.size(); i++)
{
deleteIndexAndAssociatedData(indexes.at(i));
emit documentThumbnailsUpdated(this);
}
break;
}
case EmptyFolder:
{
for (int i =0; i < indexes.size(); i++)
{
QModelIndex currentIndex = indexes.at(i);
if (currentIndex == docModel->myDocumentsIndex()) { //Emptying "My documents". Keeping Untitled Documents
int startInd = 0;
while (docModel->rowCount(currentIndex)) {
QModelIndex testSubINdecurrentIndex = docModel->index(startInd, 0, currentIndex);
if (testSubINdecurrentIndex == docModel->untitledDocumentsIndex()) {
emptyFolder(testSubINdecurrentIndex, MoveToTrash);
startInd++;
continue; continue;
} }
//N/C - NNE - 20140408 : END if (!testSubINdecurrentIndex.isValid()) {
break;
}
docModel->moveIndex(testSubINdecurrentIndex, docModel->trashIndex());
}
//issue 1629 - NNE - 20131105
//Here, we are sure that the current scene has been deleted
createNewDocumentInUntitledFolder();
} else {
//issue 1629 - NNE - 20131105
//Check if we will delete the current scene
UBDocumentTreeNode *currentNode = docModel->nodeFromIndex(currentIndex);
bool deleteCurrentScene = currentNode->findNode(docModel->nodeFromIndex(docModel->currentIndex()));
emptyFolder(currentIndex, MoveToTrash); //Empty constant folder
if(deleteCurrentScene) createNewDocumentInUntitledFolder();
}
}
break;
}
case EmptyTrash:
{
for (int i=0; i < indexes.size(); i++)
{
emptyFolder(indexes.at(i), CompleteDelete); // Empty trash folder
}
break;
}
}
updateActions();
}
switch (deletionForSelection) { void UBDocumentController::deleteSingleItem(QModelIndex currentIndex, UBDocumentTreeModel* docModel)
{
DeletionType deletionForSelection = deletionTypeForSelection(mSelectionType, currentIndex, docModel);
switch (deletionForSelection)
{
case DeletePage: case DeletePage:
{ {
deletePages(mDocumentUI->thumbnailWidget->selectedItems()); deletePages(mDocumentUI->thumbnailWidget->selectedItems());
@ -2250,7 +2293,6 @@ void UBDocumentController::deleteSelectedItem()
case MoveToTrash: case MoveToTrash:
{ {
moveToTrash(currentIndex, docModel); moveToTrash(currentIndex, docModel);
break; break;
} }
case CompleteDelete: case CompleteDelete:
@ -2297,7 +2339,6 @@ void UBDocumentController::deleteSelectedItem()
break; break;
} }
} }
}
updateActions(); updateActions();
} }
@ -2332,6 +2373,8 @@ void UBDocumentController::moveIndexesToTrash(const QModelIndexList &list, UBDoc
UBDocumentProxy *proxy = docModel->proxyForIndex(sourceSibling); UBDocumentProxy *proxy = docModel->proxyForIndex(sourceSibling);
if (proxy)
{
setDocument(proxy); setDocument(proxy);
UBApplication::boardController->setActiveDocumentScene(proxy,0,true); UBApplication::boardController->setActiveDocumentScene(proxy,0,true);
docModel->setCurrentDocument(proxy); docModel->setCurrentDocument(proxy);
@ -2340,6 +2383,7 @@ void UBDocumentController::moveIndexesToTrash(const QModelIndexList &list, UBDoc
selectionModel->select(sibling, QItemSelectionModel::ClearAndSelect); selectionModel->select(sibling, QItemSelectionModel::ClearAndSelect);
deleteCurrentScene = false; deleteCurrentScene = false;
}
}else{ }else{
sibling = findNextSiblingNotSelected(proxyMapCurentScene, selectionModel); sibling = findNextSiblingNotSelected(proxyMapCurentScene, selectionModel);
@ -2348,6 +2392,8 @@ void UBDocumentController::moveIndexesToTrash(const QModelIndexList &list, UBDoc
UBDocumentProxy *proxy = docModel->proxyForIndex(sourceSibling); UBDocumentProxy *proxy = docModel->proxyForIndex(sourceSibling);
if (proxy)
{
setDocument(proxy); setDocument(proxy);
UBApplication::boardController->setActiveDocumentScene(proxy,0,true); UBApplication::boardController->setActiveDocumentScene(proxy,0,true);
docModel->setCurrentDocument(proxy); docModel->setCurrentDocument(proxy);
@ -2358,6 +2404,7 @@ void UBDocumentController::moveIndexesToTrash(const QModelIndexList &list, UBDoc
} }
} }
} }
}
else else
{ {
UBDocumentProxy* proxy = docModel->proxyForIndex(currentScene); UBDocumentProxy* proxy = docModel->proxyForIndex(currentScene);

@ -434,6 +434,8 @@ class UBDocumentController : public UBDocumentContainer
void createNewDocumentGroup(); void createNewDocumentGroup();
void deleteSelectedItem(); void deleteSelectedItem();
void deleteSingleItem(QModelIndex index, UBDocumentTreeModel *docModel);
void deleteMultipleItems(QModelIndexList indexes, UBDocumentTreeModel *docModel);
void emptyFolder(const QModelIndex &index, DeletionType pDeletionType = MoveToTrash); void emptyFolder(const QModelIndex &index, DeletionType pDeletionType = MoveToTrash);
void deleteIndexAndAssociatedData(const QModelIndex &pIndex); void deleteIndexAndAssociatedData(const QModelIndex &pIndex);
void renameSelectedItem(); void renameSelectedItem();

Loading…
Cancel
Save