mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-23 06:31:20 -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())
|
}//if (!listDir.isEmpty())
|
||||||
|
|
||||||
//Remove wanted items
|
//Remove wanted items
|
||||||
for (int curs = 0; curs < ui._fileEntriesTW->selectedItems().count(); ++curs)
|
int leftItem = 0;
|
||||||
{// Have to call ui._fileEntriesTW->selectedItems().count() each time as selected change
|
// Have to call ui._fileEntriesTW->selectedItems().count() each time as selected change
|
||||||
QTreeWidgetItem *item = NULL;
|
while (ui._fileEntriesTW->selectedItems().count() > leftItem) {
|
||||||
item= ui._fileEntriesTW->selectedItems().at(curs);
|
QTreeWidgetItem *item = ui._fileEntriesTW->selectedItems().at(leftItem);
|
||||||
|
|
||||||
if (item != getRootItem()){
|
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) {
|
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();
|
QTreeWidgetItem *parent = item->parent();
|
||||||
parent->removeChild(item);
|
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 */
|
/** 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)
|
void RsCollectionDialog::updateRemoveDuplicate(bool checked)
|
||||||
{
|
{
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
bool bRemoveAll = false;
|
||||||
QTreeWidgetItemIterator it(ui._fileEntriesTW);
|
QTreeWidgetItemIterator it(ui._fileEntriesTW);
|
||||||
QTreeWidgetItem *item;
|
QTreeWidgetItem *item;
|
||||||
while ((item = *it) != NULL) {
|
while ((item = *it) != NULL) {
|
||||||
|
@ -1104,10 +1134,12 @@ void RsCollectionDialog::updateRemoveDuplicate(bool checked)
|
||||||
QList<QTreeWidgetItem*> founds;
|
QList<QTreeWidgetItem*> founds;
|
||||||
founds << ui._fileEntriesTW->findItems(item->text(COLUMN_HASH), Qt::MatchExactly | Qt::MatchRecursive, COLUMN_HASH);
|
founds << ui._fileEntriesTW->findItems(item->text(COLUMN_HASH), Qt::MatchExactly | Qt::MatchRecursive, COLUMN_HASH);
|
||||||
if (founds.count() > 1) {
|
if (founds.count() > 1) {
|
||||||
|
bool bRemove = false;
|
||||||
|
if (!bRemoveAll) {
|
||||||
QMessageBox* msgBox = new QMessageBox(QMessageBox::Information, "", "");
|
QMessageBox* msgBox = new QMessageBox(QMessageBox::Information, "", "");
|
||||||
msgBox->setText("Warning, duplicate file found.");
|
msgBox->setText("Warning, duplicate file found.");
|
||||||
//msgBox->setInformativeText(); If text too long, no scroll, so I add an text edit
|
//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);
|
msgBox->setDefaultButton(QMessageBox::Yes);
|
||||||
|
|
||||||
QGridLayout* layout = qobject_cast<QGridLayout*>(msgBox->layout());
|
QGridLayout* layout = qobject_cast<QGridLayout*>(msgBox->layout());
|
||||||
|
@ -1139,14 +1171,19 @@ void RsCollectionDialog::updateRemoveDuplicate(bool checked)
|
||||||
|
|
||||||
int ret = msgBox->exec();
|
int ret = msgBox->exec();
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case QMessageBox::Yes:
|
case QMessageBox::YesToAll: {
|
||||||
item->parent()->removeChild(item);
|
bRemoveAll = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case QMessageBox::Yes: {
|
||||||
|
bRemove = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case QMessageBox::No:
|
case QMessageBox::No:
|
||||||
break;
|
break;
|
||||||
case QMessageBox::Cancel: {
|
case QMessageBox::Cancel: {
|
||||||
delete msgBox;
|
delete msgBox;
|
||||||
ui._removeDuplicate_CB->setChecked(true);
|
ui._removeDuplicate_CB->setChecked(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1155,6 +1192,13 @@ void RsCollectionDialog::updateRemoveDuplicate(bool checked)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
delete msgBox;
|
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();
|
QTreeWidgetItem* getRootItem();
|
||||||
bool updateList();
|
bool updateList();
|
||||||
bool addChild(QTreeWidgetItem *parent, const std::vector<ColFileInfo> &child);
|
bool addChild(QTreeWidgetItem *parent, const std::vector<ColFileInfo> &child);
|
||||||
|
bool removeItem(QTreeWidgetItem *item, bool &removeOnlyFile) ;
|
||||||
void addRecursive(bool recursive) ;
|
void addRecursive(bool recursive) ;
|
||||||
bool addAllChild(QFileInfo &fileInfoParent
|
bool addAllChild(QFileInfo &fileInfoParent
|
||||||
, QMap<QString, QString > &dirToAdd
|
, QMap<QString, QString > &dirToAdd
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue