TreeModel: (Partially) separate header data from root item

Full separation does not seem possible as QTreeView assumes
all items to have equal column count.

Change-Id: Ia260924fe13ea62789923af8484f9838295355b6
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
hjk
2015-01-16 15:24:53 +01:00
parent c0c9a83409
commit ec187241e5
10 changed files with 62 additions and 67 deletions

View File

@@ -371,7 +371,6 @@ public:
: m_subKind(subKind), m_subSize(subSize), m_count(count), m_changed(false)
{}
int columnCount() const { return 2; }
QVariant data(int column, int role) const;
Qt::ItemFlags flags(int column) const
@@ -393,7 +392,6 @@ class RegisterItem : public Utils::TreeItem
public:
explicit RegisterItem(const Register &reg);
int columnCount() const { return 2; }
QVariant data(int column, int role) const;
Qt::ItemFlags flags(int column) const;
@@ -524,26 +522,11 @@ QVariant RegisterSubItem::data(int column, int role) const
//
//////////////////////////////////////////////////////////////////
class RegisterRootItem : public Utils::TreeItem
{
public:
int columnCount() const { return 2; }
QVariant data(int section, int role) const
{
if (role == Qt::DisplayRole) {
switch (section) {
case 0: return RegisterHandler::tr("Name");
case 1: return RegisterHandler::tr("Value");
};
}
return QVariant();
}
};
RegisterHandler::RegisterHandler()
{
setObjectName(QLatin1String("RegisterModel"));
setRootItem(new RegisterRootItem); // Needed to get two columns.
setHeader(QStringList() << tr("Name") << tr("Value"));
#if USE_REGISTER_MODEL_TEST
new ModelTest(this, 0);
#endif