mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-22 22:21:09 -04:00
Fix RsCollection Editor Count Update When Removing items.
Thanks to Jola to get this bug.
This commit is contained in:
parent
c0c7ede97b
commit
ee368ef045
2 changed files with 97 additions and 52 deletions
|
@ -880,20 +880,49 @@ void RsCollectionDialog::remove()
|
|||
}//if (!listDir.isEmpty())
|
||||
|
||||
//Remove wanted items
|
||||
for (int curs = 0; curs < ui._fileEntriesTW->selectedItems().count(); ++curs)
|
||||
{// Have to call ui._fileEntriesTW->selectedItems().count() each time as selected change
|
||||
QTreeWidgetItem *item = NULL;
|
||||
item= ui._fileEntriesTW->selectedItems().at(curs);
|
||||
int leftItem = 0;
|
||||
// Have to call ui._fileEntriesTW->selectedItems().count() each time as selected change
|
||||
while (ui._fileEntriesTW->selectedItems().count() > leftItem) {
|
||||
QTreeWidgetItem *item = ui._fileEntriesTW->selectedItems().at(leftItem);
|
||||
|
||||
if (item != getRootItem()){
|
||||
if (!removeItem(item, removeOnlyFile)) {
|
||||
++leftItem;
|
||||
}
|
||||
} else {
|
||||
//Get Root change index
|
||||
++leftItem;
|
||||
}
|
||||
}
|
||||
|
||||
updateSizes() ;
|
||||
|
||||
}
|
||||
|
||||
bool RsCollectionDialog::removeItem(QTreeWidgetItem *item, bool &removeOnlyFile)
|
||||
{
|
||||
if (item){
|
||||
if ((item->data(COLUMN_HASH, ROLE_TYPE).toUInt() != DIR_TYPE_DIR) || !removeOnlyFile) {
|
||||
int leftItem = 0;
|
||||
while (item->childCount() > leftItem) {
|
||||
if (!removeItem(item->child(0), removeOnlyFile)) {
|
||||
++leftItem;
|
||||
}
|
||||
}
|
||||
if (leftItem == 0) {
|
||||
//First uncheck item to update parent informations
|
||||
item->setCheckState(COLUMN_FILE,Qt::Unchecked);
|
||||
QTreeWidgetItem *parent = item->parent();
|
||||
parent->removeChild(item);
|
||||
curs = 0;//Cause we don't know how many child of this item was selected (and don't want iterate them ;) )
|
||||
return true;
|
||||
} else {
|
||||
if (!removeOnlyFile) {
|
||||
std::cerr << "(EE) RsCollectionDialog::removeItem This could never happen." << std::endl;
|
||||
}
|
||||
}//if (item != getRootItem())*
|
||||
}//for (int curs = 0; curs < count; ++curs)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Process each item to make a new RsCollection item */
|
||||
|
@ -1096,6 +1125,7 @@ void RsCollectionDialog::itemChanged(QTreeWidgetItem *item, int col)
|
|||
void RsCollectionDialog::updateRemoveDuplicate(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
bool bRemoveAll = false;
|
||||
QTreeWidgetItemIterator it(ui._fileEntriesTW);
|
||||
QTreeWidgetItem *item;
|
||||
while ((item = *it) != NULL) {
|
||||
|
@ -1104,10 +1134,12 @@ void RsCollectionDialog::updateRemoveDuplicate(bool checked)
|
|||
QList<QTreeWidgetItem*> founds;
|
||||
founds << ui._fileEntriesTW->findItems(item->text(COLUMN_HASH), Qt::MatchExactly | Qt::MatchRecursive, COLUMN_HASH);
|
||||
if (founds.count() > 1) {
|
||||
bool bRemove = false;
|
||||
if (!bRemoveAll) {
|
||||
QMessageBox* msgBox = new QMessageBox(QMessageBox::Information, "", "");
|
||||
msgBox->setText("Warning, duplicate file found.");
|
||||
//msgBox->setInformativeText(); If text too long, no scroll, so I add an text edit
|
||||
msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
msgBox->setStandardButtons(QMessageBox::YesToAll | QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
msgBox->setDefaultButton(QMessageBox::Yes);
|
||||
|
||||
QGridLayout* layout = qobject_cast<QGridLayout*>(msgBox->layout());
|
||||
|
@ -1139,14 +1171,19 @@ void RsCollectionDialog::updateRemoveDuplicate(bool checked)
|
|||
|
||||
int ret = msgBox->exec();
|
||||
switch (ret) {
|
||||
case QMessageBox::Yes:
|
||||
item->parent()->removeChild(item);
|
||||
case QMessageBox::YesToAll: {
|
||||
bRemoveAll = true;
|
||||
}
|
||||
break;
|
||||
case QMessageBox::Yes: {
|
||||
bRemove = true;
|
||||
}
|
||||
break;
|
||||
case QMessageBox::No:
|
||||
break;
|
||||
case QMessageBox::Cancel: {
|
||||
delete msgBox;
|
||||
ui._removeDuplicate_CB->setChecked(true);
|
||||
ui._removeDuplicate_CB->setChecked(false);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
@ -1155,6 +1192,13 @@ void RsCollectionDialog::updateRemoveDuplicate(bool checked)
|
|||
break;
|
||||
}
|
||||
delete msgBox;
|
||||
}
|
||||
|
||||
if (bRemove || bRemoveAll) {
|
||||
//First uncheck item to update parent informations
|
||||
item->setCheckState(COLUMN_FILE,Qt::Unchecked);
|
||||
item->parent()->removeChild(item);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ private:
|
|||
QTreeWidgetItem* getRootItem();
|
||||
bool updateList();
|
||||
bool addChild(QTreeWidgetItem *parent, const std::vector<ColFileInfo> &child);
|
||||
bool removeItem(QTreeWidgetItem *item, bool &removeOnlyFile) ;
|
||||
void addRecursive(bool recursive) ;
|
||||
bool addAllChild(QFileInfo &fileInfoParent
|
||||
, QMap<QString, QString > &dirToAdd
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue