diff --git a/src/plugins/qmlprofiler/qmlprofilereventview.cpp b/src/plugins/qmlprofiler/qmlprofilereventview.cpp index 114c696e0d9..e3dcedd8b0d 100644 --- a/src/plugins/qmlprofiler/qmlprofilereventview.cpp +++ b/src/plugins/qmlprofiler/qmlprofilereventview.cpp @@ -38,6 +38,9 @@ #include #include +#include +#include + #include #include @@ -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 diff --git a/src/plugins/qmlprofiler/qmlprofilereventview.h b/src/plugins/qmlprofiler/qmlprofilereventview.h index 952904f12d3..28ba21484e1 100644 --- a/src/plugins/qmlprofiler/qmlprofilereventview.h +++ b/src/plugins/qmlprofiler/qmlprofilereventview.h @@ -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); diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index d65472809ba..0dd55faea5a 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -169,15 +169,28 @@ IAnalyzerTool::ToolMode QmlProfilerTool::toolMode() const void QmlProfilerTool::showContextMenu(const QPoint &position) { + QmlProfilerEventsView *senderView = qobject_cast(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,