From: Richard Heck Date: Mon, 20 Oct 2008 19:53:15 +0000 (+0000) Subject: Remove now duplicated code. X-Git-Tag: 1.6.10~2953 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=ae339e3ca8343f188bdadc73185f89078010e93e;p=features.git Remove now duplicated code. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26996 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 715d7da70a..8214dfd8d3 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -244,9 +244,10 @@ public: QPushButton * upPB, QPushButton * downPB, GuiIdListModel * availableModel, - GuiIdListModel * selectedModel) + GuiIdListModel * selectedModel, + GuiDocument const * container) : GuiSelectionManager(availableLV, selectedLV, addPB, delPB, - upPB, downPB, availableModel, selectedModel) + upPB, downPB, availableModel, selectedModel), container_(container) {} private: /// @@ -267,6 +268,8 @@ private: { return dynamic_cast(selectedModel); } + /// + GuiDocument const * container_; }; void ModuleSelectionManager::updateAddPB() @@ -285,48 +288,9 @@ void ModuleSelectionManager::updateAddPB() QModelIndex const & idx = availableLV->selectionModel()->currentIndex(); string const modName = getAvailableModel()->getIDString(idx.row()); - int const srows = selectedModel->rowCount(); - // if no modules are yet selected, there is no more to check. - if (srows == 0) { - addPB->setEnabled(true); - return; - } - - vector selModList; - for (int i = 0; i < srows; ++i) - selModList.push_back(getSelectedModel()->getIDString(i)); - - vector::const_iterator const selModStart = selModList.begin(); - vector::const_iterator const selModEnd = selModList.end(); - - // Check whether some required module is available - vector const reqs = getRequiredList(modName); - if (!reqs.empty()) { - bool foundOne = false; - vector::const_iterator it = reqs.begin(); - vector::const_iterator en = reqs.end(); - for (; it != en; ++it) { - if (find(selModStart, selModEnd, *it) != selModEnd) { - foundOne = true; - break; - } - } - if (!foundOne) { - addPB->setEnabled(false); - return; - } - } - - // Check for conflicts with used modules - vector::const_iterator selModIt = selModStart; - for (; selModIt != selModEnd; ++selModIt) { - if (!LyXModule::areCompatible(modName, *selModIt)) { - addPB->setEnabled(false); - return; - } - } - - addPB->setEnabled(true); + bool const enable = + container_->params().moduleCanBeAdded(modName); + addPB->setEnabled(enable); } @@ -403,7 +367,7 @@ void ModuleSelectionManager::updateDelPB() deletePB->setEnabled(false); return; } - + QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex(); int const curRow = curIdx.row(); @@ -905,7 +869,7 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(latexModule->childDocPB, SIGNAL(clicked()), this, SLOT(browseMaster())); - + // postscript drivers for (int n = 0; tex_graphics[n][0]; ++n) { QString enc = qt_(tex_graphics_gui[n]); @@ -950,7 +914,7 @@ GuiDocument::GuiDocument(GuiView & lv) modulesModule->selectedLV, modulesModule->addPB, modulesModule->deletePB, modulesModule->upPB, modulesModule->downPB, - availableModel(), selectedModel()); + availableModel(), selectedModel(), this); connect(selectionManager, SIGNAL(updateHook()), this, SLOT(updateModuleInfo())); connect(selectionManager, SIGNAL(updateHook()), diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 6ba761fd74..1e9a1f38ed 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -73,6 +73,8 @@ public: void updatePagestyle(std::string const &, std::string const &); void showPreamble(); + /// + BufferParams const & params() const { return bp_; } private Q_SLOTS: void updateNumbering(); @@ -171,8 +173,6 @@ private: /// BufferParams & params() { return bp_; } /// - BufferParams const & params() const { return bp_; } - /// BufferId id() const; /// struct modInfoStruct {