Use QString for model properties.

This commit is contained in:
leo 2014-09-06 01:34:03 +00:00
parent 05cafd4055
commit a9be648237
4 changed files with 46 additions and 38 deletions

View file

@ -42,32 +42,38 @@ void lcModelProperties::SaveDefaults()
void lcModelProperties::SaveLDraw(QTextStream& Stream) const
{
if (!mName.IsEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL NAME ") << mName.Buffer() << endl;
QLatin1String LineEnding("\r\n");
if (!mAuthor.IsEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL AUTHOR ") << mAuthor.Buffer() << endl;
if (!mName.isEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL NAME ") << mName << LineEnding;
if (!mDescription.IsEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL DESCRIPTION ") << mDescription.Buffer() << endl;
if (!mAuthor.isEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL AUTHOR ") << mAuthor << LineEnding;
if (!mComments.IsEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL COMMENTS ") << mComments.Buffer() << endl;
if (!mDescription.isEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL DESCRIPTION ") << mDescription << LineEnding;
if (!mComments.isEmpty())
{
QStringList Comments = mComments.split('\n');
for (const QString& Comment : Comments)
Stream << QLatin1String("0 !LEOCAD MODEL COMMENT ") << Comment << LineEnding;
}
switch (mBackgroundType)
{
case LC_BACKGROUND_SOLID:
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE SOLID") << endl;
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE SOLID\r\n");
break;
case LC_BACKGROUND_GRADIENT:
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE GRADIENT") << endl;
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE GRADIENT\r\n");
break;
case LC_BACKGROUND_IMAGE:
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE IMAGE") << endl;
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE IMAGE\r\n");
break;
}
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND SOLID_COLOR ") << mBackgroundSolidColor[0] << ' ' << mBackgroundSolidColor[1] << ' ' << mBackgroundSolidColor[2] << endl;
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND COLOR ") << mBackgroundSolidColor[0] << ' ' << mBackgroundSolidColor[1] << ' ' << mBackgroundSolidColor[2] << endl;
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND GRADIENT_COLORS ") << mBackgroundGradientColor1[0] << ' ' << mBackgroundGradientColor1[1] << ' ' << mBackgroundGradientColor1[2] << ' ' << mBackgroundGradientColor2[0] << ' ' << mBackgroundGradientColor2[1] << ' ' << mBackgroundGradientColor2[2] << endl;
if (!mBackgroundImage.IsEmpty())
@ -84,6 +90,7 @@ void lcModelProperties::SaveLDraw(QTextStream& Stream) const
void lcModelProperties::ParseLDrawLine(char** Tokens)
{
/*
if (!Tokens[4])
return;
@ -151,7 +158,7 @@ void lcModelProperties::ParseLDrawLine(char** Tokens)
}
}
*/
/*
sprintf(Line, "0 !LEOCAD MODEL BACKGROUND SOLID_COLOR %.2f %.2f %.2f\r\n", mBackgroundSolidColor[0], mBackgroundSolidColor[1], mBackgroundSolidColor[2]);
File.WriteBuffer(Line, strlen(Line));

View file

@ -57,10 +57,10 @@ public:
void SaveLDraw(QTextStream& Stream) const;
void ParseLDrawLine(char** Tokens);
String mName;
String mAuthor;
String mDescription;
String mComments;
QString mName;
QString mAuthor;
QString mDescription;
QString mComments;
lcBackgroundType mBackgroundType;
lcVector3 mBackgroundSolidColor;

View file

@ -287,8 +287,10 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
file->Seek(sh, SEEK_CUR);
else
{
file->ReadBuffer(mProperties.mAuthor.GetBuffer(sh), sh);
mProperties.mAuthor.Buffer()[sh] = 0;
String Author;
file->ReadBuffer(Author.GetBuffer(sh), sh);
Author.Buffer()[sh] = 0;
mProperties.mAuthor = QString::fromUtf8(Author.Buffer());
}
file->ReadBuffer(&ch, 1);
@ -297,8 +299,10 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
file->Seek(sh, SEEK_CUR);
else
{
file->ReadBuffer(mProperties.mDescription.GetBuffer(sh), sh);
mProperties.mDescription.Buffer()[sh] = 0;
String Description;
file->ReadBuffer(Description.GetBuffer(sh), sh);
Description.Buffer()[sh] = 0;
mProperties.mDescription = QString::fromUtf8(Description.Buffer());
}
file->ReadBuffer(&ch, 1);
@ -307,8 +311,11 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
file->Seek(sh, SEEK_CUR);
else
{
file->ReadBuffer(mProperties.mComments.GetBuffer(sh), sh);
mProperties.mComments.Buffer()[sh] = 0;
String Comments;
file->ReadBuffer(Comments.GetBuffer(sh), sh);
Comments.Buffer()[sh] = 0;
mProperties.mComments = QString::fromUtf8(Comments.Buffer());
mProperties.mComments.replace(QLatin1String("\r\n"), QLatin1String("\n"));
}
}
}
@ -611,15 +618,15 @@ void Project::FileSave(lcFile* file, bool bUndo)
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
mPieces[PieceIdx]->FileSave(*file);
const char* Author = mProperties.mAuthor.Buffer();
QByteArray Author = mProperties.mAuthor.toUtf8();
ch = lcMin(strlen(Author), 100U);
file->WriteBuffer(&ch, 1);
file->WriteBuffer(Author, ch);
const char* Description = mProperties.mDescription.Buffer();
QByteArray Description = mProperties.mDescription.toUtf8();
ch = lcMin(strlen(Description), 100U);
file->WriteBuffer(&ch, 1);
file->WriteBuffer(Description, ch);
const char* Comments = mProperties.mComments.Buffer();
QByteArray Comments = mProperties.mComments.toUtf8();
ch = lcMin(strlen(Comments), 255U);
file->WriteBuffer(&ch, 1);
file->WriteBuffer(Comments, ch);
@ -3331,12 +3338,6 @@ void Project::HandleCommand(LC_COMMANDS id)
OBJFile.WriteLine(Line);
}
if (!mProperties.mAuthor.IsEmpty())
{
sprintf(Line, "# Author: %s\n", mProperties.mAuthor.Buffer());
OBJFile.WriteLine(Line);
}
strcpy(buf, FileName);
ptr = strrchr(buf, '.');
if (ptr)

View file

@ -25,9 +25,9 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
setWindowTitle(QString(tr("%1 Properties")).arg(options->Title.Buffer()));
ui->descriptionEdit->setText(QString::fromUtf8(options->Properties.mDescription.Buffer()));
ui->authorEdit->setText(QString::fromUtf8(options->Properties.mAuthor.Buffer()));
ui->commentsEdit->setText(QString::fromUtf8(options->Properties.mComments.Buffer()));
ui->descriptionEdit->setText(options->Properties.mDescription);
ui->authorEdit->setText(options->Properties.mAuthor);
ui->commentsEdit->setText(options->Properties.mComments);
if (options->Properties.mBackgroundType == LC_BACKGROUND_IMAGE)
ui->imageRadio->setChecked(true);
@ -127,9 +127,9 @@ lcQPropertiesDialog::~lcQPropertiesDialog()
void lcQPropertiesDialog::accept()
{
options->Properties.mDescription = ui->descriptionEdit->text().toUtf8().data();
options->Properties.mAuthor = ui->authorEdit->text().toUtf8().data();
options->Properties.mComments = ui->commentsEdit->toPlainText().toUtf8().data();
options->Properties.mDescription = ui->descriptionEdit->text();
options->Properties.mAuthor = ui->authorEdit->text();
options->Properties.mComments = ui->commentsEdit->toPlainText();
if (ui->imageRadio->isChecked())
options->Properties.mBackgroundType = LC_BACKGROUND_IMAGE;