diff --git a/changelog/unreleased/8158 b/changelog/unreleased/8158 index bd495347f62..457686a584f 100644 --- a/changelog/unreleased/8158 +++ b/changelog/unreleased/8158 @@ -9,3 +9,4 @@ https://github.com/owncloud/client/issues/8528 https://github.com/owncloud/client/pull/8584 https://github.com/owncloud/client/pull/8585 https://github.com/owncloud/client/pull/8627 +https://github.com/owncloud/client/pull/8629 diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp index 466f3a4d53e..dfbac6db228 100644 --- a/src/gui/activitywidget.cpp +++ b/src/gui/activitywidget.cpp @@ -453,7 +453,7 @@ void ActivityWidget::slotItemContextMenu() menu->setAttribute(Qt::WA_DeleteOnClose); // keep in sync with ProtocolWidget::showContextMenu - menu->addAction(tr("Copy to clipboard"), this, [text = Models::formatSelection(rows)] { + menu->addAction(tr("Copy to clipboard"), this, [text = Models::formatSelection(rows, Models::UnderlyingDataRole)] { QApplication::clipboard()->setText(text); }); diff --git a/src/gui/models/models.cpp b/src/gui/models/models.cpp index 1e62eed1e3d..e32d2859432 100644 --- a/src/gui/models/models.cpp +++ b/src/gui/models/models.cpp @@ -19,7 +19,9 @@ #include #include -QString OCC::Models::formatSelection(const QModelIndexList &items) +#include + +QString OCC::Models::formatSelection(const QModelIndexList &items, int dataRole) { if (items.isEmpty()) { return {}; @@ -28,23 +30,47 @@ QString OCC::Models::formatSelection(const QModelIndexList &items) QString out; QTextStream stream(&out); - for (int c = 0; c < columns; ++c) { + QString begin; + QString end; + + const auto iterate = [columns](const std::function &f) { + if (qApp->layoutDirection() != Qt::RightToLeft) { + for (int c = 0; c < columns; ++c) { + f(c); + } + } else { + for (int c = columns - 1; c >= 0; --c) { + f(c); + } + } + }; + if (qApp->layoutDirection() == Qt::RightToLeft) { + stream << right; + begin = QLatin1Char(','); + } else { + stream << left; + end = QLatin1Char(','); + } + + iterate([&](int c) { const auto width = items.first().model()->headerData(c, Qt::Horizontal, StringFormatWidthRole).toInt(); Q_ASSERT(width); - stream << right + stream << begin << qSetFieldWidth(width) << items.first().model()->headerData(c, Qt::Horizontal).toString() - << qSetFieldWidth(0) << ","; - } + << qSetFieldWidth(0) + << end; + }); stream << endl; for (const auto &index : items) { - for (int c = 0; c < columns; ++c) { + iterate([&](int c) { const auto &child = index.siblingAtColumn(c); - stream << right + stream << begin << qSetFieldWidth(child.model()->headerData(c, Qt::Horizontal, StringFormatWidthRole).toInt()) - << child.data(Qt::DisplayRole).toString() - << qSetFieldWidth(0) << ","; - } + << child.data(dataRole).toString() + << qSetFieldWidth(0) + << end; + }); stream << endl; } return out; diff --git a/src/gui/models/models.h b/src/gui/models/models.h index fcb6b36641f..035d2fdfe08 100644 --- a/src/gui/models/models.h +++ b/src/gui/models/models.h @@ -30,7 +30,7 @@ namespace Models { /** * Returns a cvs representation of a table */ - QString formatSelection(const QModelIndexList &items); + QString formatSelection(const QModelIndexList &items, int dataRole = Qt::DisplayRole); void displayFilterDialog(const QStringList &candidates, QSortFilterProxyModel *model, int column, int role, QWidget *parent = nullptr);