From 927c77ac25639055065d91f31c05f956f571ce0c Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Fri, 27 Jan 2012 18:31:02 +0300 Subject: [PATCH] Code refactoring: pointers instead of names in Palettes --- src/board/UBBoardPaletteManager.cpp | 13 +++++--- src/gui/UBCachePropertiesWidget.cpp | 8 ++--- src/gui/UBDockPalette.cpp | 50 +++++++++++------------------ src/gui/UBDockPalette.h | 7 ++-- src/gui/UBDockPaletteWidget.h | 4 +-- 5 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index 4c79f726..8c20d89a 100644 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -202,8 +202,11 @@ void UBBoardPaletteManager::setupDockPaletteWidgets() // The cache widget will be visible only if a cache is put on the page mRightPalette->registerWidget(mpCachePropWidget); // The teacher bar widget will always be there - mRightPalette->registerWidget(mpTeacherBarWidget); - mRightPalette->addTab(mpTeacherBarWidget); + + // TeacherBarWidget moved to left side just for testing!!!! + mLeftPalette->registerWidget(mpTeacherBarWidget); + mLeftPalette->addTab(mpTeacherBarWidget); + // The download widget will be part of the right palette but // will become visible only when the first download starts mRightPalette->registerWidget(mpDownloadWidget); @@ -211,8 +214,8 @@ void UBBoardPaletteManager::setupDockPaletteWidgets() changeMode(eUBDockPaletteWidget_BOARD, true); // Hide the tabs that must be hidden - mRightPalette->removeTab(mpDownloadWidget->name()); - mRightPalette->removeTab(mpCachePropWidget->name()); + mRightPalette->removeTab(mpDownloadWidget); + mRightPalette->removeTab(mpCachePropWidget); // mLeftPalette->showTabWidget(0); // mRightPalette->showTabWidget(0); @@ -998,7 +1001,7 @@ void UBBoardPaletteManager::stopDownloads() { mDownloadInProgress = false; mpDownloadWidget->setVisibleState(false); - mRightPalette->removeTab(mpDownloadWidget->name()); + mRightPalette->removeTab(mpDownloadWidget); } } diff --git a/src/gui/UBCachePropertiesWidget.cpp b/src/gui/UBCachePropertiesWidget.cpp index 751c5d15..e0c74986 100644 --- a/src/gui/UBCachePropertiesWidget.cpp +++ b/src/gui/UBCachePropertiesWidget.cpp @@ -222,7 +222,7 @@ void UBCachePropertiesWidget::onCloseClicked() emit cacheListEmpty(); } - emit hideTab(name()); + emit hideTab(this); } } @@ -300,7 +300,7 @@ void UBCachePropertiesWidget::updateCurrentCache() if("Cache" == it->data(Qt::UserRole).toString()) { setEnabled(true); - emit showTab(name()); + emit showTab(this); mpCurrentCache = dynamic_cast(it); if((NULL != mpCurrentCache) && (!mCaches.contains(mpCurrentCache))) { @@ -331,7 +331,7 @@ void UBCachePropertiesWidget::updateCurrentCache() // 1 - that this page has no cache // 2 - we are not in Board mode // 3 - we are in Board mode, but show desktop (as really - Desktop mode) - emit hideTab(name()); + emit hideTab(this); mpCurrentCache = NULL; setDisabled(true); } @@ -346,6 +346,6 @@ void UBCachePropertiesWidget::onSizeChanged(int newSize) void UBCachePropertiesWidget::onCacheEnabled() { - emit showTab(name()); + emit showTab(this); } diff --git a/src/gui/UBDockPalette.cpp b/src/gui/UBDockPalette.cpp index 7c3cb27e..82f28d76 100644 --- a/src/gui/UBDockPalette.cpp +++ b/src/gui/UBDockPalette.cpp @@ -567,19 +567,15 @@ void UBDockPalette::addTab(UBDockPaletteWidget *widget) * \brief Remove the given tab * @param widgetName as the tab widget name */ -void UBDockPalette::removeTab(const QString &widgetName) +void UBDockPalette::removeTab(UBDockPaletteWidget* widget) { - for(int i = 0; i < mTabWidgets.size(); i++) + int nWidget = mTabWidgets.indexOf(widget); + if( nWidget >= 0 ) { - UBDockPaletteWidget* pCrntWidget = mTabWidgets.at(i); - if(NULL != pCrntWidget && (pCrntWidget->name() == widgetName)) - { - mpStackWidget->removeWidget(pCrntWidget); - mTabWidgets.remove(i); - pCrntWidget->hide(); - update(); - break; - } + mpStackWidget->removeWidget(widget); + mTabWidgets.remove(nWidget); + widget->hide(); + update(); } resizeTabs(); mCurrentTab = qMax(mCurrentTab - 1, 0); @@ -607,17 +603,12 @@ int UBDockPalette::tabSpacing() * \brief Show the given widget * @param widgetName as the given widget name */ -void UBDockPalette::onShowTabWidget(const QString &widgetName) +void UBDockPalette::onShowTabWidget(UBDockPaletteWidget* widget) { - for(int i = 0; i < mRegisteredWidgets.size(); i++) + if (mRegisteredWidgets.contains(widget)) { - UBDockPaletteWidget* pCrntWidget = mRegisteredWidgets.at(i); - if(NULL != pCrntWidget && (pCrntWidget->name() == widgetName)) - { - pCrntWidget->setVisibleState(true); - addTab(pCrntWidget); - break; - } + widget->setVisibleState(true); + addTab(widget); } } @@ -625,16 +616,13 @@ void UBDockPalette::onShowTabWidget(const QString &widgetName) * \brief Hide the given widget * @param widgetName as the given widget name */ -void UBDockPalette::onHideTabWidget(const QString &widgetName) +void UBDockPalette::onHideTabWidget(UBDockPaletteWidget* widget) { - for(int i = 0; i < mRegisteredWidgets.size(); i++){ - UBDockPaletteWidget* pCrntWidget = mRegisteredWidgets.at(i); - if(NULL != pCrntWidget && (pCrntWidget->name() == widgetName)){ - pCrntWidget->setVisibleState(false); - break; - } + if (mRegisteredWidgets.contains(widget)) + { + widget->setVisibleState(false); + removeTab(widget); } - removeTab(widgetName); } /** @@ -644,8 +632,8 @@ void UBDockPalette::connectSignals() { for(int i=0; i < mRegisteredWidgets.size(); i++) { - connect(mRegisteredWidgets.at(i), SIGNAL(showTab(QString)), this, SLOT(onShowTabWidget(QString))); - connect(mRegisteredWidgets.at(i), SIGNAL(hideTab(QString)), this, SLOT(onHideTabWidget(QString))); + connect(mRegisteredWidgets.at(i), SIGNAL(showTab(UBDockPaletteWidget*)), this, SLOT(onShowTabWidget(UBDockPaletteWidget*))); + connect(mRegisteredWidgets.at(i), SIGNAL(hideTab(UBDockPaletteWidget*)), this, SLOT(onHideTabWidget(UBDockPaletteWidget*))); } } @@ -747,7 +735,7 @@ bool UBDockPalette::switchMode(eUBDockPaletteWidgetMode mode) } else { - removeTab(pNextWidget->name()); + removeTab(pNextWidget); } } } diff --git a/src/gui/UBDockPalette.h b/src/gui/UBDockPalette.h index 569c9854..ff3b546d 100644 --- a/src/gui/UBDockPalette.h +++ b/src/gui/UBDockPalette.h @@ -111,8 +111,9 @@ public: void setBackgroundBrush(const QBrush& brush); void registerWidget(UBDockPaletteWidget* widget); + void addTab(UBDockPaletteWidget* widget); - void removeTab(const QString& widgetName); + void removeTab(UBDockPaletteWidget* widget); void connectSignals(); @@ -129,8 +130,8 @@ public: eUBDockPaletteType paletteType(){return mPaletteType;} public slots: - void onShowTabWidget(const QString& widgetName); - void onHideTabWidget(const QString& widgetName); + void onShowTabWidget(UBDockPaletteWidget* widget); + void onHideTabWidget(UBDockPaletteWidget* widget); void onAllDownloadsFinished(); protected: diff --git a/src/gui/UBDockPaletteWidget.h b/src/gui/UBDockPaletteWidget.h index 163ca0cd..0b69a9e6 100644 --- a/src/gui/UBDockPaletteWidget.h +++ b/src/gui/UBDockPaletteWidget.h @@ -31,8 +31,8 @@ public: void setVisibleState(bool state){mVisibleState = state;} signals: - void hideTab(const QString& widgetName); - void showTab(const QString& widgetName); + void hideTab(UBDockPaletteWidget* widget); + void showTab(UBDockPaletteWidget* widget); public slots: void slot_changeMode(eUBDockPaletteWidgetMode newMode);