callgrind: simplify inheritance tree by removing AbstractModel

This commit is contained in:
hjk
2011-04-05 11:11:57 +02:00
parent faf3d5d34d
commit 223d3ca962
10 changed files with 28 additions and 102 deletions

View File

@@ -30,23 +30,3 @@
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "callgrindparsedata.h"
#include "callgrinddatamodel.h"
namespace Valgrind {
namespace Callgrind {
AbstractModel::AbstractModel()
{
}
AbstractModel::~AbstractModel()
{
}
} // Callgrind
} // Valgrind

View File

@@ -36,37 +36,19 @@
#include "../valgrind_global.h"
#include <QtGui/QAbstractItemView>
namespace Valgrind {
namespace Callgrind {
class ParseData;
class VALGRINDSHARED_EXPORT AbstractModel {
public:
AbstractModel();
virtual ~AbstractModel();
virtual void setParseData(const ParseData *data) = 0;
virtual const ParseData *parseData() const = 0;
/// Only one cost event column will be shown, this decides which one it is.
/// By default it is the first event in the @c ParseData, i.e. 0.
virtual int costEvent() const = 0;
//BEGIN SLOTS
virtual void setCostEvent(int event) = 0;
//END SLOTS
//BEGIN SIGNALS
virtual void parseDataChanged(AbstractModel *model) = 0;
//END SIGNALS
enum Roles {
enum AbstractModelRoles
{
ParentCostRole = Qt::UserRole,
RelativeTotalCostRole,
RelativeParentCostRole,
NextCustomRole
};
};
} // Callgrind

View File

@@ -69,10 +69,8 @@ CallModel::Private::Private()
//BEGIN CallModel
CallModel::CallModel(QObject *parent)
: QAbstractItemModel(parent)
, d(new Private)
: QAbstractItemModel(parent), d(new Private)
{
}
CallModel::~CallModel()
@@ -125,7 +123,6 @@ void CallModel::setParseData(const ParseData *data)
clear();
d->m_data = data;
emit parseDataChanged(this);
}
const ParseData *CallModel::parseData() const

View File

@@ -50,12 +50,11 @@ class Function;
/**
* Model to display list of function calls.
*/
class VALGRINDSHARED_EXPORT CallModel : public QAbstractItemModel, public AbstractModel
class VALGRINDSHARED_EXPORT CallModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit CallModel(QObject *parent = 0);
explicit CallModel(QObject *parent);
virtual ~CallModel();
void clear();
@@ -63,6 +62,7 @@ public:
/// Only one cost event column will be shown, this decides which one it is.
/// By default it is the first event in the @c ParseData, i.e. 0.
virtual int costEvent() const;
virtual void setCostEvent(int event);
virtual void setParseData(const ParseData *data);
virtual const ParseData *parseData() const;
@@ -87,17 +87,9 @@ public:
};
enum Roles {
FunctionCallRole = AbstractModel::NextCustomRole
FunctionCallRole = NextCustomRole
};
public slots:
/// Only one cost event column will be shown, this decides which one it is.
/// By default it is the first event in the @c ParseData, i.e. 0.
void setCostEvent(int event);
signals:
void parseDataChanged(AbstractModel *model);
private:
class Private;
Private *d;

View File

@@ -108,8 +108,7 @@ void DataModel::Private::updateFunctions()
//BEGIN DataModel
DataModel::DataModel(QObject *parent)
: QAbstractItemModel(parent)
, d(new Private)
: QAbstractItemModel(parent), d(new Private)
{
}
@@ -129,7 +128,6 @@ void DataModel::setParseData(const ParseData *data)
d->m_event = 0;
d->updateFunctions();
endResetModel();
emit parseDataChanged(this);
}
const ParseData *DataModel::parseData() const

View File

@@ -47,12 +47,12 @@ namespace Callgrind {
class Function;
class ParseData;
class VALGRINDSHARED_EXPORT DataModel : public QAbstractItemModel, public AbstractModel
class VALGRINDSHARED_EXPORT DataModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit DataModel(QObject *parent = 0);
explicit DataModel(QObject *parent);
virtual ~DataModel();
virtual void setParseData(const ParseData *data);
@@ -82,7 +82,7 @@ public:
};
enum Roles {
FunctionRole = AbstractModel::NextCustomRole,
FunctionRole = NextCustomRole,
LineNumberRole,
FileNameRole
};
@@ -95,9 +95,6 @@ public slots:
/// By default it is the first event in the @c ParseData, i.e. 0.
virtual void setCostEvent(int event);
signals:
void parseDataChanged(AbstractModel *model);
private:
class Private;
Private *d;

View File

