void TilesetDock::tilesetAdded(int index, Tileset *tileset) { TilesetView *view = new TilesetView; view->setMapDocument(mMapDocument); view->setZoomable(mZoomable); mTilesets.insert(index, tileset->sharedPointer()); mTabBar->insertTab(index, tileset->name()); mViewStack->insertWidget(index, view); updateActions(); }
void TilesetDock::setMapDocument(MapDocument *mapDocument) { if (mMapDocument == mapDocument) return; // Hide while we update the tab bar, to avoid repeated layouting widget()->hide(); setCurrentTiles(0); if (mMapDocument) { // Remember the last visible tileset for this map const QString tilesetName = mTabBar->tabText(mTabBar->currentIndex()); mCurrentTilesets.insert(mMapDocument, tilesetName); } // Clear previous content while (mTabBar->count()) mTabBar->removeTab(0); while (mViewStack->count()) delete mViewStack->widget(0); mTilesets.clear(); // Clear all connections to the previous document if (mMapDocument) mMapDocument->disconnect(this); mMapDocument = mapDocument; if (mMapDocument) { mTilesets = mMapDocument->map()->tilesets(); foreach (Tileset *tileset, mTilesets) { TilesetView *view = new TilesetView; view->setMapDocument(mMapDocument); view->setZoomable(mZoomable); mTabBar->addTab(tileset->name()); mViewStack->addWidget(view); } connect(mMapDocument, SIGNAL(tilesetAdded(int,Tileset*)), SLOT(tilesetAdded(int,Tileset*))); connect(mMapDocument, SIGNAL(tilesetRemoved(Tileset*)), SLOT(tilesetRemoved(Tileset*))); connect(mMapDocument, SIGNAL(tilesetMoved(int,int)), SLOT(tilesetMoved(int,int))); connect(mMapDocument, SIGNAL(tilesetNameChanged(Tileset*)), SLOT(tilesetNameChanged(Tileset*))); connect(mMapDocument, SIGNAL(tilesetFileNameChanged(Tileset*)), SLOT(updateActions())); QString cacheName = mCurrentTilesets.take(mMapDocument); for (int i = 0; i < mTabBar->count(); ++i) { if (mTabBar->tabText(i) == cacheName) { mTabBar->setCurrentIndex(i); break; } } }
void TilesetDock::setMapDocument(MapDocument *mapDocument) { if (mMapDocument == mapDocument) return; // Hide while we update the tab bar, to avoid repeated layouting // But, this causes problems on OS X (issue #1055) #ifndef Q_OS_OSX widget()->hide(); #endif setCurrentTiles(nullptr); setCurrentTile(nullptr); if (mMapDocument) { // Remember the last visible tileset for this map const QString tilesetName = mTabBar->tabText(mTabBar->currentIndex()); mCurrentTilesets.insert(mMapDocument, tilesetName); } // Clear previous content while (mTabBar->count()) mTabBar->removeTab(0); while (mViewStack->count()) delete mViewStack->widget(0); mTilesets.clear(); // Clear all connections to the previous document if (mMapDocument) mMapDocument->disconnect(this); mMapDocument = mapDocument; if (mMapDocument) { mTilesets = mMapDocument->map()->tilesets(); for (const SharedTileset &tileset : mTilesets) { TilesetView *view = new TilesetView; view->setMapDocument(mMapDocument); view->setZoomable(mZoomable); mTabBar->addTab(tileset->name()); mViewStack->addWidget(view); } connect(mMapDocument, &MapDocument::tilesetAdded, this, &TilesetDock::tilesetAdded); connect(mMapDocument, &MapDocument::tilesetRemoved, this, &TilesetDock::tilesetRemoved); connect(mMapDocument, &MapDocument::tilesetMoved, this, &TilesetDock::tilesetMoved); connect(mMapDocument, &MapDocument::tilesetReplaced, this, &TilesetDock::tilesetReplaced); connect(mMapDocument, &MapDocument::tilesetNameChanged, this, &TilesetDock::tilesetNameChanged); connect(mMapDocument, &MapDocument::tilesetFileNameChanged, this, &TilesetDock::updateActions); connect(mMapDocument, &MapDocument::tilesetChanged, this, &TilesetDock::tilesetChanged); connect(mMapDocument, &MapDocument::tileImageSourceChanged, this, &TilesetDock::tileImageSourceChanged); connect(mMapDocument, &MapDocument::tileAnimationChanged, this, &TilesetDock::tileAnimationChanged); QString cacheName = mCurrentTilesets.take(mMapDocument); for (int i = 0; i < mTabBar->count(); ++i) { if (mTabBar->tabText(i) == cacheName) { mTabBar->setCurrentIndex(i); break; } } if (Object *object = mMapDocument->currentObject()) if (object->typeId() == Object::TileType) setCurrentTile(static_cast<Tile*>(object)); } updateActions(); #ifndef Q_OS_OSX widget()->show(); #endif }