Some (possibly extreme?) example attached.

Summary:

Before merging controller and view for the "About" dialog:

   315  frontends/controllers/ControlAboutlyx.lo
 88760  frontends/controllers/ControlAboutlyx.o
   301  frontends/qt4/GuiAbout.lo
 95752  frontends/qt4/GuiAbout.o
  2057  frontends/qt4/GuiAbout_moc.cpp
  4887  frontends/qt4/ui_AboutUi.h

After merging controller and view:

   315  frontends/controllers/ControlAboutlyx.lo
  1640  frontends/controllers/ControlAboutlyx.o
   301  frontends/qt4/GuiAbout.lo
 50100  frontends/qt4/GuiAbout.o
  2065  frontends/qt4/GuiAbout_moc.cpp
  4887  frontends/qt4/ui_AboutUi.h

 127  405 3451 qt4/GuiAbout.cpp
  33   86  567 qt4/GuiAbout.h

plusminus /tmp/1:
     79     390    3005   // added   (lines, word, chars)
    235     914    6580   // removed

Object size shrinks by a factor of 3, Source by a factor of more than 2.
Even not counting the controller, object size is almost halved just by
sticking to Qt "mostly". "Qt only" would decrease this further.

Andre'



Index: qt4/GuiAbout.h
===================================================================
--- qt4/GuiAbout.h      (revision 20080)
+++ qt4/GuiAbout.h      (working copy)
@@ -13,11 +13,8 @@
 #define GUIABOUT_H
 
 #include "GuiDialog.h"
-#include "ControlAboutlyx.h"
 #include "ui_AboutUi.h"
 
-#include <QDialog>
-
 namespace lyx {
 namespace frontend {
 
@@ -28,8 +25,6 @@
 public:
        // Constructor
        GuiAboutDialog(LyXView & lv);
-       /// parent controller
-       ControlAboutlyx & controller() const;
 };
 
 } // namespace frontend
Index: qt4/GuiAbout.cpp
===================================================================
--- qt4/GuiAbout.cpp    (revision 20080)
+++ qt4/GuiAbout.cpp    (working copy)
@@ -13,96 +13,102 @@
 #include "GuiAbout.h"
 #include "qt_helpers.h"
 #include "gettext.h"
+#include "version.h"
 
-#include "support/lstrings.h"
+#include "support/filetools.h" // FileSearch
+#include "support/Package.h"
 
-#include <sstream>
+#include <QtCore>
+#include <QtGui>
 
-#include <QLabel>
-#include <QPushButton>
-#include <QTextCodec>
-#include <QTextBrowser>
+using lyx::support::package;
+using lyx::support::makeDisplayPath;
 
