float2string #4 (Spacing)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9445 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2005-01-06 13:48:13 +00:00
parent d7b224d692
commit 701b99ecd7
17 changed files with 98 additions and 51 deletions

View File

@ -1,3 +1,19 @@
2005-01-06 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* Spacing.[Ch]: New method getValueAsString().
* Spacing.[Ch]:
* bufferparams.C:
* ParagraphParameters.C:
* lyxlayout.C:
* text.C:
* text3.C: store/read spacing value as string.
* rowpainter.C: change float value (spacing_val) to double.
* bufferparams.C: add Spacing::Other to spacetranslator (fixes
broken custom document spacing).
2005-01-05 Lars Gullik Bjonnes <larsbj@gullik.net>
* lyxfunc.C (getStatus): moved from lyxfunc.C put into anon

View File

@ -223,7 +223,7 @@ void ParagraphParameters::read(LyXLex & lex)
} else if (tmp == "other") {
lex.next();
spacing(Spacing(Spacing::Other,
lex.getFloat()));
lex.getString()));
} else {
lex.printError("Unknown spacing token: '$$Token'");
}

View File

@ -12,12 +12,15 @@
#include <config.h>
#include "Spacing.h"
#include "support/lstrings.h"
#include "support/tostr.h"
#include <sstream>
#include <string>
using std::ios;
using std::istringstream;
using lyx::support::strToDbl;
//using std::ios;
using std::ostream;
using std::ostringstream;
using std::string;
@ -26,39 +29,51 @@ using std::string;
string const Spacing::spacing_string[]
= {"single", "onehalf", "double", "other"};
float Spacing::getValue() const
string const Spacing::getValueAsString() const
{
switch (space) {
case Default: // nothing special should happen with this...
case Single: return 1.0;
case Onehalf: return 1.25;
case Double: return 1.667;
case Single: return "1.0";
case Onehalf: return "1.25";
case Double: return "1.667";
case Other: return value;
}
return 1.0;
return "1.0";
}
double Spacing::getValue() const
{
return strToDbl(getValueAsString());
}
void Spacing::set(Spacing::Space sp, float val)
{
space = sp;
if (sp == Other) {
switch (int(val * 1000 + 0.5)) {
case 1000: space = Single; break;
case 1250: space = Onehalf; break;
case 1667: space = Double; break;
default: value = val; break;
}
}
set(sp, tostr(val));
}
void Spacing::set(Spacing::Space sp, string const & val)
{
float fval = 0.0;
istringstream istr(val);
istr >> fval;
set(sp, fval);
space = sp;
if (sp == Other) {
switch (int(strToDbl(val) * 1000 + 0.5)) {
case 1000:
space = Single;
break;
case 1250:
space = Onehalf;
break;
case 1667:
space = Double;
break;
default:
value = val;
break;
}
}
}
@ -69,10 +84,8 @@ void Spacing::writeFile(ostream & os, bool para) const
string cmd = para ? "\\paragraph_spacing " : "\\spacing ";
if (getSpace() == Spacing::Other) {
os.setf(ios::showpoint|ios::fixed);
os.precision(2);
os << cmd << spacing_string[getSpace()]
<< ' ' << getValue() << "\n";
<< ' ' << getValueAsString() << "\n";
} else {
os << cmd << spacing_string[getSpace()] << "\n";
}
@ -93,7 +106,7 @@ string const Spacing::writeEnvirBegin() const
{
ostringstream ost;
ost << "\\begin{spacing}{"
<< getValue() << '}';
<< getValueAsString() << '}';
return ost.str();
}
}

View File

@ -33,7 +33,7 @@ public:
Default
};
///
Spacing() : space(Default), value(1.0) {}
Spacing() : space(Default), value("1.0") {}
///
Spacing(Spacing::Space sp, float val = 1.0) {
set(sp, val);
@ -46,13 +46,15 @@ public:
return space == Default;
}
///
float getValue() const;
std::string const getValueAsString() const;
///
double getValue() const;
///
Spacing::Space getSpace() const { return space; }
///
void set(Spacing::Space sp, float val = 1.0);
///
void set(Spacing::Space sp, std::string const & val) ;
void set(Spacing::Space sp, std::string const & val);
///
void writeFile(std::ostream &, bool para = false) const;
///
@ -64,7 +66,7 @@ private:
///
Space space;
///
float value;
std::string value;
/// names of line spacing
static std::string const spacing_string[];
};
@ -75,7 +77,7 @@ inline
bool operator==(Spacing const & a, Spacing const & b)
{
return a.getSpace() == b.getSpace()
&& a.getValue() == b.getValue();
&& a.getValueAsString() == b.getValueAsString();
}
///

View File

