Sanified multiple inheritance for AbstractChatView.
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 5 Apr 2008 21:34:54 +0000 (21:34 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 5 Apr 2008 21:34:54 +0000 (21:34 +0000)
src/qtui/bufferwidget.cpp
src/qtui/bufferwidget.h
src/uisupport/abstractbuffercontainer.cpp
src/uisupport/abstractbuffercontainer.h
version.inc

index a670705..4158311 100644 (file)
@@ -37,24 +37,28 @@ BufferWidget::~BufferWidget() {
 }
 
 AbstractChatView *BufferWidget::createChatView(BufferId id) {
 }
 
 AbstractChatView *BufferWidget::createChatView(BufferId id) {
-  AbstractChatView *chatView;
+  QWidget *chatView;
   if(Global::SPUTDEV) {
     chatView = new ChatView(Client::buffer(id), this);
   } else {
     chatView = new ChatWidget(id, this);
   }
   if(Global::SPUTDEV) {
     chatView = new ChatView(Client::buffer(id), this);
   } else {
     chatView = new ChatWidget(id, this);
   }
-  ui.stackedWidget->addWidget(dynamic_cast<QWidget *>(chatView));
-  dynamic_cast<QWidget *>(chatView)->setFocusProxy(this);
-  return chatView;
+  _chatViews[id] = chatView;
+  ui.stackedWidget->addWidget(chatView);
+  chatView->setFocusProxy(this);
+  return dynamic_cast<AbstractChatView*>(chatView);
 }
 
 }
 
-void BufferWidget::removeChatView(AbstractChatView *view) {
-  ui.stackedWidget->removeWidget(dynamic_cast<QWidget *>(view));
-  dynamic_cast<QWidget *>(view)->deleteLater();
+void BufferWidget::removeChatView(BufferId id) {
+  QWidget *view = _chatViews.value(id, 0);
+  if(!view) return;
+  ui.stackedWidget->removeWidget(view);
+  view->deleteLater();
+  _chatViews.take(id);
 }
 
 }
 
-void BufferWidget::showChatView(AbstractChatView *view) {
-  if(!view) ui.stackedWidget->setCurrentWidget(ui.page);
-  else ui.stackedWidget->setCurrentWidget(dynamic_cast<QWidget *>(view));
+void BufferWidget::showChatView(BufferId id) {
+  if(!id.isValid()) ui.stackedWidget->setCurrentWidget(ui.page);
+  else ui.stackedWidget->setCurrentWidget(_chatViews.value(id));
 }
 
 }
 
index 17e939d..4d9bf56 100644 (file)
@@ -34,14 +34,14 @@ class BufferWidget : public AbstractBufferContainer {
 
   protected:
     virtual AbstractChatView *createChatView(BufferId);
 
   protected:
     virtual AbstractChatView *createChatView(BufferId);
-    virtual void removeChatView(AbstractChatView *view);
+    virtual void removeChatView(BufferId);
 
   protected slots:
 
   protected slots:
-    virtual void showChatView(AbstractChatView *view);
+    virtual void showChatView(BufferId);
 
   private:
     Ui::BufferWidget ui;
 
   private:
     Ui::BufferWidget ui;
-
+    QHash<BufferId, QWidget *> _chatViews;
 };
 
 #endif
 };
 
 #endif
index 78ead27..1444027 100644 (file)
@@ -42,13 +42,10 @@ void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, in
     if(model()->rowCount(parent) != end - start + 1)
       return;
 
     if(model()->rowCount(parent) != end - start + 1)
       return;
 
-    AbstractChatView *chatView;
-    QHash<BufferId, AbstractChatView *>::iterator iter = _chatViews.begin();
-    while(iter != _chatViews.end()) {
-      chatView = *iter;
-      iter = _chatViews.erase(iter);
-      removeChatView(chatView);
+    foreach(BufferId id, _chatViews.keys()) {
+      removeChatView(id);
     }
     }
