forked from qt-creator/qt-creator
QmlProfiler: copy event information to clipboard
Task-number: QTCREATORBUG-5033 Change-Id: I7424afc24a03c4094b01f8a4d424a21daa20ed4a Reviewed-on: http://codereview.qt.nokia.com/3478 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
@@ -38,6 +38,9 @@
|
||||
#include <QtGui/QStandardItem>
|
||||
#include <QtGui/QHeaderView>
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QClipboard>
|
||||
|
||||
#include <QtGui/QContextMenuEvent>
|
||||
#include <QDebug>
|
||||
|
||||
@@ -84,6 +87,8 @@ public:
|
||||
QString displayTime(double time) const;
|
||||
QString nameForType(int typeNumber) const;
|
||||
|
||||
QString textForItem(QStandardItem *item, bool recursive) const;
|
||||
|
||||
|
||||
QmlProfilerEventsView *q;
|
||||
|
||||
@@ -407,5 +412,70 @@ void QmlProfilerEventsView::contextMenuEvent(QContextMenuEvent *ev)
|
||||
emit contextMenuRequested(ev->globalPos());
|
||||
}
|
||||
|
||||
QModelIndex QmlProfilerEventsView::selectedItem() const
|
||||
{
|
||||
QModelIndexList sel = selectedIndexes();
|
||||
if (sel.isEmpty())
|
||||
return QModelIndex();
|
||||
else
|
||||
return sel.first();
|
||||
}
|
||||
|
||||
QString QmlProfilerEventsView::QmlProfilerEventsViewPrivate::textForItem(QStandardItem *item, bool recursive = true) const
|
||||
{
|
||||
QString str;
|
||||
|
||||
if (recursive) {
|
||||
// indentation
|
||||
QStandardItem *itemParent = item->parent();
|
||||
while (itemParent) {
|
||||
str += '\t';
|
||||
itemParent = itemParent->parent();
|
||||
}
|
||||
}
|
||||
|
||||
// item's data
|
||||
int colCount = m_model->columnCount();
|
||||
for (int j = 0; j < colCount; ++j) {
|
||||
QStandardItem *colItem = item->parent() ? item->parent()->child(item->row(),j) : m_model->item(item->row(),j);
|
||||
str += colItem->data(Qt::DisplayRole).toString();
|
||||
if (j < colCount-1) str += '\t';
|
||||
}
|
||||
str += '\n';
|
||||
|
||||
// recursively print children
|
||||
if (recursive && item->child(0))
|
||||
for (int j = 0; j != item->rowCount(); j++)
|
||||
str += textForItem(item->child(j));
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void QmlProfilerEventsView::copyTableToClipboard()
|
||||
{
|
||||
QString str;
|
||||
int n = d->m_model->rowCount();
|
||||
for (int i = 0; i != n; ++i) {
|
||||
str += d->textForItem(d->m_model->item(i));
|
||||
}
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
# ifdef Q_WS_X11
|
||||
clipboard->setText(str, QClipboard::Selection);
|
||||
# endif
|
||||
clipboard->setText(str, QClipboard::Clipboard);
|
||||
}
|
||||
|
||||
void QmlProfilerEventsView::copyRowToClipboard()
|
||||
{
|
||||
QString str;
|
||||
str = d->textForItem(d->m_model->itemFromIndex(selectedItem()), false);
|
||||
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
# ifdef Q_WS_X11
|
||||
clipboard->setText(str, QClipboard::Selection);
|
||||
# endif
|
||||
clipboard->setText(str, QClipboard::Clipboard);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlProfiler
|
||||
|
@@ -85,6 +85,10 @@ public:
|
||||
void setViewType(ViewTypes type);
|
||||
void setShowAnonymousEvents( bool showThem );
|
||||
|
||||
QModelIndex selectedItem() const;
|
||||
void copyTableToClipboard();
|
||||
void copyRowToClipboard();
|
||||
|
||||
signals:
|
||||
void gotoSourceLocation(const QString &fileName, int lineNumber);
|
||||
void contextMenuRequested(const QPoint &position);
|
||||
|
@@ -169,15 +169,28 @@ IAnalyzerTool::ToolMode QmlProfilerTool::toolMode() const
|
||||
|
||||
void QmlProfilerTool::showContextMenu(const QPoint &position)
|
||||
{
|
||||
QmlProfilerEventsView *senderView = qobject_cast<QmlProfilerEventsView *>(sender());
|
||||
|
||||
QMenu menu;
|
||||
QAction *loadAction = menu.addAction(tr("Load QML Trace"));
|
||||
QAction *saveAction = menu.addAction(tr("Save QML Trace"));
|
||||
QAction *copyRowAction;
|
||||
QAction *copyTableAction;
|
||||
if (senderView) {
|
||||
if (senderView->selectedItem().isValid())
|
||||
copyRowAction = menu.addAction(tr("Copy Row"));
|
||||
copyTableAction = menu.addAction(tr("Copy Table"));
|
||||
}
|
||||
|
||||
QAction *selectedAction = menu.exec(position);
|
||||
if (selectedAction == loadAction)
|
||||
showLoadDialog();
|
||||
if (selectedAction == saveAction)
|
||||
showSaveDialog();
|
||||
if (selectedAction == copyRowAction)
|
||||
senderView->copyRowToClipboard();
|
||||
if (selectedAction == copyTableAction)
|
||||
senderView->copyTableToClipboard();
|
||||
}
|
||||
|
||||
IAnalyzerEngine *QmlProfilerTool::createEngine(const AnalyzerStartParameters &sp,
|
||||
|
Reference in New Issue
Block a user