lyx_mirror/src/ModuleList.h
Richard Heck d5d665482e This commit changes the way individual LyXModule's are represented, both internally and in the .lyx files. The earlier version represented them by their `descriptive name', e.g., "Endnote" or "Theorems (AMS)", these being the same names used in the UI. This was a mistake, as becomes readily apparent when one starts to think about translating these strings. The modules ought to be represented by their filename, without the extension, just as TextClass's are.
The changes that accomplish this part are in ModuleList.{h,cpp}, configure.py, and the *.module files themselves. This is a format change, and the lyx2lyx is in those files.

By itself, that change would not be major, except for the fact that we do not want the module to be represented in the UI by its filename---e.g., theorems-std---but rather by a descriptive name, such as "Theorems". But that change turns out to be wholly non-trivial. The mechanism for choosing modules was the same as---indeed, was borrowed from---that in GuiCitation: You get a list of modules, and choosing them involves moving strings from one QListView to another. The models underlying these views are just QStringListModels, which means that, when you want to know what modules have been selected, you see what strings are in the "selected" QListView. But these are just the descriptive names, and we can't look up a module by its descriptive name if it's been translated. That, indeed, was the whole point of the change to the new representation.

So, we need a more complicated model underlying the QListView, one that will pair an identifying string---the filename minus the extension, in this case---with each item. This turns out not to be terribly difficult, though it took rather a while for me to understand why it's not difficult. There are two parts:
(i)  GuiSelectionManger gets re-written to use any QAbstractListModel, not just a QStringListModel. This actually seems to improve the code, independently.
(ii) We then subclass QAbstractListModel to get the associated ID string, using the Qt::UserRole slot associated with each item to store its ID. This would be almost completely trivial if QAbstractListItem::itemData() included the QVariant associated with this role, but it doesn't, so there are some additional hoops through which to jump.

The new model, a GuiIdListModel, is defined in the files by that name. The changes in GuiSelectionManger.{h,cpp} make it more abstract; the changes in GuiDocument.{h,cpp} adapt it to the new framework. 

I've also updated the module documenation to accord with this change.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22501 a592a061-630c-0410-9148-cb99ea01b6c8
2008-01-12 04:28:12 +00:00

121 lines
3.3 KiB
C++

// -*- C++ -*-
/**
* \file ModuleList.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
#ifndef MODULELIST_H
#define MODULELIST_H
#include <map>
#include <string>
#include <vector>
namespace lyx {
/**
* This struct represents a particular LyX "module", which is a like a layout
* file, except that it does not stand alone. In that sense, it is more like
* a LaTeX package, where a layout file corresponds to a LaTeX class.
*/
//FIXME Give us some access functions here.
class LyXModule {
public:
///
LyXModule(std::string const & n, std::string const & i,
std::string const & d, std::vector<std::string> const & p,
std::vector<std::string> const & r,
std::vector<std::string> const & e);
/// whether the required packages are available
bool isAvailable();
///
std::string const & getName() const { return name; }
///
std::string const & getID() const { return id; }
///
std::string const & getFilename() const { return filename; }
///
std::string const & getDescription() const { return description; }
///
std::vector<std::string> const & getPackageList() const
{ return packageList; }
///
std::vector<std::string> const & getRequiredModules() const
{ return requiredModules; }
/// Modules this one excludes: the list should be treated disjunctively
std::vector<std::string> const & getExcludedModules() const
{ return excludedModules; }
private:
/// what appears in the ui
std::string name;
/// the module's unique identifier
/// at present, this is the filename, without the extension
std::string id;
/// the filename
std::string filename;
/// a short description for use in the ui
std::string description;
/// the LaTeX packages on which this depends, if any
std::vector<std::string> packageList;
/// Modules this one requires: at least one
std::vector<std::string> requiredModules;
/// Modules this one excludes: none of these
std::vector<std::string> excludedModules;
///
bool checked;
///
bool available;
};
typedef std::vector<LyXModule> LyXModuleList;
/**
* The ModuleList represents the various LyXModule's that are available at
* present.
*/
class ModuleList {
public:
///
ModuleList() {}
/// reads the modules from a file generated by configure.py
bool load();
///
LyXModuleList::const_iterator begin() const;
///
LyXModuleList::iterator begin();
///
LyXModuleList::const_iterator end() const;
///
LyXModuleList::iterator end();
///
bool empty() const { return modlist_.empty(); }
/// Returns a pointer to the LyXModule with name str.
/// Returns a null pointer if no such module is found.
LyXModule * getModuleByName(std::string const & str);
/// Returns a pointer to the LyXModule with filename str.
/// Returns a null pointer if no such module is found.
LyXModule * operator[](std::string const & str);
private:
/// noncopyable
ModuleList(ModuleList const &);
///
void operator=(ModuleList const &);
/// add a module to the list
void addLayoutModule(std::string const &, std::string const &,
std::string const &, std::vector<std::string> const &,
std::vector<std::string> const &, std::vector<std::string> const &);
///
std::vector<LyXModule> modlist_;
};
extern ModuleList moduleList;
}
#endif