PRevent duplicates in dynamic rules
This commit is contained in:
@@ -159,6 +159,7 @@
|
||||
version.
|
||||
94. If compiled with both ffmpeg and mpg123, then prefer mpg123 for mp3 files
|
||||
if ffmpeg does not have mp3float codec.
|
||||
95. Remove duplicates from dynamic rules.
|
||||
|
||||
0.9.2
|
||||
-----
|
||||
|
||||
@@ -218,7 +218,12 @@ void DynamicRulesDialog::add()
|
||||
if (dlg->edit(Dynamic::Rule())) {
|
||||
QStandardItem *item = new QStandardItem();
|
||||
::update(item, dlg->rule());
|
||||
model->setItem(model->rowCount(), 0, item);
|
||||
int index=indexOf(item);
|
||||
if (-1!=index) {
|
||||
delete item;
|
||||
} else {
|
||||
model->setItem(model->rowCount(), 0, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +237,8 @@ void DynamicRulesDialog::edit()
|
||||
if (!dlg) {
|
||||
dlg=new DynamicRuleDialog(this);
|
||||
}
|
||||
QStandardItem *item=model->itemFromIndex(proxy->mapToSource(items.at(0)));
|
||||
QModelIndex index=proxy->mapToSource(items.at(0));
|
||||
QStandardItem *item=model->itemFromIndex(index);
|
||||
Dynamic::Rule rule;
|
||||
QMap<QString, QVariant> v=item->data().toMap();
|
||||
QMap<QString, QVariant>::ConstIterator it(v.constBegin());
|
||||
@@ -242,6 +248,10 @@ void DynamicRulesDialog::edit()
|
||||
}
|
||||
if (dlg->edit(rule)) {
|
||||
::update(item, dlg->rule());
|
||||
int idx=indexOf(item, true);
|
||||
if (-1!=idx && idx!=index.row()) {
|
||||
model->removeRow(index.row());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,3 +346,18 @@ bool DynamicRulesDialog::save()
|
||||
return saved;
|
||||
}
|
||||
}
|
||||
|
||||
int DynamicRulesDialog::indexOf(QStandardItem *item, bool diff)
|
||||
{
|
||||
QMap<QString, QVariant> v=item->data().toMap();
|
||||
|
||||
for (int i=0; i<model->rowCount(); ++i) {
|
||||
QStandardItem *itm=model->item(i);
|
||||
if (itm) {
|
||||
if (itm->data().toMap()==v && (!diff || itm!=item)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
class DynamicRuleDialog;
|
||||
class QStandardItemModel;
|
||||
class QStandardItem;
|
||||
class RulesSort;
|
||||
|
||||
class DynamicRulesDialog : public Dialog, Ui::DynamicRules
|
||||
@@ -45,6 +46,7 @@ public:
|
||||
private:
|
||||
void slotButtonClicked(int button);
|
||||
bool save();
|
||||
int indexOf(QStandardItem *item, bool diff=false);
|
||||
|
||||
private Q_SLOTS:
|
||||
void saved(bool s);
|
||||
|
||||
Reference in New Issue
Block a user