It doesn’t seem to be necessary at this point, I think just adding a dock
extension, and commenting that is we break ABI then a common base might be
appropriate. How much would the two classes share in a common base? If not
very much it would be more appropriate to keep the inheritance relatively
shallow, if lots then I would go for it.
My proposal:
#define AVOGADRO_EXTENSION(i, t, d)
…
#define AVOGADRO_EXTENSION_FACTORY(c)
…
class A_EXPORT AbstractExtension : public Plugin
{
Q_OBJECT
public:
AbstractExtension(QObject *parent = 0);
~AbstractExtension
enum MoleculeChangedHint {…};
Plugin::Type type() const;
QString typeName() const;
virtual void writeSettings(QSettings &settings) const;//=0; // don’t understand why they are here, should be =0 or removed
virtual void readSettings(QSettings &settings);//=0; // or introduce some automagical thing that should read&save properties~variables, declared by extension
public Q_SLOTS:
virtual void setMolecule(Molecule *molecule);
Q_SIGNALS:
void message(const QString &m);
void moleculeChanged(Molecule , int);
void performCommand(QUndoCommand);
};
// DialogExtension
class Extension : public AbstractExtension
{
virtual QList actions() const = 0;
virtual QString menuPath(QAction action) const = 0; // maybe all this extensions must have action in menu? or how it could be called?
virtual int usefulness() const; //=0; // menu order is needed only for dialog extensions
virtual QUndoCommand performAction(QAction *action, GLWidget *widget) = 0;
// maybe something else
};
class DockExtension : public AbstractExtension
{
virtual QDockWidget * dockWidget() = 0;
virtual Qt::DockWidgetArea prefferredDockArea() const; // one prefferred area
// maybe something else
};
// maybe also useful
class NetworkUser // is not inherited from anything; will be mixed in extension classes which want network as second base class
{
//some network related stuff
};
See that dialog and dock extensions must have different sets of methods. Also, type() could be overridden to distinct ones from anothers
If implement DockExtension if separate class, too many methods will be duplicated
Addition of property will be painless, but it’ll intoduce more mess in API: currently, some functions must be overridden in any cases, even if they aren’t needed, other need this only for some kinds of extension (docks), some things are set up with properties, etc.
I know it can wait, and there aren’t any massive code duplications, but making API more clear will simplify task of extension writing. Almost everything works correctly in my dock, I onlu wished to contribute into core structure to make it more clear.
Also I stay for more dock extensions, because docks doesn’t appear on top of target molecule
–
Regards,
Konstantin