mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Use QString for model properties.
This commit is contained in:
parent
05cafd4055
commit
a9be648237
4 changed files with 46 additions and 38 deletions
|
@ -42,32 +42,38 @@ void lcModelProperties::SaveDefaults()
|
||||||
|
|
||||||
void lcModelProperties::SaveLDraw(QTextStream& Stream) const
|
void lcModelProperties::SaveLDraw(QTextStream& Stream) const
|
||||||
{
|
{
|
||||||
if (!mName.IsEmpty())
|
QLatin1String LineEnding("\r\n");
|
||||||
Stream << QLatin1String("0 !LEOCAD MODEL NAME ") << mName.Buffer() << endl;
|
|
||||||
|
|
||||||
if (!mAuthor.IsEmpty())
|
if (!mName.isEmpty())
|
||||||
Stream << QLatin1String("0 !LEOCAD MODEL AUTHOR ") << mAuthor.Buffer() << endl;
|
Stream << QLatin1String("0 !LEOCAD MODEL NAME ") << mName << LineEnding;
|
||||||
|
|
||||||
if (!mDescription.IsEmpty())
|
if (!mAuthor.isEmpty())
|
||||||
Stream << QLatin1String("0 !LEOCAD MODEL DESCRIPTION ") << mDescription.Buffer() << endl;
|
Stream << QLatin1String("0 !LEOCAD MODEL AUTHOR ") << mAuthor << LineEnding;
|
||||||
|
|
||||||
if (!mComments.IsEmpty())
|
if (!mDescription.isEmpty())
|
||||||
Stream << QLatin1String("0 !LEOCAD MODEL COMMENTS ") << mComments.Buffer() << endl;
|
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)
|
switch (mBackgroundType)
|
||||||
{
|
{
|
||||||
case LC_BACKGROUND_SOLID:
|
case LC_BACKGROUND_SOLID:
|
||||||
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE SOLID") << endl;
|
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE SOLID\r\n");
|
||||||
break;
|
break;
|
||||||
case LC_BACKGROUND_GRADIENT:
|
case LC_BACKGROUND_GRADIENT:
|
||||||
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE GRADIENT") << endl;
|
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE GRADIENT\r\n");
|
||||||
break;
|
break;
|
||||||
case LC_BACKGROUND_IMAGE:
|
case LC_BACKGROUND_IMAGE:
|
||||||
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE IMAGE") << endl;
|
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND_TYPE IMAGE\r\n");
|
||||||
break;
|
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;
|
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND GRADIENT_COLORS ") << mBackgroundGradientColor1[0] << ' ' << mBackgroundGradientColor1[1] << ' ' << mBackgroundGradientColor1[2] << ' ' << mBackgroundGradientColor2[0] << ' ' << mBackgroundGradientColor2[1] << ' ' << mBackgroundGradientColor2[2] << endl;
|
||||||
|
|
||||||
if (!mBackgroundImage.IsEmpty())
|
if (!mBackgroundImage.IsEmpty())
|
||||||
|
@ -84,6 +90,7 @@ void lcModelProperties::SaveLDraw(QTextStream& Stream) const
|
||||||
|
|
||||||
void lcModelProperties::ParseLDrawLine(char** Tokens)
|
void lcModelProperties::ParseLDrawLine(char** Tokens)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
if (!Tokens[4])
|
if (!Tokens[4])
|
||||||
return;
|
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]);
|
sprintf(Line, "0 !LEOCAD MODEL BACKGROUND SOLID_COLOR %.2f %.2f %.2f\r\n", mBackgroundSolidColor[0], mBackgroundSolidColor[1], mBackgroundSolidColor[2]);
|
||||||
File.WriteBuffer(Line, strlen(Line));
|
File.WriteBuffer(Line, strlen(Line));
|
||||||
|
|
|
@ -57,10 +57,10 @@ public:
|
||||||
void SaveLDraw(QTextStream& Stream) const;
|
void SaveLDraw(QTextStream& Stream) const;
|
||||||
void ParseLDrawLine(char** Tokens);
|
void ParseLDrawLine(char** Tokens);
|
||||||
|
|
||||||
String mName;
|
QString mName;
|
||||||
String mAuthor;
|
QString mAuthor;
|
||||||
String mDescription;
|
QString mDescription;
|
||||||
String mComments;
|
QString mComments;
|
||||||
|
|
||||||
lcBackgroundType mBackgroundType;
|
lcBackgroundType mBackgroundType;
|
||||||
lcVector3 mBackgroundSolidColor;
|
lcVector3 mBackgroundSolidColor;
|
||||||
|
|
|
@ -287,8 +287,10 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
file->Seek(sh, SEEK_CUR);
|
file->Seek(sh, SEEK_CUR);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file->ReadBuffer(mProperties.mAuthor.GetBuffer(sh), sh);
|
String Author;
|
||||||
mProperties.mAuthor.Buffer()[sh] = 0;
|
file->ReadBuffer(Author.GetBuffer(sh), sh);
|
||||||
|
Author.Buffer()[sh] = 0;
|
||||||
|
mProperties.mAuthor = QString::fromUtf8(Author.Buffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
file->ReadBuffer(&ch, 1);
|
file->ReadBuffer(&ch, 1);
|
||||||
|
@ -297,8 +299,10 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
file->Seek(sh, SEEK_CUR);
|
file->Seek(sh, SEEK_CUR);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file->ReadBuffer(mProperties.mDescription.GetBuffer(sh), sh);
|
String Description;
|
||||||
mProperties.mDescription.Buffer()[sh] = 0;
|
file->ReadBuffer(Description.GetBuffer(sh), sh);
|
||||||
|
Description.Buffer()[sh] = 0;
|
||||||
|
mProperties.mDescription = QString::fromUtf8(Description.Buffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
file->ReadBuffer(&ch, 1);
|
file->ReadBuffer(&ch, 1);
|
||||||
|
@ -307,8 +311,11 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
file->Seek(sh, SEEK_CUR);
|
file->Seek(sh, SEEK_CUR);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file->ReadBuffer(mProperties.mComments.GetBuffer(sh), sh);
|
String Comments;
|
||||||
mProperties.mComments.Buffer()[sh] = 0;
|
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++)
|
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
||||||
mPieces[PieceIdx]->FileSave(*file);
|
mPieces[PieceIdx]->FileSave(*file);
|
||||||
|
|
||||||
const char* Author = mProperties.mAuthor.Buffer();
|
QByteArray Author = mProperties.mAuthor.toUtf8();
|
||||||
ch = lcMin(strlen(Author), 100U);
|
ch = lcMin(strlen(Author), 100U);
|
||||||
file->WriteBuffer(&ch, 1);
|
file->WriteBuffer(&ch, 1);
|
||||||
file->WriteBuffer(Author, ch);
|
file->WriteBuffer(Author, ch);
|
||||||
const char* Description = mProperties.mDescription.Buffer();
|
QByteArray Description = mProperties.mDescription.toUtf8();
|
||||||
ch = lcMin(strlen(Description), 100U);
|
ch = lcMin(strlen(Description), 100U);
|
||||||
file->WriteBuffer(&ch, 1);
|
file->WriteBuffer(&ch, 1);
|
||||||
file->WriteBuffer(Description, ch);
|
file->WriteBuffer(Description, ch);
|
||||||
const char* Comments = mProperties.mComments.Buffer();
|
QByteArray Comments = mProperties.mComments.toUtf8();
|
||||||
ch = lcMin(strlen(Comments), 255U);
|
ch = lcMin(strlen(Comments), 255U);
|
||||||
file->WriteBuffer(&ch, 1);
|
file->WriteBuffer(&ch, 1);
|
||||||
file->WriteBuffer(Comments, ch);
|
file->WriteBuffer(Comments, ch);
|
||||||
|
@ -3331,12 +3338,6 @@ void Project::HandleCommand(LC_COMMANDS id)
|
||||||
OBJFile.WriteLine(Line);
|
OBJFile.WriteLine(Line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mProperties.mAuthor.IsEmpty())
|
|
||||||
{
|
|
||||||
sprintf(Line, "# Author: %s\n", mProperties.mAuthor.Buffer());
|
|
||||||
OBJFile.WriteLine(Line);
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(buf, FileName);
|
strcpy(buf, FileName);
|
||||||
ptr = strrchr(buf, '.');
|
ptr = strrchr(buf, '.');
|
||||||
if (ptr)
|
if (ptr)
|
||||||
|
|
|
@ -25,9 +25,9 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
|
||||||
|
|
||||||
setWindowTitle(QString(tr("%1 Properties")).arg(options->Title.Buffer()));
|
setWindowTitle(QString(tr("%1 Properties")).arg(options->Title.Buffer()));
|
||||||
|
|
||||||
ui->descriptionEdit->setText(QString::fromUtf8(options->Properties.mDescription.Buffer()));
|
ui->descriptionEdit->setText(options->Properties.mDescription);
|
||||||
ui->authorEdit->setText(QString::fromUtf8(options->Properties.mAuthor.Buffer()));
|
ui->authorEdit->setText(options->Properties.mAuthor);
|
||||||
ui->commentsEdit->setText(QString::fromUtf8(options->Properties.mComments.Buffer()));
|
ui->commentsEdit->setText(options->Properties.mComments);
|
||||||
|
|
||||||
if (options->Properties.mBackgroundType == LC_BACKGROUND_IMAGE)
|
if (options->Properties.mBackgroundType == LC_BACKGROUND_IMAGE)
|
||||||
ui->imageRadio->setChecked(true);
|
ui->imageRadio->setChecked(true);
|
||||||
|
@ -127,9 +127,9 @@ lcQPropertiesDialog::~lcQPropertiesDialog()
|
||||||
|
|
||||||
void lcQPropertiesDialog::accept()
|
void lcQPropertiesDialog::accept()
|
||||||
{
|
{
|
||||||
options->Properties.mDescription = ui->descriptionEdit->text().toUtf8().data();
|
options->Properties.mDescription = ui->descriptionEdit->text();
|
||||||
options->Properties.mAuthor = ui->authorEdit->text().toUtf8().data();
|
options->Properties.mAuthor = ui->authorEdit->text();
|
||||||
options->Properties.mComments = ui->commentsEdit->toPlainText().toUtf8().data();
|
options->Properties.mComments = ui->commentsEdit->toPlainText();
|
||||||
|
|
||||||
if (ui->imageRadio->isChecked())
|
if (ui->imageRadio->isChecked())
|
||||||
options->Properties.mBackgroundType = LC_BACKGROUND_IMAGE;
|
options->Properties.mBackgroundType = LC_BACKGROUND_IMAGE;
|
||||||
|
|
Loading…
Reference in a new issue