Revision: 4539
http://tora.svn.sourceforge.net/tora/?rev=4539&view=rev
Author: ibre5041
Date: 2012-11-08 11:53:45 +0000 (Thu, 08 Nov 2012)
Log Message:
-----------
some sanity checks
Modified Paths:
--------------
branches/tora3/src/core/toworkspace.cpp
Modified: branches/tora3/src/core/toworkspace.cpp
===================================================================
--- branches/tora3/src/core/toworkspace.cpp 2012-11-08 11:40:43 UTC (rev 4538)
+++ branches/tora3/src/core/toworkspace.cpp 2012-11-08 11:53:45 UTC (rev 4539)
@@ -90,6 +90,7 @@
void toWorkSpace::addToolWidget(toToolWidget *toolWidget)
{
Q_ASSERT_X(!m_toolsRegistry.contains(toolWidget), qPrintable(__QHERE__), "Tool window already added");
+ // Create the tab and the stacked widget
ToolIndex i;
i.WidgetIndex = m_stackedWidget->addWidget(toolWidget);
i.TabBarIndex = m_tabBar->insertTab(m_tabBar->count(), toolWidget->windowTitle()); // note this emits currentIndexChanged
@@ -99,7 +100,8 @@
if (icon)
m_tabBar->setTabIcon(i.TabBarIndex, *icon);
- QVariant data = qVariantFromValue((void *) toolWidget);
+ // associate the tab with some usefull QVariant data
+ QVariant data = qVariantFromValue(static_cast<QWidget*>(toolWidget));
m_tabBar->setTabData(i.TabBarIndex, data);
if(m_lastWidget == NULL) // 0th tab was added (slotCurrentIndexChanged did nothing)
{
@@ -122,7 +124,8 @@
if(idx == -1)
return; // no tab opened
- toToolWidget *w = static_cast<toToolWidget*>(m_tabBar->tabData(idx).value<void*>());
+ QWidget *wp = m_tabBar->tabData(idx).value<QWidget*>();
+ toToolWidget *w = dynamic_cast<toToolWidget*>(wp);
if(w)
{
ToolIndex i = m_toolsRegistry.value(w);
@@ -154,7 +157,7 @@
{
m_label->setText(QString("%1 %2").arg(from).arg(to));
- toToolWidget *w = static_cast<toToolWidget*>(m_tabBar->tabData(to).value<void*>());
+ toToolWidget *w = dynamic_cast<toToolWidget*>(m_tabBar->tabData(to).value<QWidget*>());
if(!w)
return;
@@ -169,13 +172,9 @@
void toWorkSpace::slotTabCloseRequested(int idx)
{
- toToolWidget *w = static_cast<toToolWidget*>(m_tabBar->tabData(idx).value<void*>());
+ toToolWidget *w = dynamic_cast<toToolWidget*>(m_tabBar->tabData(idx).value<QWidget*>());
+ Q_ASSERT_X(w != NULL, qPrintable(__QHERE__), "Trying to close non-existing tab");
- if(!w)
- {
- throw QString("Trying to close non-existing tab %1").arg(idx);
- }
-
m_tabBar->setCurrentIndex(idx); // show tab before showing Save dialog
if(w->close())
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|