-using lyx::support::prefixIs;
+namespace lyx {
+namespace frontend {
 
-using std::getline;
+static QString credits()
+{
+       QString res;
+       QFile file(toqstr(package().system_support().absFilename()) + 
"/CREDITS");
+       QTextStream out(&res);
 
-using std::istringstream;
-using std::ostringstream;
-using std::string;
+       if (file.isReadable()) {
+               out << toqstr(_("ERROR: LyX wasn't able to read CREDITS 
file\n"));
+               out << toqstr(_("Please install correctly to estimate the 
great\n"));
+               out << toqstr(_("amount of work other people have done for the 
LyX project."));
+       } else {
+               QTextStream ts(&file);
+               QString line;
+               do {
+                       line = ts.readLine();
+                       if (line.startsWith("@b"))
+                               out << "<b>" << line.mid(2) << "</b>";
+                       else if (line.startsWith("@i"))
+                               out << "<i>" << line.mid(2) << "</i>";
+                       else
+                               out << line;
+                       out << "<br>";
+               } while (!line.isNull());
+       }
+       return res;
+}
 
 
-namespace lyx {
-namespace frontend {
-
-GuiAboutDialog::GuiAboutDialog(LyXView & lv)
-       : GuiDialog(lv, "aboutlyx")
+static QString copyright()
 {
-       setupUi(this);
-       setViewTitle(_("About LyX"));
+       return toqstr(_("LyX is Copyright (C) 1995 by Matthias 
Ettrich,\n1995-2006 LyX Team"));
+}
 
-       setController(new ControlAboutlyx(*this));
 
-       connect(closePB, SIGNAL(clicked()), this, SLOT(reject()));
+static QString license()
+{
+       return toqstr(_("This program is free software; you can redistribute it 
and/or modify it under the terms of the GNU General Public License as published 
by the Free Software Foundation; either version 2 of the License, or (at your 
option) any later version."));
+}
 
-       connect(closePB, SIGNAL(clicked()),
-               this, SLOT(slotClose()));
 
-       copyrightTB->setPlainText(toqstr(controller().getCopyright()));
-       copyrightTB->append("");
-       copyrightTB->append(toqstr(controller().getLicense()));
-       copyrightTB->append("");
-       copyrightTB->append(toqstr(controller().getDisclaimer()));
+static QString disclaimer()
+{
+       return toqstr(_("LyX is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
or FITNESS FOR A PARTICULAR PURPOSE.\nSee the GNU General Public License for 
more details.\nYou should have received a copy of the GNU General Public 
License along with this program; if not, write to the Free Software Foundation, 
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA."));
+}
 
-       versionLA->setText(toqstr(controller().getVersion()));
 
-       // The code below should depend on a autoconf test. (Lgb)
-#if 1
-       // There are a lot of buggy stringstream implementations..., but the
-       // code below will work on all of them (I hope). The drawback with
-       // this solutions os the extra copying. (Lgb)
+static QString version()
+{
+       QString res;
+       QTextStream out(&res);
+       out << toqstr(_("LyX Version "));
+       out << lyx_version;
+       out << " (";
+       out << lyx_release_date;
+       out << ")\n";
+       out << toqstr(_("Library directory: "));
+       out << 
toqstr(makeDisplayPath(package().system_support().absFilename()));
+       out << "\n";
+       out << toqstr(_("User directory: "));
+       out << toqstr(makeDisplayPath(package().user_support().absFilename()));
+       return res;
+}
 
-       ostringstream in;
-       controller().getCredits(in);
 
-       istringstream ss(in.str());
+GuiAboutDialog::GuiAboutDialog(LyXView & lv)
+       : GuiDialog(lv, "aboutlyx")
+{
+       setupUi(this);
+       setViewTitle(_("About LyX"));
 
-       string s;
-       ostringstream out;
+       connect(closePB, SIGNAL(clicked()), this, SLOT(reject()));
+       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
 
-       while (getline(ss, s)) {
-               if (prefixIs(s, "@b"))
-                       out << "<b>" << s.substr(2) << "</b>";
-               else if (prefixIs(s, "@i"))
-                       out << "<i>" << s.substr(2) << "</i>";
-               else
-                       out << s;
-               out << "<br>";
-       }
-#else
-       // Good stringstream implementations can handle this. It avoids
-       // some copying, and should thus be faster and use less memory. (Lgb)
-       // I'll make this the default for a short while to see if anyone
-       // see the error...
-       stringstream in;
-       controller().getCredits(in);
-       in.seekg(0);
-       string s;
-       ostringstream out;
+       copyrightTB->setPlainText(copyright());
+       copyrightTB->append(QString());
+       copyrightTB->append(license());
+       copyrightTB->append(QString());
+       copyrightTB->append(disclaimer());
 
-       while (getline(in, s)) {
-               if (prefixIs(s, "@b"))
-                       out << "<b>" << s.substr(2) << "</b>";
-               else if (prefixIs(s, "@i"))
-                       out << "<i>" << s.substr(2) << "</i>";
-               else
-                       out << s;
-               out << "<br>";
-       }
-#endif
+       versionLA->setText(version());
+       creditsTB->setHtml(credits());
 
-       creditsTB->setHtml(toqstr(out.str()));
-
        // try to resize to a good size
        copyrightTB->hide();
        setMinimumSize(copyrightTB->sizeHint());
@@ -115,12 +121,6 @@
        bc().refresh();
 }
 
-
-ControlAboutlyx & GuiAboutDialog::controller() const
-{
-       return static_cast<ControlAboutlyx &>(Dialog::controller());
-}
-
 } // namespace frontend
 } // namespace lyx
 
Index: controllers/ControlAboutlyx.cpp
===================================================================
--- controllers/ControlAboutlyx.cpp     (revision 20080)
+++ controllers/ControlAboutlyx.cpp     (working copy)
@@ -1,102 +0,0 @@
-/**
- * \file ControlAboutlyx.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "ControlAboutlyx.h"
-#include "gettext.h"
-#include "version.h"
-
-#include "support/filetools.h" // FileSearch
-#include "support/Package.h"
-
-#include <fstream>
-#include <sstream>
-
-using std::ostream;
-using std::ostringstream;
-using std::string;
-
-
-namespace lyx {
-
-using support::FileName;
-using support::fileSearch;
-using support::makeDisplayPath;
-using support::package;
-
-namespace frontend {
-
-
-ControlAboutlyx::ControlAboutlyx(Dialog & parent)
-       : Dialog::Controller(parent)
-{}
-
-
-void ControlAboutlyx::getCredits(ostream & ss) const
-{
-       FileName const name = 
fileSearch(package().system_support().absFilename(), "CREDITS");
-
-       bool found(!name.empty());
-
-       if (found) {
-               std::ifstream in(name.toFilesystemEncoding().c_str());
-
-               ss << in.rdbuf();
-               found = ss.good();
-       }
-
-       if (!found) {
-               ss << to_utf8(_("ERROR: LyX wasn't able to read CREDITS 
file\n"))
-                  << to_utf8(_("Please install correctly to estimate the 
great\n"))
-                  << to_utf8(_("amount of work other people have done for the 
LyX project."));
-       }
-}
-
-
-string const ControlAboutlyx::getCopyright() const
-{
-       return to_utf8(_("LyX is Copyright (C) 1995 by Matthias 
Ettrich,\n1995-2006 LyX Team"));
-}
-
-
-string const ControlAboutlyx::getLicense() const
-{
-       return to_utf8(_("This program is free software; you can redistribute 
it and/or modify it under the terms of the GNU General Public License as 
published by the Free Software Foundation; either version 2 of the License, or 
(at your option) any later version."));
-}
-
-
-string const ControlAboutlyx::getDisclaimer() const
-{
-       return to_utf8(_("LyX is distributed in the hope that it will be 
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\nSee the GNU General 
Public License for more details.\nYou should have received a copy of the GNU 
General Public License along with this program; if not, write to the Free 
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
02110-1301, USA."));
-}
-
-
-string const ControlAboutlyx::getVersion() const
-{
-       ostringstream ss;
-
-       ss << to_utf8(_("LyX Version "))
-          << lyx_version
-          << " ("
-          << lyx_release_date
-          << ")\n"
-          << to_utf8(_("Library directory: "))
-          << to_utf8(makeDisplayPath(package().system_support().absFilename()))
-          << "\n"
-          << to_utf8(_("User directory: "))
-          << to_utf8(makeDisplayPath(package().user_support().absFilename()));
-
-       return ss.str();
-}
-
-} // namespace frontend
-} // namespace lyx
Index: controllers/ControlAboutlyx.h
===================================================================
--- controllers/ControlAboutlyx.h       (revision 20080)
+++ controllers/ControlAboutlyx.h       (working copy)
@@ -1,49 +0,0 @@
-// -*- C++ -*-
-/**
- * \file ControlAboutlyx.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef CONTROLABOUTLYX_H
-#define CONTROLABOUTLYX_H
-
-#include "Dialog.h"
-#include <iosfwd>
-
-namespace lyx {
-namespace frontend {
-
-/** \c ControlAboutlyx is a controller for the "About LyX" dialogs.
- */
-class ControlAboutlyx : public Dialog::Controller {
-public:
-       ControlAboutlyx(Dialog & parent);
-
-       //@{
-       /// Instantiate Dialog::Controller methods.
-       virtual bool initialiseParams(std::string const &) { return true; }
-       virtual void clearParams() {}
-       virtual void dispatchParams() {}
-       virtual bool isBufferDependent() const { return false; }
-       //@}
-
-       //@{
-       /// Provide the View with specific pieces of information.
-       void getCredits(std::ostream &) const;
-       std::string const getCopyright() const;
-       std::string const getLicense() const;
-       std::string const getDisclaimer() const;
-       std::string const getVersion() const;
-       //@}
-};
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // CONTROLABOUTLYX_H

Reply via email to