Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTL support in copy to clipboard #8629

Merged
merged 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/unreleased/8158
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/gui/activitywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
46 changes: 36 additions & 10 deletions src/gui/models/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <QSortFilterProxyModel>
#include <QMenu>

QString OCC::Models::formatSelection(const QModelIndexList &items)
#include <functional>

QString OCC::Models::formatSelection(const QModelIndexList &items, int dataRole)
{
if (items.isEmpty()) {
return {};
Expand All @@ -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<void(int)> &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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/models/models.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down