GUI: show duplicates: use a result table window instead of the static list

This commit is contained in:
Jean-Francois Dockes 2022-02-07 15:37:06 +01:00
parent b49696653b
commit 5666ec568a
4 changed files with 49 additions and 52 deletions

View File

@ -37,6 +37,7 @@
#include "webcache.h" #include "webcache.h"
#include "restable.h" #include "restable.h"
#include "actsearch_w.h" #include "actsearch_w.h"
#include "docseqdocs.h"
using namespace std; using namespace std;
@ -443,27 +444,16 @@ void RclMain::showActiveTypes()
void RclMain::newDupsW(const Rcl::Doc, const vector<Rcl::Doc> dups) void RclMain::newDupsW(const Rcl::Doc, const vector<Rcl::Doc> dups)
{ {
ListDialog dialog; if (nullptr == m_dupsw) {
dialog.setWindowTitle(tr("Duplicate documents")); m_dupsw = new ResTable(nullptr, {"ipath", "url"});
m_dupsw->setRclMain(this, false);
dialog.groupBox->setTitle(tr("These Urls ( | ipath) share the same"
" content:"));
// We replace the list with an editor so that the user can copy/paste
deleteZ(dialog.listWidget);
QTextEdit *editor = new QTextEdit(dialog.groupBox);
editor->setReadOnly(true);
dialog.horizontalLayout->addWidget(editor);
for (vector<Rcl::Doc>::const_iterator it = dups.begin();
it != dups.end(); it++) {
if (it->ipath.empty())
editor->append(path2qs(it->url));
else
editor->append(path2qs(it->url) + " | " + u8s2qs(it->ipath));
} }
editor->moveCursor(QTextCursor::Start); auto src = std::make_shared<DocSequenceDocs>(rcldb, dups, qs2utf8s(tr("Duplicates")));
editor->ensureCursorVisible(); src->setDescription(qs2utf8s(tr("Duplicates")));
dialog.exec(); auto source = std::make_shared<DocSource>(theconfig, src);
m_dupsw->setDocSource(source);
m_dupsw->readDocSource();
m_dupsw->show();
} }
void RclMain::showSnippets(Rcl::Doc doc) void RclMain::showSnippets(Rcl::Doc doc)

View File

@ -213,6 +213,7 @@ private:
QTimer *periodictimer{0}; QTimer *periodictimer{0};
WebcacheEdit *webcache{0}; WebcacheEdit *webcache{0};
ResTable *restable{0}; ResTable *restable{0};
ResTable *m_dupsw{0};
bool displayingTable{false}; bool displayingTable{false};
ActSearchW *actsearchw{0}; ActSearchW *actsearchw{0};
QAction *m_idNoStem{0}; QAction *m_idNoStem{0};

View File

@ -250,8 +250,7 @@ string RecollModel::baseField(const string& field)
return field; return field;
} }
RecollModel::RecollModel(const QStringList fields, ResTable *tb, RecollModel::RecollModel(const QStringList fields, ResTable *tb, QObject *parent)
QObject *parent)
: QAbstractTableModel(parent), m_table(tb), m_ignoreSort(false) : QAbstractTableModel(parent), m_table(tb), m_ignoreSort(false)
{ {
// Initialize the translated map for column headers // Initialize the translated map for column headers
@ -286,8 +285,7 @@ RecollModel::RecollModel(const QStringList fields, ResTable *tb,
} }
// Construct the actual list of column names // Construct the actual list of column names
for (QStringList::const_iterator it = fields.begin(); for (QStringList::const_iterator it = fields.begin(); it != fields.end(); it++) {
it != fields.end(); it++) {
m_fields.push_back((const char *)(it->toUtf8())); m_fields.push_back((const char *)(it->toUtf8()));
m_getters.push_back(chooseGetter(m_fields.back())); m_getters.push_back(chooseGetter(m_fields.back()));
} }
@ -593,10 +591,12 @@ void ResTable::setDefRowHeight()
} }
} }
void ResTable::init() void ResTable::init(QStringList _ifields)
{ {
QSettings settings; QSettings settings;
auto restableFields = settings.value(settingskey_fieldlist).toStringList(); QStringList restableFields;
if (_ifields.empty()) {
restableFields = settings.value(settingskey_fieldlist).toStringList();
if (restableFields.empty()) { if (restableFields.empty()) {
restableFields.push_back("date"); restableFields.push_back("date");
restableFields.push_back("title"); restableFields.push_back("title");
@ -604,6 +604,9 @@ void ResTable::init()
restableFields.push_back("author"); restableFields.push_back("author");
restableFields.push_back("url"); restableFields.push_back("url");
} }
} else {
restableFields = _ifields;
}
if (!(m_model = new RecollModel(restableFields, this))) if (!(m_model = new RecollModel(restableFields, this)))
return; return;
tableView->setModel(m_model); tableView->setModel(m_model);
@ -626,6 +629,7 @@ void ResTable::init()
QHeaderView *header = tableView->horizontalHeader(); QHeaderView *header = tableView->horizontalHeader();
if (header) { if (header) {
if (_ifields.empty()) {
QString qw = settings.value(settingskey_fieldwiths).toString(); QString qw = settings.value(settingskey_fieldwiths).toString();
vector<string> vw; vector<string> vw;
stringToStrings(qs2utf8s(qw), vw); stringToStrings(qs2utf8s(qw), vw);
@ -641,11 +645,13 @@ void ResTable::init()
header->setSortIndicatorShown(true); header->setSortIndicatorShown(true);
header->setSortIndicator(-1, Qt::AscendingOrder); header->setSortIndicator(-1, Qt::AscendingOrder);
header->setContextMenuPolicy(Qt::CustomContextMenu); header->setContextMenuPolicy(Qt::CustomContextMenu);
header->setStretchLastSection(1); connect(header, SIGNAL(sectionResized(int,int,int)), this, SLOT(saveColState()));
connect(header, SIGNAL(sectionResized(int,int,int)),
this, SLOT(saveColState()));
connect(header, SIGNAL(customContextMenuRequested(const QPoint&)), connect(header, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(createHeaderPopupMenu(const QPoint&))); this, SLOT(createHeaderPopupMenu(const QPoint&)));
} else {
header->setSortIndicatorShown(false);
}
header->setStretchLastSection(1);
} }
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
header->setSectionsMovable(true); header->setSectionsMovable(true);

View File

@ -137,10 +137,10 @@ class ResTable : public QWidget, public Ui::ResTable
Q_OBJECT; Q_OBJECT;
public: public:
ResTable(QWidget* parent = 0) ResTable(QWidget* parent = 0, QStringList fields = QStringList())
: QWidget(parent) { : QWidget(parent) {
setupUi(this); setupUi(this);
init(); init(fields);
} }
virtual ~ResTable() {} virtual ~ResTable() {}
@ -214,7 +214,7 @@ protected:
bool eventFilter(QObject* obj, QEvent* event); bool eventFilter(QObject* obj, QEvent* event);
private: private:
void init(); void init(QStringList fields);
RecollModel *m_model{nullptr}; RecollModel *m_model{nullptr};
ResTablePager *m_pager{nullptr}; ResTablePager *m_pager{nullptr};