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. ** 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 "../valgrind_global.h"
#include <QtGui/QAbstractItemView>
namespace Valgrind { namespace Valgrind {
namespace Callgrind { namespace Callgrind {
class ParseData; class ParseData;
class VALGRINDSHARED_EXPORT AbstractModel { enum AbstractModelRoles
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 {
ParentCostRole = Qt::UserRole, ParentCostRole = Qt::UserRole,
RelativeTotalCostRole, RelativeTotalCostRole,
RelativeParentCostRole, RelativeParentCostRole,
NextCustomRole NextCustomRole
};
}; };
} // Callgrind } // Callgrind

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -60,7 +60,7 @@ void CallgrindTextMark::paint(QPainter *painter, const QRect &paintRect) const
return; return;
bool ok; 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(ok, return)
QTC_ASSERT(costs >= 0.0 && costs <= 100.0, return) QTC_ASSERT(costs >= 0.0 && costs <= 100.0, return)