Commit 7adfaccb authored by Martin Walch's avatar Martin Walch

reformat whole code base of Kalzium

Across the project there are many coding styles with lots of different
indentation patterns. There are three different tabs to space
conversions (1:2, 1:4, 1:8), even mixed within individual files. This
makes the code unnecessarily hard to read and to edit.

In the hope that I do not offend anybody: unify code style.

Roughly apply the style from kdelibs:

* get rid of all tabs
* indentation is four spaces
* unify includes and include guards
* less blank lines
* one space after "if", "for", etc.
* no space after cast
* prefix operators ("++", "--") instead of postfix where applicable
* pointers: preferably single space before "\*" (same for "&")
* opening curly braces on same line except for implementations
* no whitespace after opening parenthesis "(" or before closing ones ")"
* no single line "if", "for", "else", etc. (always curly braces)
* indent "case" to same level as corresponding "switch"
* at least in some files adjust line wraps to a limit of 100 chars
* exactly one newline at EOF

Also some formatting to copyright statements (I hope this is legally ok)

Additionally:
* fix some spelling errors
* constify& some foreach loops (suggested by krazy2)
* replace some single char strings with chars (suggested by krazy2)

This whole patch fixes between 15 and 20 krazy2 warnings.

REVIEW: 120238
parent 287791bb
......@@ -11,6 +11,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "kalziumglpart.h"
#include "kalziumglwidget.h"
......@@ -20,11 +21,11 @@
KAboutData kalziumGLPartAboutData()
{
KAboutData aboutData(
"kalzium", QByteArray(), ki18n("Kalzium OpenGL Part"), "1.1.1",
ki18n("A cool thing"),
KAboutData::License_GPL, ki18n("(c) 2006, Carsten Niehaus"),
KLocalizedString(),
"http://edu.kde.org/kalzium/index.php"
"kalzium", QByteArray(), ki18n("Kalzium OpenGL Part"), "1.1.1",
ki18n("A cool thing"),
KAboutData::License_GPL, ki18n("(c) 2006, Carsten Niehaus"),
KLocalizedString(),
"http://edu.kde.org/kalzium/index.php"
);
aboutData.addAuthor(ki18n("Carsten Niehaus"), KLocalizedString(), "cniehaus@kde.org");
aboutData.addAuthor(ki18n("Marcus D. Hanwell"), KLocalizedString(), "marcus@cryos.org");
......@@ -41,7 +42,7 @@ KalziumGLPart::KalziumGLPart(QWidget* parentWidget, QObject* parent, const QVari
Q_UNUSED(parentWidget);
Q_UNUSED(args);
kDebug() << "KalziumGLPart::KalziumGLPart()";
m_widget = new KalziumGLWidget();
m_widget->setObjectName("KalziumGLWidget-KPart");
}
......@@ -54,7 +55,7 @@ KalziumGLPart::~KalziumGLPart()
bool KalziumGLPart::openFile()
{
return m_widget->openFile( url().toLocalFile() );
return m_widget->openFile(url().toLocalFile());
}
#include "kalziumglpart.moc"
......@@ -11,6 +11,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef KALZIUMGLPART_H
#define KALZIUMGLPART_H
......@@ -21,14 +22,14 @@ class KalziumGLWidget;
class KalziumGLPart : public KParts::ReadOnlyPart
{
Q_OBJECT
public:
KalziumGLPart(QWidget*, QObject*, const QVariantList&);
virtual ~KalziumGLPart();
public:
KalziumGLPart(QWidget*, QObject*, const QVariantList&);
virtual ~KalziumGLPart();
protected:
bool openFile();
protected:
bool openFile();
KalziumGLWidget* m_widget;
KalziumGLWidget* m_widget;
};
#endif // KALZIUMGLPART_H
......@@ -11,6 +11,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "kalziumglwidget.h"
#include <QSettings>
......@@ -38,10 +39,8 @@ KalziumGLWidget::KalziumGLWidget(QWidget *parent) : Avogadro::GLWidget(parent),
// first set the Avogadro plugin directory,
// avoiding overwriting an already set envvar
static bool s_pluginDirSet = false;
if (!s_pluginDirSet)
{
if (qgetenv("AVOGADRO_PLUGINS").isEmpty())
{
if (!s_pluginDirSet) {
if (qgetenv("AVOGADRO_PLUGINS").isEmpty()) {
qputenv("AVOGADRO_PLUGINS", AVOGADRO_PLUGIN_DIR);
}
s_pluginDirSet = true;
......@@ -70,33 +69,32 @@ KalziumGLWidget::~KalziumGLWidget()
bool KalziumGLWidget::openFile(const QString &file)
{
Avogadro::Molecule* mol = OpenBabel2Wrapper::readMolecule( file );
if (!mol)
Avogadro::Molecule* mol = OpenBabel2Wrapper::readMolecule(file);
if (!mol) {
return false;
}
Avogadro::Molecule* oldmol = molecule();
if (oldmol)
if (oldmol) {
oldmol->deleteLater();
setMolecule( mol );
}
setMolecule(mol);
update();
return true;
}
void KalziumGLWidget::setStyle( int style )
void KalziumGLWidget::setStyle(int style)
{
foreach(Avogadro::Engine *engine, engines())
{
if((m_lastEngine1 == 0 && engine->identifier() == "Ball and Stick")
|| (m_lastEngine1 == 1 && engine->identifier() == "Stick")
|| (m_lastEngine1 == 2 && engine->identifier() == "Van der Waals Spheres")
|| (m_lastEngine1 == 3 && engine->identifier() == "Wireframe"))
{
foreach (Avogadro::Engine *engine, engines()) {
if ((m_lastEngine1 == 0 && engine->identifier() == "Ball and Stick")
|| (m_lastEngine1 == 1 && engine->identifier() == "Stick")
|| (m_lastEngine1 == 2 && engine->identifier() == "Van der Waals Spheres")
|| (m_lastEngine1 == 3 && engine->identifier() == "Wireframe")) {
engine->setEnabled(false);
}
if((style == 0 && engine->identifier() == "Ball and Stick")
|| (style == 1 && engine->identifier() == "Stick")
|| (style == 2 && engine->identifier() == "Van der Waals Spheres")
|| (style == 3 && engine->identifier() == "Wireframe"))
{
if ((style == 0 && engine->identifier() == "Ball and Stick")
|| (style == 1 && engine->identifier() == "Stick")
|| (style == 2 && engine->identifier() == "Van der Waals Spheres")
|| (style == 3 && engine->identifier() == "Wireframe")) {
engine->setEnabled(true);
}
}
......@@ -104,20 +102,17 @@ void KalziumGLWidget::setStyle( int style )
update();
}
void KalziumGLWidget::setStyle2( int style )
void KalziumGLWidget::setStyle2(int style)
{
foreach(Avogadro::Engine *engine, engines())
{
if((m_lastEngine2 == 1 && engine->identifier() == "Ribbon")
|| (m_lastEngine2 == 2 && engine->identifier() == "Ring")
|| (m_lastEngine2 == 3 && engine->identifier() == "Orbitals"))
{
foreach (Avogadro::Engine *engine, engines()) {
if ((m_lastEngine2 == 1 && engine->identifier() == "Ribbon")
|| (m_lastEngine2 == 2 && engine->identifier() == "Ring")
|| (m_lastEngine2 == 3 && engine->identifier() == "Orbitals")) {
engine->setEnabled(false);
}
if((style == 1 && engine->identifier() == "Ribbon")
|| (style == 2 && engine->identifier() == "Ring")
|| (style == 3 && engine->identifier() == "Orbitals"))
{
if ((style == 1 && engine->identifier() == "Ribbon")
|| (style == 2 && engine->identifier() == "Ring")
|| (style == 3 && engine->identifier() == "Orbitals")) {
engine->setEnabled(true);
}
}
......@@ -127,46 +122,46 @@ void KalziumGLWidget::setStyle2( int style )
void KalziumGLWidget::setLabels(int style)
{
// Use the QSettings framework to configure the label engine
foreach(Avogadro::Engine *engine, engines())
{
if(engine->name() == "Label")
{
QSettings settings;
int atomType = 0;
int bondType = 0;
bool enabled = false;
// We need to use
switch(style)
{
case 0: // Display no labels
enabled = false;
break;
case 1: // Display the atom symbol
enabled = true;
atomType = 3;
break;
case 2: // Display the atom name
enabled = true;
atomType = 2;
break;
default:
engine->setEnabled(false);
}
settings.setValue("atomLabel", atomType);
settings.setValue("bondLabel", bondType);
settings.setValue("enabled", enabled);
engine->readSettings(settings);
// Use the QSettings framework to configure the label engine
foreach (Avogadro::Engine *engine, engines()) {
if (engine->name() == "Label") {
QSettings settings;
int atomType = 0;
int bondType = 0;
bool enabled = false;
// We need to use
switch(style) {
case 0: // Display no labels
enabled = false;
break;
case 1: // Display the atom symbol
enabled = true;
atomType = 3;
break;
case 2: // Display the atom name
enabled = true;
atomType = 2;
break;
default:
engine->setEnabled(false);
}
settings.setValue("atomLabel", atomType);
settings.setValue("bondLabel", bondType);
settings.setValue("enabled", enabled);
engine->readSettings(settings);
}
}
}
}
void KalziumGLWidget::setQuality(int quality)
{
// Set the global quality of the GLWidget, 0=min, 2=mid, 4=max
int q = 0;
if(quality == 1) q = 2;
else if(quality == 2) q = 4;
if (quality == 1) {
q = 2;
} else if (quality == 2) {
q = 4;
}
GLWidget::setQuality(q);
invalidateDLs();
GLWidget::update();
......
......@@ -11,6 +11,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef KALZIUMGLWIDGET_H
#define KALZIUMGLWIDGET_H
......@@ -19,20 +20,20 @@
class KalziumGLWidget : public Avogadro::GLWidget
{
Q_OBJECT
public:
KalziumGLWidget(QWidget *parent = 0);
virtual ~KalziumGLWidget();
public slots:
void setStyle(int style);
void setStyle2(int style);
void setLabels(int style);
void setQuality(int quality);
bool openFile(const QString &file);
public:
KalziumGLWidget(QWidget *parent = 0);
virtual ~KalziumGLWidget();
public slots:
void setStyle(int style);
void setStyle2(int style);
void setLabels(int style);
void setQuality(int quality);
bool openFile(const QString &file);
protected:
QByteArray m_lc_numeric;
int m_lastEngine1, m_lastEngine2;
protected:
QByteArray m_lc_numeric;
int m_lastEngine1, m_lastEngine2;
};
#endif // KALZIUMGLWIDGET_H
......@@ -25,10 +25,10 @@
#ifndef COMPOUNDVIEWER_EXPORT
# if defined(MAKE_COMPOUNDVIEWER_LIB)
/* We are building this library */
/* We are building this library */
# define COMPOUNDVIEWER_EXPORT KDE_EXPORT
# else
/* We are using this library */
/* We are using this library */
# define COMPOUNDVIEWER_EXPORT KDE_IMPORT
# endif
#endif
......@@ -37,4 +37,4 @@
# define COMPOUNDVIEWER_EXPORT_DEPRECATED KDE_DEPRECATED COMPOUNDVIEWER_EXPORT
# endif
#endif
#endif // LIBKDEEDU_COMPOUNDVIEWER_EXPORT_H
......@@ -11,6 +11,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "openbabel2wrapper.h"
#include <kdebug.h>
......@@ -29,74 +30,72 @@
#include <QFile>
Avogadro::Molecule* OpenBabel2Wrapper::readMolecule( const QString& filename )
Avogadro::Molecule* OpenBabel2Wrapper::readMolecule(const QString& filename)
{
OpenBabel::OBConversion Conv;
OpenBabel::OBFormat *inFormat = NULL;
OpenBabel::OBConversion Conv;
OpenBabel::OBFormat *inFormat = NULL;
// the Avogadro Molecule
Avogadro::Molecule *mol = new Avogadro::Molecule;
OpenBabel::OBMol *obmol = new OpenBabel::OBMol;
std::ifstream inFileStream( QFile::encodeName(filename) );
if ( !inFileStream ) {
KMessageBox::error( 0,
i18n( "Problem while opening the file" ),
i18n( "Cannot open the specified file." ) );
delete mol;
return 0;
}
// the Avogadro Molecule
Avogadro::Molecule *mol = new Avogadro::Molecule;
OpenBabel::OBMol *obmol = new OpenBabel::OBMol;
std::ifstream inFileStream(QFile::encodeName(filename));
if (!inFileStream) {
KMessageBox::error(0,
i18n("Problem while opening the file"),
i18n("Cannot open the specified file."));
delete mol;
return 0;
}
//find out which format the file has...
inFormat = Conv.FormatFromExt( QFile::encodeName(filename) );
if (!inFormat || !Conv.SetInFormat(inFormat))
{
KMessageBox::error( 0, i18n("Cannot read the file format. Check your OpenBabel installation."), i18n("Problem reading file format"));
delete mol;
return 0;
}
Conv.SetInAndOutFormats( inFormat,inFormat );
Conv.Read( obmol, &inFileStream );
//find out which format the file has...
inFormat = Conv.FormatFromExt(QFile::encodeName(filename));
if (!inFormat || !Conv.SetInFormat(inFormat)) {
KMessageBox::error(0,
i18n("Cannot read the file format. Check your OpenBabel installation."),
i18n("Problem reading file format"));
delete mol;
return 0;
}
Conv.SetInAndOutFormats(inFormat,inFormat);
Conv.Read(obmol, &inFileStream);
kDebug() << QString::fromLatin1( obmol->GetFormula().c_str() ) << " (Weight: " << obmol->GetMolWt() << ", Title: "<< obmol->GetTitle() << ")";
mol->setOBMol(obmol);
return mol;
kDebug() << QString::fromLatin1(obmol->GetFormula().c_str()) << " (Weight: " << obmol->GetMolWt() << ", Title: "<< obmol->GetTitle() << ")";
mol->setOBMol(obmol);
return mol;
}
bool OpenBabel2Wrapper::writeMolecule( const QString& filename, Avogadro::Molecule* mol )
bool OpenBabel2Wrapper::writeMolecule(const QString& filename, Avogadro::Molecule* mol)
{
OpenBabel::OBConversion Conv;
OpenBabel::OBFormat *outFormat = NULL;
OpenBabel::OBConversion Conv;
OpenBabel::OBFormat *outFormat = NULL;
std::ofstream outFileStream( QFile::encodeName(filename) );
if ( !outFileStream ) {
KMessageBox::error( 0,
i18n( "Cannot save to the specified file." )
);
return false;
}
outFormat = Conv.FormatFromExt( QFile::encodeName(filename) );
if (!outFormat || !Conv.SetOutFormat(outFormat))
{
KMessageBox::error( 0, i18n("Unrecognized file format extension. Please append an extension to the file name, "
"for example \".cml\".") );
delete mol;
return false;
}
Conv.SetInAndOutFormats( outFormat,outFormat );
OpenBabel::OBMol obmol = mol->OBMol();
Conv.Write( &obmol, &outFileStream );
return true;
std::ofstream outFileStream(QFile::encodeName(filename));
if (!outFileStream) {
KMessageBox::error(0, i18n("Cannot save to the specified file."));
return false;
}
outFormat = Conv.FormatFromExt(QFile::encodeName(filename));
if (!outFormat || !Conv.SetOutFormat(outFormat)) {
KMessageBox::error(0, i18n("Unrecognized file format extension. Please append an extension to the file name, "
"for example \".cml\"."));
delete mol;
return false;
}
Conv.SetInAndOutFormats(outFormat,outFormat);
OpenBabel::OBMol obmol = mol->OBMol();
Conv.Write(&obmol, &outFileStream);
return true;
}
QString OpenBabel2Wrapper::getFormula( Avogadro::Molecule* molecule )
QString OpenBabel2Wrapper::getFormula(Avogadro::Molecule* molecule)
{
QString formula( molecule->OBMol().GetFormula().c_str() );
return formula;
QString formula(molecule->OBMol().GetFormula().c_str());
return formula;
}
QString OpenBabel2Wrapper::getPrettyFormula( Avogadro::Molecule* molecule )
QString OpenBabel2Wrapper::getPrettyFormula(Avogadro::Molecule* molecule)
{
QString formula( molecule->OBMol().GetSpacedFormula(1,"").c_str() );
formula.replace( QRegExp( "(\\d+)" ), "<sub>\\1</sub>" );
return formula;
QString formula(molecule->OBMol().GetSpacedFormula(1, "").c_str());
formula.replace(QRegExp("(\\d+)"), "<sub>\\1</sub>");
return formula;
}
......@@ -27,18 +27,18 @@
*/
class COMPOUNDVIEWER_EXPORT OpenBabel2Wrapper
{
public:
/**
* This class reads the molecule in the file @p filename. It returns 0 if
* the file couldn't be read.
*/
static Avogadro::Molecule* readMolecule( const QString& filename );
static bool writeMolecule( const QString& filename, Avogadro::Molecule* );
static QString getFormula( Avogadro::Molecule* molecule );
static QString getPrettyFormula( Avogadro::Molecule* molecule );
public:
/**
* This class reads the molecule in the file @p filename. It returns 0 if
* the file couldn't be read.
*/
static Avogadro::Molecule *readMolecule(const QString& filename);
static bool writeMolecule(const QString& filename, Avogadro::Molecule *);
static QString getFormula(Avogadro::Molecule *molecule);
static QString getPrettyFormula(Avogadro::Molecule *molecule);
};
#endif // OPENBABEL2WRAPPER_H
/***************************************************************************
* Copyright (C) 2005 by Carsten Niehaus *
* cniehaus@kde.org *
* Copyright (C) 2005 by Carsten Niehaus <cniehaus@kde.org> *
* *
* 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 *
......@@ -19,6 +18,7 @@
***************************************************************************/
#include "chemicaldataobject.h"
#include <kunitconversion/converter.h>
#include <kdebug.h>
......@@ -47,7 +47,7 @@ ChemicalDataObjectPrivate::~ChemicalDataObjectPrivate()
}
//##############
ChemicalDataObject::ChemicalDataObject( const QVariant& v, BlueObelisk type, const QVariant& errorValue )
ChemicalDataObject::ChemicalDataObject(const QVariant& v, BlueObelisk type, const QVariant& errorValue)
: d(new ChemicalDataObjectPrivate)
{
d->m_value = v;
......@@ -78,34 +78,38 @@ ChemicalDataObject& ChemicalDataObject::operator=(const ChemicalDataObject &othe
return *this;
}
bool ChemicalDataObject::operator==( const int v ) const
bool ChemicalDataObject::operator==(const int v) const
{
if ( d->m_value.type() != QVariant::Int )
if (d->m_value.type() != QVariant::Int) {
return false;
}
return d->m_value.toInt() == v;
}
bool ChemicalDataObject::operator==( const bool v ) const
bool ChemicalDataObject::operator==(const bool v) const
{
if ( d->m_value.type() != QVariant::Bool )
if (d->m_value.type() != QVariant::Bool) {
return false;
}
return d->m_value.toBool() == v;
}
bool ChemicalDataObject::operator==( const double v ) const
bool ChemicalDataObject::operator==(const double v) const
{
if ( d->m_value.type() != QVariant::Double )
if (d->m_value.type() != QVariant::Double) {
return false;
}
return d->m_value.toDouble() == v;
}
bool ChemicalDataObject::operator==( const QString& v ) const
bool ChemicalDataObject::operator==(const QString& v) const
{
if (