1
0
Fork 0

GUI: resolved issue #216 (additional option to copy a resized table)

This commit is contained in:
mrexodia 2016-05-31 06:56:24 +02:00
parent da607528b1
commit fd8f2d2239
No known key found for this signature in database
GPG Key ID: D72F9A4FAA0073B4
3 changed files with 38 additions and 9 deletions

View File

@ -316,7 +316,7 @@ void StdTable::copyLineSlot()
Bridge::CopyToClipboard(finalText);
}
void StdTable::copyTableSlot()
void StdTable::copyTable(std::function<int (int)> getMaxColumnLength)
{
int colCount = getColumnCount();
int rowCount = getRowCount();
@ -333,12 +333,14 @@ void StdTable::copyTableSlot()
}
else
{
int charwidth = getCharWidth();
std::vector<int> colWidths;
for(int i = 0; i < colCount; i++)
colWidths.push_back(getMaxColumnLength(i));
for(int i = 0; i < colCount; i++)
{
if(i)
finalText += " ";
int colWidth = getColumnWidth(i) / charwidth;
int colWidth = colWidths[i];
if(colWidth)
finalText += getColTitle(i).leftJustified(colWidth, QChar(' '), true);
else
@ -353,7 +355,7 @@ void StdTable::copyTableSlot()
if(j)
finalRowText += " ";
QString cellContent = getCellContent(i, j);
int colWidth = getColumnWidth(j) / charwidth;
int colWidth = colWidths[j];
if(colWidth && j != colCount - 1)
finalRowText += cellContent.leftJustified(colWidth, QChar(' '), true);
else
@ -365,6 +367,26 @@ void StdTable::copyTableSlot()
Bridge::CopyToClipboard(finalText);
}
void StdTable::copyTableSlot()
{
copyTable([this](int col)
{
return getColumnWidth(col) / getCharWidth();
});
}
void StdTable::copyTableResizeSlot()
{
copyTable([this](int col)
{
int max = 0;
int rowCount = getRowCount();
for(int i = 0; i < rowCount; i++)
max = std::max(getCellContent(i, col).length(), max);
return max;
});
}
void StdTable::copyEntrySlot()
{
QAction* action = qobject_cast<QAction*>(sender());
@ -381,13 +403,17 @@ void StdTable::setupCopyMenu(QMenu* copyMenu)
if(!getColumnCount())
return;
//Copy->Whole Line
QAction* mCopyLine = new QAction(tr("Whole &Line"), this);
QAction* mCopyLine = new QAction(tr("&Line"), copyMenu);
connect(mCopyLine, SIGNAL(triggered()), this, SLOT(copyLineSlot()));
copyMenu->addAction(mCopyLine);
//Copy->Whole Table
QAction* mCopyTable = new QAction(tr("Whole &Table"), this);
//Copy->Cropped Table
QAction* mCopyTable = new QAction(tr("Cropped &Table"), copyMenu);
connect(mCopyTable, SIGNAL(triggered()), this, SLOT(copyTableSlot()));
copyMenu->addAction(mCopyTable);
//Copy->Full Table
QAction* mCopyTableResize = new QAction(tr("&Full Table"), copyMenu);
connect(mCopyTableResize, SIGNAL(triggered()), this, SLOT(copyTableResizeSlot()));
copyMenu->addAction(mCopyTableResize);
//Copy->Separator
copyMenu->addSeparator();
//Copy->ColName
@ -398,7 +424,7 @@ void StdTable::setupCopyMenu(QMenu* copyMenu)
QString title = mCopyTitles.at(i);
if(!title.length()) //skip empty copy titles
continue;
QAction* mCopyAction = new QAction(title, this);
QAction* mCopyAction = new QAction(title, copyMenu);
mCopyAction->setObjectName(QString::number(i));
connect(mCopyAction, SIGNAL(triggered()), this, SLOT(copyEntrySlot()));
copyMenu->addAction(mCopyAction);

View File

@ -49,11 +49,14 @@ signals:
public slots:
void copyLineSlot();
void copyTableSlot();
void copyTableResizeSlot();
void copyEntrySlot();
void contextMenuRequestedSlot(const QPoint & pos);
void headerButtonPressedSlot(int col);
private:
void copyTable(std::function<int(int)> getMaxColSize);
class ColumnCompare
{
public:

View File

@ -270,7 +270,7 @@ void CPUInfoBox::addFollowMenuItem(QMenu* menu, QString name, dsint value)
foreach(QAction * action, menu->actions()) //check for duplicate action
if(action->text() == name)
return;
QAction* newAction = new QAction(name, this);
QAction* newAction = new QAction(name, menu);
newAction->setFont(QFont("Courier New", 8));
menu->addAction(newAction);
newAction->setObjectName(QString("DUMP|") + QString("%1").arg(value, sizeof(dsint) * 2, 16, QChar('0')).toUpper());