/* * Copyright (c) 2015, University of Kaiserslautern * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Authors: * Janik Schlemminger * Robert Gernhardt * Matthias Jung */ #include "transactiontreewidget.h" #include "data/tracedb.h" #include #include #include using namespace std; TransactionTreeWidget::TransactionTreeWidget(QWidget *parent) : QTreeWidget(parent), isInitialized(false) { QObject::connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(ContextMenuRequested(QPoint))); setContextMenuPolicy(Qt::CustomContextMenu); goToTransaction = new QAction("Move to",this); } void TransactionTreeWidget::init(TraceNavigator *navigator) { Q_ASSERT(isInitialized == false); isInitialized = true; this->navigator = navigator; setColumnCount(3); setHeaderLabels(QStringList({"Transaction", "Value", "Value"})); } void TransactionTreeWidget::AppendTransaction(const shared_ptr &transaction) { QTreeWidgetItem *node = new TransactionTreeItem(this,transaction); addTopLevelItem(node); } void TransactionTreeWidget::ContextMenuRequested(QPoint point) { if(selectedItems().count() > 0 && selectedItems().at(0)->type() == TransactionTreeWidget::TransactionTreeItem::transactionTreeItemType) { QMenu contextMenu; contextMenu.addActions({goToTransaction}); QAction* selectedContextMenuItems = contextMenu.exec(mapToGlobal(point)); if(selectedContextMenuItems) { TransactionTreeItem *item = static_cast(selectedItems().at(0)); navigator->selectTransaction(item->Id()); } } } TransactionTreeWidget::TransactionTreeItem::TransactionTreeItem(QTreeWidget *parent, const shared_ptr &transaction) : QTreeWidgetItem(parent,transactionTreeItemType) { this->setText(0, QString::number(transaction->Id())); this->id = transaction->Id(); QTreeWidgetItem *time = new QTreeWidgetItem({"Timespan"}); AppendTimespan(time, transaction->Span()); this->addChild(time); this->addChild(new QTreeWidgetItem( {"Lenght", prettyFormatTime(transaction->Span().timeCovered())})); this->addChild(new QTreeWidgetItem( {"Channel", QString::number(transaction->Channel())})); this->addChild(new QTreeWidgetItem( {"Bank", QString::number(transaction->Bank())} )); this->addChild(new QTreeWidgetItem( {"Bankgroup", QString::number(transaction->BankGroup())} )); this->addChild(new QTreeWidgetItem( {"Row", QString::number(transaction->Row())} )); this->addChild(new QTreeWidgetItem( {"Column", QString::number(transaction->Column())} )); this->addChild(new QTreeWidgetItem( {"Address", QString("0x") + QString::number(transaction->Address(),16)} )); if(!transaction->isControllerInternal()) { this->addChild(new QTreeWidgetItem( {"Burstlength", QString::number(transaction->Burstlength())})); this->addChild(new QTreeWidgetItem( {"Thread", QString::number(transaction->Thread())})); } QTreeWidgetItem *phasesNode = new QTreeWidgetItem(this); phasesNode->setText(0,"Phases"); phasesNode->addChild(new QTreeWidgetItem( {"", "Begin", "End"} )); for(std::shared_ptr phase : transaction->Phases()) { AppendPhase(phasesNode, *phase); } } void TransactionTreeWidget::TransactionTreeItem::AppendPhase(QTreeWidgetItem *parent, const Phase &phase) { QTreeWidgetItem *node = new QTreeWidgetItem(parent); node->setText(0, phase.Name() + QString(" [") + QString::number(phase.Id()) + QString("]")); AppendTimespan(node, phase.Span()); } void TransactionTreeWidget::TransactionTreeItem::AppendTimespan(QTreeWidgetItem *parent, const Timespan ×pan) { parent->setText(1, prettyFormatTime(timespan.Begin())); parent->setText(2, prettyFormatTime(timespan.End())); }