mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-06 05:14:21 -04:00
Merge pull request #466 from PhenomRetroShare/Fix_RsCollEditorCountUpdateWhenRemove
Fix RsCollection Editor Count Update When Removing items.
This commit is contained in:
commit
aaf13eb4dd
2 changed files with 97 additions and 52 deletions
|
@ -805,7 +805,7 @@ bool RsCollectionDialog::addAllChild(QFileInfo &fileInfoParent
|
||||||
*/
|
*/
|
||||||
void RsCollectionDialog::remove()
|
void RsCollectionDialog::remove()
|
||||||
{
|
{
|
||||||
bool removeOnlyFile=false;
|
bool removeOnlyFile=false;
|
||||||
QString listDir;
|
QString listDir;
|
||||||
// First, check if selection contains directories
|
// First, check if selection contains directories
|
||||||
for (int curs = 0; curs < ui._fileEntriesTW->selectedItems().count(); ++curs)
|
for (int curs = 0; curs < ui._fileEntriesTW->selectedItems().count(); ++curs)
|
||||||
|
@ -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 ((item->data(COLUMN_HASH, ROLE_TYPE).toUInt() != DIR_TYPE_DIR) || !removeOnlyFile) {
|
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();
|
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,57 +1134,71 @@ 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) {
|
||||||
QMessageBox* msgBox = new QMessageBox(QMessageBox::Information, "", "");
|
bool bRemove = false;
|
||||||
msgBox->setText("Warning, duplicate file found.");
|
if (!bRemoveAll) {
|
||||||
//msgBox->setInformativeText(); If text too long, no scroll, so I add an text edit
|
QMessageBox* msgBox = new QMessageBox(QMessageBox::Information, "", "");
|
||||||
msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
msgBox->setText("Warning, duplicate file found.");
|
||||||
msgBox->setDefaultButton(QMessageBox::Yes);
|
//msgBox->setInformativeText(); If text too long, no scroll, so I add an text edit
|
||||||
|
msgBox->setStandardButtons(QMessageBox::YesToAll | QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||||
|
msgBox->setDefaultButton(QMessageBox::Yes);
|
||||||
|
|
||||||
QGridLayout* layout = qobject_cast<QGridLayout*>(msgBox->layout());
|
QGridLayout* layout = qobject_cast<QGridLayout*>(msgBox->layout());
|
||||||
if (layout) {
|
if (layout) {
|
||||||
int newRow = 1;
|
int newRow = 1;
|
||||||
for (int row = layout->count()-1; row >= 0; --row) {
|
for (int row = layout->count()-1; row >= 0; --row) {
|
||||||
for (int col = layout->columnCount()-1; col >= 0; --col) {
|
for (int col = layout->columnCount()-1; col >= 0; --col) {
|
||||||
QLayoutItem *item = layout->itemAtPosition(row, col);
|
QLayoutItem *item = layout->itemAtPosition(row, col);
|
||||||
if (item) {
|
if (item) {
|
||||||
int index = layout->indexOf(item->widget());
|
int index = layout->indexOf(item->widget());
|
||||||
int r=0, c=0, rSpan=0, cSpan=0;
|
int r=0, c=0, rSpan=0, cSpan=0;
|
||||||
layout->getItemPosition(index, &r, &c, &rSpan, &cSpan);
|
layout->getItemPosition(index, &r, &c, &rSpan, &cSpan);
|
||||||
if (r>0) {
|
if (r>0) {
|
||||||
layout->removeItem(item);
|
layout->removeItem(item);
|
||||||
layout->addItem(item, r+3, c, rSpan, cSpan);
|
layout->addItem(item, r+3, c, rSpan, cSpan);
|
||||||
} else if (rSpan>1) {
|
} else if (rSpan>1) {
|
||||||
newRow = rSpan + 1;
|
newRow = rSpan + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QLabel *label = new QLabel(tr("Do you want to remove this file from the list?"));
|
||||||
|
layout->addWidget(label,newRow, 0, 1, layout->columnCount(), Qt::AlignHCenter );
|
||||||
|
QTextEdit *edit = new QTextEdit(item->text(COLUMN_FILEPATH));
|
||||||
|
edit->setReadOnly(true);
|
||||||
|
edit->setWordWrapMode(QTextOption::NoWrap);
|
||||||
|
layout->addWidget(edit,newRow+1, 0, 1, layout->columnCount(), Qt::AlignHCenter );
|
||||||
}
|
}
|
||||||
QLabel *label = new QLabel(tr("Do you want to remove this file from the list?"));
|
|
||||||
layout->addWidget(label,newRow, 0, 1, layout->columnCount(), Qt::AlignHCenter );
|
int ret = msgBox->exec();
|
||||||
QTextEdit *edit = new QTextEdit(item->text(COLUMN_FILEPATH));
|
switch (ret) {
|
||||||
edit->setReadOnly(true);
|
case QMessageBox::YesToAll: {
|
||||||
edit->setWordWrapMode(QTextOption::NoWrap);
|
bRemoveAll = true;
|
||||||
layout->addWidget(edit,newRow+1, 0, 1, layout->columnCount(), Qt::AlignHCenter );
|
}
|
||||||
|
break;
|
||||||
|
case QMessageBox::Yes: {
|
||||||
|
bRemove = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case QMessageBox::No:
|
||||||
|
break;
|
||||||
|
case QMessageBox::Cancel: {
|
||||||
|
delete msgBox;
|
||||||
|
ui._removeDuplicate_CB->setChecked(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// should never be reached
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
delete msgBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = msgBox->exec();
|
if (bRemove || bRemoveAll) {
|
||||||
switch (ret) {
|
//First uncheck item to update parent informations
|
||||||
case QMessageBox::Yes:
|
item->setCheckState(COLUMN_FILE,Qt::Unchecked);
|
||||||
item->parent()->removeChild(item);
|
item->parent()->removeChild(item);
|
||||||
break;
|
|
||||||
case QMessageBox::No:
|
|
||||||
break;
|
|
||||||
case QMessageBox::Cancel: {
|
|
||||||
delete msgBox;
|
|
||||||
ui._removeDuplicate_CB->setChecked(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// should never be reached
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
delete msgBox;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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