mirror of
https://github.com/tnodir/fort
synced 2024-11-15 01:47:47 +00:00
UI: Connections: Add ability to copy selected cells' text.
This commit is contained in:
parent
e408f7db6b
commit
05a2e7367b
@ -71,6 +71,7 @@ void ConnectionsWindow::onRetranslateUi()
|
||||
this->unsetLocale();
|
||||
|
||||
m_btEdit->setText(tr("Edit"));
|
||||
m_actCopy->setText(tr("Copy"));
|
||||
m_actRemoveConn->setText(tr("Remove"));
|
||||
m_actClearConns->setText(tr("Clear All"));
|
||||
|
||||
@ -125,11 +126,17 @@ QLayout *ConnectionsWindow::setupHeader()
|
||||
// Edit Menu
|
||||
auto editMenu = new QMenu(this);
|
||||
|
||||
m_actCopy = editMenu->addAction(IconCache::icon(":/icons/copy.png"), QString());
|
||||
m_actCopy->setShortcut(Qt::Key_Copy);
|
||||
|
||||
m_actRemoveConn = editMenu->addAction(IconCache::icon(":/icons/sign-delete.png"), QString());
|
||||
m_actRemoveConn->setShortcut(Qt::Key_Delete);
|
||||
|
||||
m_actClearConns = editMenu->addAction(IconCache::icon(":/icons/trash.png"), QString());
|
||||
|
||||
connect(m_actCopy, &QAction::triggered, this, [&] {
|
||||
GuiUtil::setClipboardData(m_connListView->selectedText());
|
||||
});
|
||||
connect(m_actRemoveConn, &QAction::triggered, this, [&] {
|
||||
if (fortManager()->showQuestionBox(tr("Are you sure to remove selected connection(s)?"))) {
|
||||
deleteSelectedConns();
|
||||
@ -279,6 +286,7 @@ void ConnectionsWindow::setupTableConnsChanged()
|
||||
const auto refreshTableConnsChanged = [&] {
|
||||
const int connIndex = connListCurrentIndex();
|
||||
const bool connSelected = (connIndex >= 0);
|
||||
m_actCopy->setEnabled(connSelected);
|
||||
m_actRemoveConn->setEnabled(connSelected);
|
||||
m_appInfoRow->setVisible(connSelected);
|
||||
};
|
||||
|
@ -64,6 +64,7 @@ private:
|
||||
ConnectionsController *m_ctrl = nullptr;
|
||||
|
||||
QPushButton *m_btEdit = nullptr;
|
||||
QAction *m_actCopy = nullptr;
|
||||
QAction *m_actRemoveConn = nullptr;
|
||||
QAction *m_actClearConns = nullptr;
|
||||
QPushButton *m_btLogOptions = nullptr;
|
||||
|
@ -19,6 +19,46 @@ QVector<int> TableView::selectedRows() const
|
||||
return rows.toVector();
|
||||
}
|
||||
|
||||
QModelIndexList TableView::sortedSelectedIndexes() const
|
||||
{
|
||||
auto indexes = selectedIndexes();
|
||||
std::sort(indexes.begin(), indexes.end());
|
||||
return indexes;
|
||||
}
|
||||
|
||||
QString TableView::selectedText() const
|
||||
{
|
||||
QString text;
|
||||
|
||||
int prevRow = -1;
|
||||
int prevColumn = -1;
|
||||
|
||||
const auto indexes = sortedSelectedIndexes();
|
||||
for (const auto index : indexes) {
|
||||
const int row = index.row();
|
||||
if (prevRow != row) {
|
||||
if (prevRow != -1) {
|
||||
text.append('\n');
|
||||
}
|
||||
prevRow = row;
|
||||
prevColumn = -1;
|
||||
}
|
||||
|
||||
const int column = index.column();
|
||||
if (prevColumn != column) {
|
||||
if (prevColumn != -1) {
|
||||
text.append('\t');
|
||||
}
|
||||
prevColumn = column;
|
||||
}
|
||||
|
||||
const QString s = model()->data(index).toString();
|
||||
text.append(s);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
void TableView::selectCell(int row, int column)
|
||||
{
|
||||
const auto index = model()->index(row, column);
|
||||
|
@ -14,6 +14,9 @@ public:
|
||||
void setMenu(QMenu *menu) { m_menu = menu; }
|
||||
|
||||
QVector<int> selectedRows() const;
|
||||
QModelIndexList sortedSelectedIndexes() const;
|
||||
|
||||
QString selectedText() const;
|
||||
|
||||
signals:
|
||||
void currentIndexChanged(const QModelIndex &index);
|
||||
|
Loading…
Reference in New Issue
Block a user