@ -263,6 +263,7 @@ SpaceTranslator const init_spacetranslator()
translator.addPair("single", Spacing::Single);
translator.addPair("onehalf", Spacing::Onehalf);
translator.addPair("double", Spacing::Double);
translator.addPair("other", Spacing::Other);
return translator;
}
@ -583,7 +584,7 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
} else if (token == "\\spacing") {
string nspacing;
lex >> nspacing;
float tmp_val = 0.0;
string tmp_val;
if (nspacing == "other") {
lex >> tmp_val;
}

View File

@ -1,3 +1,8 @@
2005-01-06 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* QDocument.C:
* QParagraph.C: store all float/double values as strings.
2005-01-05 Lars Gullik Bjonnes <larsbj@gullik.net>
* ui/moc/Makefile.am (libqt2uimoc_la_LINK): improve link trick

View File

@ -316,9 +316,7 @@ void QDocument::apply()
break;
case 3:
params.spacing().set(Spacing::Other,
dialog_->textLayoutModule->
lspacingLE->text().toFloat()
);
fromqstr(dialog_->textLayoutModule->lspacingLE->text()));
break;
}
@ -567,9 +565,9 @@ void QDocument::update_contents()
dialog_->textLayoutModule->lspacingCO->setCurrentItem(nitem);
if (params.spacing().getSpace() == Spacing::Other) {
dialog_->textLayoutModule->lspacingLE->setText(
toqstr(tostr(params.spacing().getValue())));
dialog_->setLSpacing(3);
toqstr(params.spacing().getValueAsString()));
}
dialog_->setLSpacing(nitem);
if (params.paragraph_separation
== BufferParams::PARSEP_INDENT) {

View File

@ -172,8 +172,7 @@ void QParagraph::update_contents()
}
dialog_->linespacing->setCurrentItem(linespacing);
if (space.getSpace() == Spacing::Other) {
string const sp = tostr(space.getValue());
dialog_->linespacingValue->setText(toqstr(sp));
dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
dialog_->linespacingValue->setEnabled(true);
} else {
dialog_->linespacingValue->setText("");

View File

@ -1,3 +1,8 @@
2005-01-06 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* FormDocument.C:
* FormParagraph.C: store all float/double values as strings.
2005-01-05 Lars Gullik Bjonnes <larsbj@gullik.net>
* pch.h: remove duplicate entries

View File

@ -1173,7 +1173,7 @@ void FormDocument::class_update(BufferParams const & params)
bool const spacing_input = pos == 4;
setEnabled(class_->input_spacing, spacing_input);
string const input = spacing_input ? tostr(params.spacing().getValue()) : string();
string const input = spacing_input ? params.spacing().getValueAsString() : string();
fl_set_input(class_->input_spacing, input.c_str());
}

View File

@ -266,8 +266,8 @@ void FormParagraph::update()
bool const spacing_other = space.getSpace() == Spacing::Other;
setEnabled(dialog_->input_linespacing, spacing_other);
if (spacing_other) {
string const sp = tostr(space.getValue());
fl_set_input(dialog_->input_linespacing, sp.c_str());
fl_set_input(dialog_->input_linespacing,
space.getValueAsString().c_str());
} else {
fl_set_input(dialog_->input_linespacing, "");
}

View File

@ -785,7 +785,7 @@ void LyXLayout::readSpacing(LyXLex & lexrc)
break;
case ST_OTHER:
lexrc.next();
spacing.set(Spacing::Other, lexrc.getFloat());
spacing.set(Spacing::Other, lexrc.getString());
break;
}
}

View File

@ -509,7 +509,7 @@ void RowPainter::paintFirst()
// the top.
if (layout->counter == "chapter") {
if (buffer.params().secnumdepth >= 0) {
float spacing_val = 1.0;
double spacing_val = 1.0;
if (!parparams.spacing().isDefault()) {
spacing_val = parparams.spacing().getValue();
} else {
@ -550,7 +550,7 @@ void RowPainter::paintFirst()
LyXFont font = getLabelFont();
if (!par_.getLabelstring().empty()) {
string const str = par_.getLabelstring();
float spacing_val = 1.0;
double spacing_val = 1.0;
if (!parparams.spacing().isDefault()) {
spacing_val = parparams.spacing().getValue();
} else {

View File

@ -1,3 +1,7 @@
2005-01-06 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* Spacing.h: adapt dummy file to the changes in src/Spacing.h.
2005-01-04 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* preamble.C (parse_preamble): handle second optional arg of

View File

@ -16,6 +16,8 @@
#ifndef SPACING_H
#define SPACING_H
#include <string>
class Spacing {
public:
///
@ -26,8 +28,10 @@ public:
Other,
Default
};
///
void set(Spacing::Space, float = 1.0) {}
///
void set(Spacing::Space sp, std::string const & val) {}
};
#endif // NOT SPACING_H

View File

@ -2134,7 +2134,7 @@ string LyXText::currentState(LCursor & cur)
os << _("Double");
break;
case Spacing::Other:
os << _("Other (") << spacing.getValue() << ')';
os << _("Other (") << spacing.getValueAsString() << ')';
break;
case Spacing::Default:
// should never happen, do nothing

View File

@ -753,15 +753,15 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_PARAGRAPH_SPACING: {
Paragraph & par = cur.paragraph();
Spacing::Space cur_spacing = par.params().spacing().getSpace();
float cur_value = 1.0;
string cur_value = "1.0";
if (cur_spacing == Spacing::Other)
cur_value = par.params().spacing().getValue();
cur_value = par.params().spacing().getValueAsString();
istringstream is(cmd.argument);
string tmp;
is >> tmp;
Spacing::Space new_spacing = cur_spacing;
float new_value = cur_value;
string new_value = cur_value;
if (tmp.empty()) {
lyxerr << "Missing argument to `paragraph-spacing'"
<< endl;
@ -773,10 +773,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
new_spacing = Spacing::Double;
} else if (tmp == "other") {
new_spacing = Spacing::Other;
float tmpval = 0.0;
string tmpval = "0.0";
is >> tmpval;
lyxerr << "new_value = " << tmpval << endl;
if (tmpval != 0.0)
if (tmpval != "0.0")
new_value = tmpval;
} else if (tmp == "default") {
new_spacing = Spacing::Default;