File indexing completed on 2024-05-19 05:05:47
0001 /*************************************************************************** 0002 * SPDX-License-Identifier: GPL-2.0-or-later 0003 * * 0004 * SPDX-FileCopyrightText: 2004-2019 Thomas Fischer <fischer@unix-ag.uni-kl.de> 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, see <https://www.gnu.org/licenses/>. * 0018 ***************************************************************************/ 0019 0020 #ifndef KBIBTEX_PROCESSING_FINDDUPLICATES_H 0021 #define KBIBTEX_PROCESSING_FINDDUPLICATES_H 0022 0023 #include <QObject> 0024 #include <QMap> 0025 0026 #include <Value> 0027 0028 #ifdef HAVE_KF 0029 #include "kbibtexprocessing_export.h" 0030 #endif // HAVE_KF 0031 0032 class Entry; 0033 class File; 0034 class FileModel; 0035 0036 class KBIBTEXPROCESSING_EXPORT FindDuplicates; 0037 0038 /** 0039 * @author Thomas Fischer <fischer@unix-ag.uni-kl.de> 0040 */ 0041 class KBIBTEXPROCESSING_EXPORT EntryClique 0042 { 0043 friend class FindDuplicates; 0044 public: 0045 EntryClique(); 0046 0047 enum class ValueOperation { SetValue, AddValue, RemoveValue }; 0048 0049 int entryCount() const; 0050 QList<QSharedPointer<Entry> > entryList() const; 0051 bool isEntryChecked(QSharedPointer<Entry> entry) const; 0052 void setEntryChecked(QSharedPointer<Entry> entry, bool isChecked); 0053 0054 int fieldCount() const; 0055 QList<QString> fieldList() const; 0056 QVector<Value> values(const QString &field) const; 0057 QVector<Value> &values(const QString &field); 0058 Value chosenValue(const QString &field) const; 0059 QVector<Value> chosenValues(const QString &field) const; 0060 void setChosenValue(const QString &field, const Value &value, ValueOperation valueOperation = ValueOperation::SetValue); 0061 0062 QString dump() const; 0063 0064 protected: 0065 void addEntry(QSharedPointer<Entry> entry); 0066 0067 private: 0068 QMap<QSharedPointer<Entry>, bool> checkedEntries; 0069 QMap<QString, QVector<Value> > valueMap; 0070 QMap<QString, QVector<Value> > chosenValueMap; 0071 0072 void recalculateValueMap(); 0073 void insertKeyValueToValueMap(const QString &fieldName, const Value &fieldValue, const QString &fieldValueText, const Qt::CaseSensitivity = Qt::CaseSensitive); 0074 }; 0075 0076 /** 0077 * @author Thomas Fischer <fischer@unix-ag.uni-kl.de> 0078 */ 0079 class KBIBTEXPROCESSING_EXPORT FindDuplicates : public QObject 0080 { 0081 Q_OBJECT 0082 0083 public: 0084 explicit FindDuplicates(QWidget *parent, int sensitivity = 4000); 0085 ~FindDuplicates() override; 0086 0087 bool findDuplicateEntries(File *file, QVector<EntryClique *> &entryCliqueList); 0088 0089 Q_SIGNALS: 0090 void maximumProgress(int maxProgress); 0091 void currentProgress(int progress); 0092 0093 private: 0094 class FindDuplicatesPrivate; 0095 FindDuplicatesPrivate *d; 0096 }; 0097 0098 /** 0099 * @author Thomas Fischer <fischer@unix-ag.uni-kl.de> 0100 */ 0101 class KBIBTEXPROCESSING_EXPORT MergeDuplicates 0102 { 0103 public: 0104 static bool mergeDuplicateEntries(const QVector<EntryClique *> &entryCliques, FileModel *fileModel); 0105 0106 private: 0107 explicit MergeDuplicates(); 0108 }; 0109 0110 #endif // KBIBTEX_PROCESSING_FINDDUPLICATES_H