+    _chatViews.clear();
   } else {
     // check if there are explicitly buffers removed
     for(int i = start; i <= end; i++) {
   } else {
     // check if there are explicitly buffers removed
     for(int i = start; i <= end; i++) {
@@ -63,19 +60,21 @@ void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, in
 }
 
 void AbstractBufferContainer::removeBuffer(BufferId bufferId) {
 }
 
 void AbstractBufferContainer::removeBuffer(BufferId bufferId) {
+  if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false);
   if(!_chatViews.contains(bufferId))
     return;
 
   if(!_chatViews.contains(bufferId))
     return;
 
-  if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false);
-  AbstractChatView *chatView = _chatViews.take(bufferId);
-  removeChatView(chatView);
+  removeChatView(bufferId);
+  _chatViews.take(bufferId);
 }
 
 void AbstractBufferContainer::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
   BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
   BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
 }
 
 void AbstractBufferContainer::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
   BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
   BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
-  if(newBufferId != oldBufferId)
+  if(newBufferId != oldBufferId) {
     setCurrentBuffer(newBufferId);
     setCurrentBuffer(newBufferId);
+    emit currentChanged(newBufferId);
+  }
 }
 
 void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) {
 }
 
 void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) {
@@ -102,7 +101,7 @@ void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) {
     _chatViews[bufferId] = chatView;
   }
   _currentBuffer = bufferId;
     _chatViews[bufferId] = chatView;
   }
   _currentBuffer = bufferId;
-  showChatView(chatView);
+  showChatView(bufferId);
   buf->setVisible(true);
   setFocus();
 }
   buf->setVisible(true);
   setFocus();
 }
index a8c5055..cb0e502 100644 (file)
@@ -37,6 +37,9 @@ class AbstractBufferContainer : public AbstractItemView {
 
     inline BufferId currentBuffer() const { return _currentBuffer; }
 
 
     inline BufferId currentBuffer() const { return _currentBuffer; }
 
+  signals:
+    void currentChanged(BufferId);
+
   protected:
     //! Create an AbstractChatView for the given BufferId and add it to the UI if necessary
     virtual AbstractChatView *createChatView(BufferId) = 0;
   protected:
     //! Create an AbstractChatView for the given BufferId and add it to the UI if necessary
     virtual AbstractChatView *createChatView(BufferId) = 0;
@@ -46,7 +49,7 @@ class AbstractBufferContainer : public AbstractItemView {
      *  It also shall delete the object afterwards.
      * \param view The chat view to be removed and deleted
      */
      *  It also shall delete the object afterwards.
      * \param view The chat view to be removed and deleted
      */
-    virtual void removeChatView(AbstractChatView *view) = 0;
+    virtual void removeChatView(BufferId) = 0;
 
   protected slots:
     virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
 
   protected slots:
     virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
@@ -57,7 +60,7 @@ class AbstractBufferContainer : public AbstractItemView {
      *  selecting the appropriate page in a QStackedWidget.
      * \param view The chat view to be displayed. May be 0 if no chat view is selected.
      */
      *  selecting the appropriate page in a QStackedWidget.
      * \param view The chat view to be displayed. May be 0 if no chat view is selected.
      */
-    virtual void showChatView(AbstractChatView *view) = 0;
+    virtual void showChatView(BufferId) = 0;
 
   private slots:
     void appendMsg(AbstractUiMsg *);
 
   private slots:
     void appendMsg(AbstractUiMsg *);
@@ -77,6 +80,7 @@ class AbstractChatView {
     virtual void appendMsg(AbstractUiMsg *msg) = 0;
     virtual void prependMsg(AbstractUiMsg *msg) = 0;
     virtual void setContents(const QList<AbstractUiMsg *> &contents) = 0;
     virtual void appendMsg(AbstractUiMsg *msg) = 0;
     virtual void prependMsg(AbstractUiMsg *msg) = 0;
     virtual void setContents(const QList<AbstractUiMsg *> &contents) = 0;
+    //virtual BufferId bufferId() const = 0;
 
 };
 
 
 };
 
index e45335a..abdc3f7 100644 (file)
@@ -5,7 +5,7 @@
 
   quasselVersion = "0.2.0-alpha5-pre";
   quasselDate = "2008-04-05";
 
   quasselVersion = "0.2.0-alpha5-pre";
   quasselDate = "2008-04-05";
-  quasselBuild = 702;
+  quasselBuild = 706;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 642;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 642;