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 "restable.h"
#include "actsearch_w.h"
#include "docseqdocs.h"
using namespace std;
@ -443,27 +444,16 @@ void RclMain::showActiveTypes()
void RclMain::newDupsW(const Rcl::Doc, const vector<Rcl::Doc> dups)
{
ListDialog dialog;
dialog.setWindowTitle(tr("Duplicate documents"));
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));
if (nullptr == m_dupsw) {
m_dupsw = new ResTable(nullptr, {"ipath", "url"});
m_dupsw->setRclMain(this, false);
}
editor->moveCursor(QTextCursor::Start);
editor->ensureCursorVisible();
dialog.exec();
auto src = std::make_shared<DocSequenceDocs>(rcldb, dups, qs2utf8s(tr("Duplicates")));
src->setDescription(qs2utf8s(tr("Duplicates")));
auto source = std::make_shared<DocSource>(theconfig, src);
m_dupsw->setDocSource(source);
m_dupsw->readDocSource();
m_dupsw->show();
}
void RclMain::showSnippets(Rcl::Doc doc)

View File

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

View File

@ -250,8 +250,7 @@ string RecollModel::baseField(const string& field)
return field;
}
RecollModel::RecollModel(const QStringList fields, ResTable *tb,
QObject *parent)
RecollModel::RecollModel(const QStringList fields, ResTable *tb, QObject *parent)
: QAbstractTableModel(parent), m_table(tb), m_ignoreSort(false)
{
// 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
for (QStringList::const_iterator it = fields.begin();
it != fields.end(); it++) {
for (QStringList::const_iterator it = fields.begin(); it != fields.end(); it++) {
m_fields.push_back((const char *)(it->toUtf8()));
m_getters.push_back(chooseGetter(m_fields.back()));
}
@ -593,16 +591,21 @@ void ResTable::setDefRowHeight()
}
}
void ResTable::init()
void ResTable::init(QStringList _ifields)
{
QSettings settings;
auto restableFields = settings.value(settingskey_fieldlist).toStringList();
if (restableFields.empty()) {
restableFields.push_back("date");
restableFields.push_back("title");
restableFields.push_back("filename");
restableFields.push_back("author");
restableFields.push_back("url");
QStringList restableFields;
if (_ifields.empty()) {
restableFields = settings.value(settingskey_fieldlist).toStringList();
if (restableFields.empty()) {
restableFields.push_back("date");
restableFields.push_back("title");
restableFields.push_back("filename");
restableFields.push_back("author");
restableFields.push_back("url");
}
} else {
restableFields = _ifields;
}
if (!(m_model = new RecollModel(restableFields, this)))
return;
@ -626,26 +629,29 @@ void ResTable::init()
QHeaderView *header = tableView->horizontalHeader();
if (header) {
QString qw = settings.value(settingskey_fieldwiths).toString();
vector<string> vw;
stringToStrings(qs2utf8s(qw), vw);
vector<int> restableColWidths;
for (const auto& w : vw) {
restableColWidths.push_back(atoi(w.c_str()));
}
if (int(restableColWidths.size()) == header->count()) {
for (int i = 0; i < header->count(); i++) {
header->resizeSection(i, restableColWidths[i]);
if (_ifields.empty()) {
QString qw = settings.value(settingskey_fieldwiths).toString();
vector<string> vw;
stringToStrings(qs2utf8s(qw), vw);
vector<int> restableColWidths;
for (const auto& w : vw) {
restableColWidths.push_back(atoi(w.c_str()));
}
if (int(restableColWidths.size()) == header->count()) {
for (int i = 0; i < header->count(); i++) {
header->resizeSection(i, restableColWidths[i]);
}
}
header->setSortIndicatorShown(true);
header->setSortIndicator(-1, Qt::AscendingOrder);
header->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header, SIGNAL(sectionResized(int,int,int)), this, SLOT(saveColState()));
connect(header, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(createHeaderPopupMenu(const QPoint&)));
} else {
header->setSortIndicatorShown(false);
}
header->setSortIndicatorShown(true);
header->setSortIndicator(-1, Qt::AscendingOrder);
header->setContextMenuPolicy(Qt::CustomContextMenu);
header->setStretchLastSection(1);
connect(header, SIGNAL(sectionResized(int,int,int)),
this, SLOT(saveColState()));
connect(header, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(createHeaderPopupMenu(const QPoint&)));
}
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
header->setSectionsMovable(true);

View File

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