diff -r cf14046909cd -r 7ea31701156e mainwindow.cpp --- a/mainwindow.cpp Mon Aug 04 13:35:54 2008 +0000 +++ b/mainwindow.cpp Tue Aug 05 07:36:53 2008 +0000 @@ -74,6 +74,7 @@ extern QString iconPath; extern QString flagsPath; + Main::Main(QWidget* parent, const char* name, Qt::WFlags f) : QMainWindow(parent,name,f) { @@ -201,9 +202,6 @@ connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), this, SLOT( editorChanged( QWidget * ) ) ); - lineedit=new QLineEdit (this); - lineedit->hide(); - setCentralWidget(tabWidget); setupFileActions(); @@ -1691,22 +1689,16 @@ MapEditor* Main::currentMapEditor() const { - // FIXME currentMapEditor should return the latest used editor for a model, or NULL if no editor is open - if ( tabWidget->currentPage() && - tabWidget->currentPage()->inherits( "MapEditor" ) ) - return (MapEditor*)tabWidget->currentPage(); + if ( tabWidget->currentPage()) + return tabModel.at(tabWidget->currentIndex())->getMapEditor(); return NULL; } VymModel* Main::currentModel() const { - // FIXME better get currentModel from a maintained list, - // just in case we allow other views in tabs later - MapEditor *me=currentMapEditor(); - if (me) - return me->getModel(); - else - return NULL; + if ( tabWidget->currentPage()) + return tabModel.at(tabWidget->currentIndex()); + return NULL; } @@ -1714,12 +1706,9 @@ { // Unselect all possibly selected objects // (Important to update note editor) - MapEditor *me; for (int i=0;i<=tabWidget->count() -1;i++) { - - me=(MapEditor*)tabWidget->page(i); - me->getModel()->unselect(); + tabModel.at(i)->unselect(); } VymModel *m=currentModel(); if (m) m->reselect(); @@ -1728,18 +1717,43 @@ updateActions(); } +VymView *Main::createView (VymModel *model) +{ + VymView *vm=new VymView; + + // Create TreeView + QTreeView *tv=new QTreeView; + tv->setModel (model->getTreeModel() ); + + // Create good old MapEditor + MapEditor* me=model->getMapEditor(); + if (!me) me=new MapEditor (model); + //me->viewport()->setFocus(); + me->setAntiAlias (actionViewToggleAntiAlias->isOn()); + me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn()); + + vm->addWidget (tv); + vm->addWidget (me); + + // Set geometry + QList sizes; + sizes.append (150); + sizes.append (600); + vm->setSizes (sizes); + + return vm; +} + void Main::fileNew() { VymModel *m=new VymModel; - models.append (m); + tabModel.append (m); MapEditor* me = new MapEditor (m); me->setObjectName ("MapEditor"); - QString fn="unnamed"; - tabWidget->addTab (me,fn); - tabWidget->showPage(me); - me->viewport()->setFocus(); - me->setAntiAlias (actionViewToggleAntiAlias->isOn()); - me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn()); + + VymView *view=createView (m); + tabWidget->addTab (view,tr("unnamed","MainWindow: name for new and empty file")); + tabWidget->setCurrentIndex (tabModel.count() ); // For the very first map we do not have flagrows yet... m->select("mc:"); @@ -1748,25 +1762,14 @@ void Main::fileNewCopy() { QString fn="unnamed"; - MapEditor* oldME =currentMapEditor(); - if (oldME) + VymModel *srcModel=currentModel(); + if (srcModel) { - oldME->getModel()->copy(); - VymModel *m=new VymModel; - models.append (m); - MapEditor* newME = new MapEditor ( m); - if (newME) - { - tabWidget->addTab (newME,fn); - tabWidget->showPage(newME); - newME->viewport()->setFocus(); - newME->setAntiAlias (actionViewToggleAntiAlias->isOn()); - newME->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn()); - // For the very first map we do not have flagrows yet... - m->select("mc:"); - m->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap); - } - + srcModel->copy(); + fileNew(); + VymModel *dstModel=tabModel.last (); + dstModel->select("mc:"); + dstModel->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap); } } @@ -1788,8 +1791,7 @@ int i=0; while (i<=tabWidget->count() -1) { - me=(MapEditor*)tabWidget->page(i); - if (me->getModel()->getFilePath() == fn) + if (tabModel.at(i)->getFilePath() == fn) { // Already there, ask for confirmation QMessageBox mb( vymName, @@ -1806,7 +1808,7 @@ switch( mb.exec() ) { case QMessageBox::Yes: - // load anyway + // end loop and load anyway i=tabWidget->count(); break; case QMessageBox::Cancel: @@ -1818,26 +1820,24 @@ i++; } } - + + int tabIndex=tabWidget->currentPageIndex(); // Try to load map if ( !fn.isEmpty() ) { me = currentMapEditor(); - int tabIndex=tabWidget->currentPageIndex(); // Check first, if mapeditor exists // If it is not default AND we want a new map, // create a new mapeditor in a new tab if ( lmode==NewMap && (!me || !me->getModel()->isDefault() ) ) { VymModel *m=new VymModel; - models.append (m); - me= new MapEditor ( m); - tabWidget->addTab (me,fn); - tabIndex=tabWidget->indexOf (me); + tabModel.append (m); + VymView *view=createView (m); + tabWidget->addTab (view,fn); + tabIndex=tabWidget->count()-1; tabWidget->setCurrentPage (tabIndex); - me->setAntiAlias (actionViewToggleAntiAlias->isOn()); - me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn()); } // Check, if file exists (important for creating new files @@ -1858,7 +1858,7 @@ case QMessageBox::Yes: // Create new map currentMapEditor()->getModel()->setFilePath(fn); - tabWidget->setTabLabel (currentMapEditor(), + tabWidget->setTabText (tabIndex, currentMapEditor()->getModel()->getFileName() ); statusBar()->message( "Created " + fn , statusbarTime ); return success; @@ -1873,7 +1873,7 @@ //tabWidget->currentPage() won't be NULL here, because of above... - tabWidget->showPage(me); + tabWidget->setCurrentIndex (tabIndex); me->viewport()->setFocus(); if (err!=aborted) @@ -1900,7 +1900,7 @@ if (lmode==NewMap) { me->getModel()->setFilePath (fn); - tabWidget->changeTab(tabWidget->page(tabIndex), me->getModel()->getFileName()); + tabWidget->setTabText (tabIndex, me->getModel()->getFileName()); if (!isInTmpDir (fn)) { // Only append to lastMaps if not loaded from a tmpDir @@ -1990,7 +1990,7 @@ // call fileSaveAs() now, this will call fileSave() // again. // First switch to editor - tabWidget->setCurrentWidget (m->getMapEditor()); + //FIXME needed??? tabWidget->setCurrentWidget (m->getMapEditor()); fileSaveAs(savemode); } @@ -2068,13 +2068,13 @@ // Save now - currentModel()->setFilePath(fn); - fileSave(currentModel(), savemode); - - // Set name of tab + VymModel *m=currentModel(); + m->setFilePath(fn); + fileSave(m, savemode); + + // Set name of tab, assuming current tab is the one we just saved if (savemode==CompleteMap) - tabWidget->setTabLabel (currentMapEditor(), - currentModel()->getFileName() ); + tabWidget->setTabText (tabWidget->currentIndex(), m->getFileName() ); return; } } @@ -2342,7 +2342,8 @@ } } me->close(); - tabWidget->removePage(me); + tabModel.removeAt (tabWidget->currentIndex() ); + tabWidget->removeTab (tabWidget->currentIndex() ); delete me; // FIXME if event was triggered _in_ ME this causes warning message updateActions(); } @@ -2357,15 +2358,11 @@ void Main::fileExitVYM() { // Check if one or more editors have changed - MapEditor *me; int i; - for (i=0;i<=tabWidget->count() -1;i++) + for (i=0;i<=tabModel.count() -1;i++) { - - me=(MapEditor*)tabWidget->page(i); - // If something changed, ask what to do - if (me->getModel()->hasChanged()) + if (tabModel.at(i)->hasChanged()) { tabWidget->setCurrentPage(i); QMessageBox mb( vymName, @@ -2740,11 +2737,9 @@ // compare path with already loaded maps int index=-1; int i; - MapEditor *me; - for (i=0;i<=tabWidget->count() -1;i++) + for (i=0;i<=tabModel.count() -1;i++) { - me=(MapEditor*)tabWidget->page(i); - if (vl.at(j)==me->getModel()->getFilePath() ) + if (vl.at(j)==tabModel.at(i)->getFilePath() ) { index=i; break; @@ -2759,11 +2754,11 @@ else { fileLoad (vl.at(j), NewMap); - tabWidget->setCurrentPage (tabWidget->count()-1); + tabWidget->setCurrentIndex (tabWidget->count()-1); } } else // Go to tab containing the map - tabWidget->setCurrentPage (index); + tabWidget->setCurrentIndex (index); } } @@ -2884,7 +2879,7 @@ void Main::editAddMapCenter() { VymModel *m=currentModel(); - if (!lineedit->isVisible() && m) + if (m) { m->addMapCenter (); } @@ -2893,7 +2888,7 @@ void Main::editNewBranch() { VymModel *m=currentModel(); - if (!lineedit->isVisible() && m) + if (m) { BranchObj *bo=(BranchObj*)m->getSelection(); BranchObj *newbo=m->addNewBranch(0); @@ -2920,7 +2915,7 @@ void Main::editNewBranchBefore() { VymModel *m=currentModel(); - if (!lineedit->isVisible() && m) + if (m) { BranchObj *bo=(BranchObj*)m->getSelection(); BranchObj *newbo=m->addNewBranchBefore(); @@ -2942,7 +2937,7 @@ void Main::editNewBranchAbove() { VymModel *m=currentModel(); - if (!lineedit->isVisible() && m) + if ( m) { BranchObj *bo=(BranchObj*)m->getSelection(); BranchObj *newbo=m->addNewBranch (-1); @@ -2964,7 +2959,7 @@ void Main::editNewBranchBelow() { VymModel *m=currentModel(); - if (!lineedit->isVisible() && m) + if (m) { BranchObj *bo=(BranchObj*)m->getSelection(); BranchObj *newbo=m->addNewBranch (1); @@ -3372,10 +3367,10 @@ { bool b=actionViewToggleAntiAlias->isOn(); MapEditor *me; - for (int i=0;icount();i++) + for (int i=0;ipage(i); - me->setAntiAlias(b); + me=tabModel.at(i)->getMapEditor(); + if (me) me->setAntiAlias(b); } } @@ -3384,11 +3379,11 @@ { bool b=actionViewToggleSmoothPixmapTransform->isOn(); MapEditor *me; - for (int i=0;icount();i++) + for (int i=0;ipage(i); - me->setSmoothPixmap(b); + me=tabModel.at(i)->getMapEditor(); + if (me) me->setSmoothPixmap(b); } } @@ -3679,14 +3674,14 @@ void Main::windowNextEditor() { - if (tabWidget->currentPageIndex() < tabWidget->count()) - tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1); + if (tabWidget->currentIndex() < tabWidget->count()) + tabWidget->setCurrentIndex (tabWidget->currentIndex() +1); } void Main::windowPreviousEditor() { - if (tabWidget->currentPageIndex() >0) - tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1); + if (tabWidget->currentIndex() >0) + tabWidget->setCurrentIndex (tabWidget->currentIndex() -1); } void Main::standardFlagChanged()