@@ -51,13 +51,12 @@ using namespace Valgrind::Callgrind;
namespace Callgrind {
namespace Internal {
//BEGIN CostDelegate::Private
class CostDelegate::Private {
class CostDelegate::Private
{
public:
Private();
~Private();
Valgrind::Callgrind::AbstractModel *m_model;
QAbstractItemModel *m_model;
CostDelegate::CostFormat m_format;
static int toNativeRole(CostFormat format);
@@ -69,12 +68,6 @@ CostDelegate::Private::Private()
: m_model(0)
, m_format(CostDelegate::FormatAbsolute)
{
}
CostDelegate::Private::~Private()
{
}
int CostDelegate::Private::toNativeRole(CostDelegate::CostFormat format)
@@ -83,9 +76,9 @@ int CostDelegate::Private::toNativeRole(CostDelegate::CostFormat format)
{
case FormatAbsolute:
case FormatRelative:
return Valgrind::Callgrind::AbstractModel::RelativeTotalCostRole;
return Valgrind::Callgrind::RelativeTotalCostRole;
case FormatRelativeToParent:
return Valgrind::Callgrind::AbstractModel::RelativeParentCostRole;
return Valgrind::Callgrind::RelativeParentCostRole;
default:
return -1;
}
@@ -129,7 +122,7 @@ CostDelegate::~CostDelegate()
delete d;
}
void CostDelegate::setModel(Valgrind::Callgrind::AbstractModel *model)
void CostDelegate::setModel(QAbstractItemModel *model)
{
d->m_model = model;
}

View File

@@ -36,16 +36,9 @@
#include <QtGui/QStyledItemDelegate>
namespace Valgrind {
namespace Callgrind {
class AbstractModel;
}
}
namespace Callgrind {
namespace Internal {
class CostDelegate : public QStyledItemDelegate
{
Q_OBJECT
@@ -58,7 +51,7 @@ public:
const QModelIndex &index) const;
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setModel(Valgrind::Callgrind::AbstractModel *model);
void setModel(QAbstractItemModel *model);
enum CostFormat {
/// show absolute numbers
@@ -77,7 +70,6 @@ private:
Private *d;
};
} // Internal
} // Callgrind

View File

@@ -96,12 +96,7 @@ void CostView::setModel(QAbstractItemModel *model)
{
QTreeView::setModel(model);
AbstractModel *abstractModel = 0;
forever {
abstractModel = dynamic_cast<AbstractModel *>(model);
if (abstractModel)
break;
QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(model);
if (proxy)
model = proxy->sourceModel();
@@ -114,7 +109,7 @@ void CostView::setModel(QAbstractItemModel *model)
headerView->setResizeMode(QHeaderView::Interactive);
headerView->setStretchLastSection(false);
if (dynamic_cast<CallModel *>(abstractModel)) {
if (qobject_cast<CallModel *>(model)) {
setItemDelegateForColumn(CallModel::CostColumn, d->m_costDelegate);
headerView->setResizeMode(CallModel::CostColumn, QHeaderView::ResizeToContents);
headerView->setResizeMode(CallModel::CallsColumn, QHeaderView::ResizeToContents);
@@ -122,7 +117,7 @@ void CostView::setModel(QAbstractItemModel *model)
setItemDelegateForColumn(CallModel::CalleeColumn, d->m_nameDelegate);
headerView->setResizeMode(CallModel::CallerColumn, QHeaderView::Stretch);
setItemDelegateForColumn(CallModel::CallerColumn, d->m_nameDelegate);
} else if(dynamic_cast<DataModel *>(abstractModel)) {
} else if (qobject_cast<DataModel *>(model)) {
setItemDelegateForColumn(DataModel::SelfCostColumn, d->m_costDelegate);
headerView->setResizeMode(DataModel::SelfCostColumn, QHeaderView::ResizeToContents);
setItemDelegateForColumn(DataModel::InclusiveCostColumn, d->m_costDelegate);
@@ -132,7 +127,7 @@ void CostView::setModel(QAbstractItemModel *model)
headerView->setResizeMode(DataModel::LocationColumn, QHeaderView::Stretch);
}
d->m_costDelegate->setModel(abstractModel);
d->m_costDelegate->setModel(model);
}
void CostView::setCostFormat(CostDelegate::CostFormat format)

View File

@@ -60,7 +60,7 @@ void CallgrindTextMark::paint(QPainter *painter, const QRect &paintRect) const
return;
bool ok;
qreal costs = m_modelIndex.data(DataModel::RelativeTotalCostRole).toReal(&ok);
qreal costs = m_modelIndex.data(RelativeTotalCostRole).toReal(&ok);
QTC_ASSERT(ok, return)
QTC_ASSERT(costs >= 0.0 && costs <= 100.0, return)