From aeab97f48ee6c260a3e2a21bca7a291ed1af8063 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Sun, 26 Jul 2009 19:05:52 +0100
Subject: Removing RosterItem and including in QtTreeWidgetItem.


diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
index 559f4e2..73ac86c 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.h
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -9,7 +9,6 @@
 #include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
 #include "Swift/QtUI/Roster/QtTreeWidget.h"
 #include "Swift/QtUI/Roster/RosterModel.h"
-#include "Swift/QtUI/Roster/RosterItem.h"
 
 namespace Swift {
 
diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
index f65c3bf..4ac2164 100644
--- a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
@@ -1,7 +1,45 @@
 #include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
 #include "Swift/QtUI/Roster/QtTreeWidget.h"
+
+#include <qdebug.h>
+
 namespace Swift {
 
+QtTreeWidgetItem::QtTreeWidgetItem(QtTreeWidgetItem* parentItem) : QObject() {
+	parent_ = parentItem;
+}
+
+void QtTreeWidgetItem::setText(const String& text) {
+	setName(P2QSTRING(text));
+}
+
+void QtTreeWidgetItem::setTextColor(unsigned long color) {
+	// QTreeWidgetItem::setTextColor(0, QColor(
+	// 					((color & 0xFF0000)>>16),
+	// 					((color & 0xFF00)>>8), 
+	// 					(color & 0xFF)));
+}
+
+void QtTreeWidgetItem::setBackgroundColor(unsigned long color) {
+	// QTreeWidgetItem::setBackgroundColor(0, QColor(
+	// 					((color & 0xFF0000)>>16),
+	// 					((color & 0xFF00)>>8), 
+	// 					(color & 0xFF)));
+}
+
+void QtTreeWidgetItem::setExpanded(bool b) {
+	//treeWidget()->setItemExpanded(this, b);
+}
+
+void QtTreeWidgetItem::hide() {
+	//setHidden(true);
+}
+
+void QtTreeWidgetItem::show() {
+	//setHidden(false);
+}
+
+
 QWidget* QtTreeWidgetItem::getCollapsedRosterWidget() {
 	QWidget* widget = new QWidget();
 	
@@ -14,4 +52,51 @@ QWidget* QtTreeWidgetItem::getExpandedRosterWidget() {
 	return widget;
 }
 
+QtTreeWidgetItem::~QtTreeWidgetItem() {
+	qDeleteAll(children_);
+}
+
+QtTreeWidgetItem* QtTreeWidgetItem::getParentItem() {
+	return parent_;
+}
+
+void QtTreeWidgetItem::addChild(QtTreeWidgetItem* child) {
+	printf("Boing\n");
+	children_.append(child);
+	connect(child, SIGNAL(changed()), this, SIGNAL(changed()));
+	emit changed();
+}
+
+int QtTreeWidgetItem::rowCount() {
+	qDebug() << "Returning size of " << children_.size() << " for item " << name_;
+	return children_.size();
+}
+
+int QtTreeWidgetItem::rowOf(QtTreeWidgetItem* item) {
+	return children_.indexOf(item);
+}
+
+int QtTreeWidgetItem::row() {
+	return parent_ ? parent_->rowOf(this) : 0;
+}
+
+QtTreeWidgetItem* QtTreeWidgetItem::getItem(int row) {
+	qDebug() << "Returning row " << row << " from item " << name_;
+	return children_[row];
+}
+
+QVariant QtTreeWidgetItem::data(int role) {
+	if (role != Qt::DisplayRole) {
+		return QVariant();
+	}
+	qDebug() << "Returning name " << name_ << " for role " << role;
+	return name_;
+}
+
+void QtTreeWidgetItem::setName(QString name) {
+	name_ = name;
+	qDebug() << "Name changed to " << name;
+	changed();
+}
+
 }
\ No newline at end of file
diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.h b/Swift/QtUI/Roster/QtTreeWidgetItem.h
index 2a72a83..202c44a 100644
--- a/Swift/QtUI/Roster/QtTreeWidgetItem.h
+++ b/Swift/QtUI/Roster/QtTreeWidgetItem.h
@@ -8,7 +8,6 @@
 #include "Swiften/Roster/TreeWidget.h"
 #include "Swiften/Roster/TreeWidgetItem.h"
 #include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
-#include "Swift/QtUI/Roster/RosterItem.h"
 
 
 #include "Swift/QtUI/QtSwiftUtil.h"
@@ -16,47 +15,36 @@
 
 namespace Swift {
 class QtTreeWidget;
-class QtTreeWidgetItem : public TreeWidgetItem, public RosterItem {
+class QtTreeWidgetItem : public QObject, public TreeWidgetItem {
+	Q_OBJECT
 	public:
-		QtTreeWidgetItem(RosterItem* parentItem) : RosterItem(parentItem) {
-
-		}
-
-		void setText(const String& text) {
-			setName(P2QSTRING(text));
-		}
-
-		void setTextColor(unsigned long color) {
-			// QTreeWidgetItem::setTextColor(0, QColor(
-			// 					((color & 0xFF0000)>>16),
-			// 					((color & 0xFF00)>>8), 
-			// 					(color & 0xFF)));
-		}
-
-		void setBackgroundColor(unsigned long color) {
-			// QTreeWidgetItem::setBackgroundColor(0, QColor(
-			// 					((color & 0xFF0000)>>16),
-			// 					((color & 0xFF00)>>8), 
-			// 					(color & 0xFF)));
-		}
-
-		void setExpanded(bool b) {
-			//treeWidget()->setItemExpanded(this, b);
-		}
-
-		void hide() {
-			//setHidden(true);
-		}
-
-		void show() {
-			//setHidden(false);
-		}
-		
-		QWidget* getCollapsedRosterWidget();
-		QWidget* getExpandedRosterWidget();
+			~QtTreeWidgetItem();
+			void addChild(QtTreeWidgetItem* child);
+			QtTreeWidgetItem* getParentItem();
+			int rowCount();
+			int rowOf(QtTreeWidgetItem* item);
+			int row();
+			QtTreeWidgetItem* getItem(int row);
+			QVariant data(int role);
+			void setName(QString name);
+			QtTreeWidgetItem(QtTreeWidgetItem* parentItem);
+			void setText(const String& text);
+			void setTextColor(unsigned long color);
+			void setBackgroundColor(unsigned long color);
+			void setExpanded(bool b);
+			void hide();
+			void show();
+
+			QWidget* getCollapsedRosterWidget();
+			QWidget* getExpandedRosterWidget();
 		
-	private:
-		QString displayName_;
+		signals:
+			void changed();
+		private:
+			QList<QtTreeWidgetItem*> children_;
+			QtTreeWidgetItem* parent_;
+			QString name_;
+			QString displayName_;
 };
 
 }
diff --git a/Swift/QtUI/Roster/Roster.pri b/Swift/QtUI/Roster/Roster.pri
index 56ff472..bc14889 100644
--- a/Swift/QtUI/Roster/Roster.pri
+++ b/Swift/QtUI/Roster/Roster.pri
@@ -1,11 +1,11 @@
 SOURCES += $$PWD/RosterDelegate.cpp \
-	$$PWD/RosterItem.cpp \
+#	$$PWD/RosterItem.cpp \
 	$$PWD/RosterModel.cpp \
 	$$PWD/QtTreeWidget.cpp \
 	$$PWD/QtTreeWidgetItem.cpp 
 
 HEADERS += $$PWD/RosterDelegate.h \
-	$$PWD/RosterItem.h \
+#	$$PWD/RosterItem.h \
 	$$PWD/RosterModel.h \
 	$$PWD/QtTreeWidget.h \
 	$$PWD/QtTreeWidgetFactory.h \
diff --git a/Swift/QtUI/Roster/RosterItem.cpp b/Swift/QtUI/Roster/RosterItem.cpp
deleted file mode 100644
index b39a47c..0000000
--- a/Swift/QtUI/Roster/RosterItem.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include "RosterItem.h"
-
-#include <qdebug.h>
-
-namespace Swift {
-	
-RosterItem::RosterItem(RosterItem* parent) : QObject() {
-	parent_ = parent;
-}
-
-RosterItem::~RosterItem() {
-	qDeleteAll(children_);
-}
-
-RosterItem* RosterItem::getParentItem() {
-	return parent_;
-}
-
-void RosterItem::addChild(RosterItem* child) {
-	printf("Boing\n");
-	children_.append(child);
-	connect(child, SIGNAL(changed()), this, SIGNAL(changed()));
-	emit changed();
-}
-
-int RosterItem::rowCount() {
-	qDebug() << "Returning size of " << children_.size() << " for item " << name_;
-	return children_.size();
-}
-
-int RosterItem::rowOf(RosterItem* item) {
-	return children_.indexOf(item);;
-}
-
-int RosterItem::row() {
-	return parent_ ? parent_->rowOf(this) : 0;
-}
-
-RosterItem* RosterItem::getItem(int row) {
-	qDebug() << "Returning row " << row << " from item " << name_;
-	return children_[row];
-}
-
-QVariant RosterItem::data(int role) {
-	if (role != Qt::DisplayRole) {
-		return QVariant();
-	}
-	qDebug() << "Returning name " << name_ << " for role " << role;
-	return name_;
-}
-
-void RosterItem::setName(QString name) {
-	name_ = name;
-	qDebug() << "Name changed to " << name;
-	changed();
-}
-}
\ No newline at end of file
diff --git a/Swift/QtUI/Roster/RosterItem.h b/Swift/QtUI/Roster/RosterItem.h
deleted file mode 100644
index e0041d2..0000000
--- a/Swift/QtUI/Roster/RosterItem.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#pragma once
-
-#include <QList>
-#include <QVariant>
-namespace Swift {
-	class RosterItem : public QObject {
-	Q_OBJECT
-	public:
-		RosterItem(RosterItem* parent);
-		~RosterItem();
-		void addChild(RosterItem* child);
-		RosterItem* getParentItem();
-		int rowCount();
-		int rowOf(RosterItem* item);
-		int row();
-		RosterItem* getItem(int row);
-		QVariant data(int role);
-		void setName(QString name);
-	signals:
-		void changed();
-	private:
-		QList<RosterItem*> children_;
-		RosterItem* parent_;
-		QString name_;
-	};
-	
-}
\ No newline at end of file
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
index 4c5954e..147aa67 100644
--- a/Swift/QtUI/Roster/RosterModel.cpp
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -9,7 +9,7 @@ RosterModel::~RosterModel() {
 	delete tree_;
 }
 
-void RosterModel::setRoot(RosterItem* root) {
+void RosterModel::setRoot(QtTreeWidgetItem* root) {
 	tree_ = root;
 	connect(tree_, SIGNAL(changed()), this, SLOT(handleItemChanged()));
 }
@@ -29,12 +29,12 @@ int RosterModel::columnCount(const QModelIndex& parent) const {
 }
 
 QVariant RosterModel::data(const QModelIndex& index, int role) const {
-	RosterItem* item = index.isValid() ? static_cast<RosterItem*>(index.internalPointer()) : NULL;
+	QtTreeWidgetItem* item = index.isValid() ? static_cast<QtTreeWidgetItem*>(index.internalPointer()) : NULL;
 	return item ? item->data(role) : QVariant();
 }
 
 QModelIndex RosterModel::index(int row, int column, const QModelIndex& parent) const {
-	RosterItem* parentItem = parent.isValid() ? static_cast<RosterItem*>(parent.internalPointer()) : tree_;
+	QtTreeWidgetItem* parentItem = parent.isValid() ? static_cast<QtTreeWidgetItem*>(parent.internalPointer()) : tree_;
 	Q_ASSERT(parentItem);
 	
 	return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex();
@@ -45,16 +45,16 @@ QModelIndex RosterModel::parent(const QModelIndex& index) const {
 		return QModelIndex();
 	}
 	
-	RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+	QtTreeWidgetItem* item = static_cast<QtTreeWidgetItem*>(index.internalPointer());
 	Q_ASSERT(item);
 
-	RosterItem* parentItem = item->getParentItem();
+	QtTreeWidgetItem* parentItem = item->getParentItem();
 	return parentItem == tree_ ? QModelIndex() : createIndex(parentItem->row(), 0, parentItem);
 
 }
 
 int RosterModel::rowCount(const QModelIndex& parent) const {
-	RosterItem* item = parent.isValid() ? static_cast<RosterItem*>(parent.internalPointer()) : tree_;
+	QtTreeWidgetItem* item = parent.isValid() ? static_cast<QtTreeWidgetItem*>(parent.internalPointer()) : tree_;
 	Q_ASSERT(item);
 	
 	return item->rowCount();
diff --git a/Swift/QtUI/Roster/RosterModel.h b/Swift/QtUI/Roster/RosterModel.h
index fbede32..e75bc2f 100644
--- a/Swift/QtUI/Roster/RosterModel.h
+++ b/Swift/QtUI/Roster/RosterModel.h
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "Swift/QtUI/Roster/RosterItem.h"
+#include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
 
 #include <QAbstractItemModel>
 #include <QList>
@@ -11,7 +11,7 @@ Q_OBJECT
 public:
 	RosterModel();
 	~RosterModel();
-	void setRoot(RosterItem* tree);
+	void setRoot(QtTreeWidgetItem* tree);
 	int columnCount(const QModelIndex& parent = QModelIndex()) const;
 	QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
 	QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
@@ -20,7 +20,7 @@ public:
 private slots:
 	void handleItemChanged();
 private:
-	RosterItem* tree_;
+	QtTreeWidgetItem* tree_;
 };
 
 }
\ No newline at end of file
-- 
cgit v0.10.2-6-g49f6