mirror of
https://github.com/leozide/leocad
synced 2025-02-06 08:46:06 +01:00
Workaround for a bug in QTextStream::pos() that was causing some mpd files to fail to load.
This commit is contained in:
parent
b1ed33ac3f
commit
2fe1ed273a
3 changed files with 17 additions and 13 deletions
|
@ -308,7 +308,7 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
|
||||||
Stream.flush();
|
Stream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcModel::LoadLDraw(QTextStream& Stream)
|
void lcModel::LoadLDraw(QIODevice& Device)
|
||||||
{
|
{
|
||||||
lcPiece* Piece = NULL;
|
lcPiece* Piece = NULL;
|
||||||
lcCamera* Camera = NULL;
|
lcCamera* Camera = NULL;
|
||||||
|
@ -316,10 +316,10 @@ void lcModel::LoadLDraw(QTextStream& Stream)
|
||||||
lcArray<lcGroup*> CurrentGroups;
|
lcArray<lcGroup*> CurrentGroups;
|
||||||
int CurrentStep = 1;
|
int CurrentStep = 1;
|
||||||
|
|
||||||
while (!Stream.atEnd())
|
while (!Device.atEnd())
|
||||||
{
|
{
|
||||||
qint64 Pos = Stream.pos();
|
qint64 Pos = Device.pos();
|
||||||
QString Line = Stream.readLine().trimmed();
|
QString Line = Device.readLine().trimmed();
|
||||||
QTextStream LineStream(&Line, QIODevice::ReadOnly);
|
QTextStream LineStream(&Line, QIODevice::ReadOnly);
|
||||||
|
|
||||||
QString Token;
|
QString Token;
|
||||||
|
@ -333,7 +333,7 @@ void lcModel::LoadLDraw(QTextStream& Stream)
|
||||||
{
|
{
|
||||||
if (!mProperties.mName.isEmpty())
|
if (!mProperties.mName.isEmpty())
|
||||||
{
|
{
|
||||||
Stream.seek(Pos);
|
Device.seek(Pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,8 +847,9 @@ void lcModel::Paste()
|
||||||
|
|
||||||
lcModel* Model = new lcModel(QString());
|
lcModel* Model = new lcModel(QString());
|
||||||
|
|
||||||
QTextStream Stream(&g_App->mClipboard);
|
QBuffer Buffer(&g_App->mClipboard);
|
||||||
Model->LoadLDraw(Stream);
|
Buffer.open(QIODevice::ReadOnly);
|
||||||
|
Model->LoadLDraw(Buffer);
|
||||||
|
|
||||||
Merge(Model);
|
Merge(Model);
|
||||||
SaveCheckpoint(tr("Pasting"));
|
SaveCheckpoint(tr("Pasting"));
|
||||||
|
@ -1137,8 +1138,9 @@ void lcModel::LoadCheckPoint(lcModelHistoryEntry* CheckPoint)
|
||||||
{
|
{
|
||||||
DeleteModel();
|
DeleteModel();
|
||||||
|
|
||||||
QTextStream Stream(CheckPoint->File, QIODevice::ReadOnly);
|
QBuffer Buffer(&CheckPoint->File);
|
||||||
LoadLDraw(Stream);
|
Buffer.open(QIODevice::ReadOnly);
|
||||||
|
LoadLDraw(Buffer);
|
||||||
|
|
||||||
gMainWindow->UpdateFocusObject(GetFocusObject());
|
gMainWindow->UpdateFocusObject(GetFocusObject());
|
||||||
gMainWindow->UpdateCameraMenu();
|
gMainWindow->UpdateCameraMenu();
|
||||||
|
|
|
@ -200,7 +200,7 @@ public:
|
||||||
void ShowEditGroupsDialog();
|
void ShowEditGroupsDialog();
|
||||||
|
|
||||||
void SaveLDraw(QTextStream& Stream, bool SelectedOnly) const;
|
void SaveLDraw(QTextStream& Stream, bool SelectedOnly) const;
|
||||||
void LoadLDraw(QTextStream& Stream);
|
void LoadLDraw(QIODevice& Device);
|
||||||
bool LoadBinary(lcFile* File);
|
bool LoadBinary(lcFile* File);
|
||||||
void Merge(lcModel* Other);
|
void Merge(lcModel* Other);
|
||||||
|
|
||||||
|
|
|
@ -202,13 +202,15 @@ bool Project::Load(const QString& FileName)
|
||||||
|
|
||||||
if (Extension == QLatin1String("dat") || Extension == QLatin1String("ldr") || Extension == QLatin1String("mpd"))
|
if (Extension == QLatin1String("dat") || Extension == QLatin1String("ldr") || Extension == QLatin1String("mpd"))
|
||||||
{
|
{
|
||||||
QTextStream Stream(&File);
|
QByteArray FileData = File.readAll();
|
||||||
|
QBuffer Buffer(&FileData);
|
||||||
|
Buffer.open(QIODevice::ReadOnly);
|
||||||
|
|
||||||
while (!Stream.atEnd())
|
while (!Buffer.atEnd())
|
||||||
{
|
{
|
||||||
lcModel* Model = new lcModel(QString());
|
lcModel* Model = new lcModel(QString());
|
||||||
mModels.Add(Model);
|
mModels.Add(Model);
|
||||||
Model->LoadLDraw(Stream);
|
Model->LoadLDraw(Buffer);
|
||||||
Model->SetSaved();
|
Model->SetSaved();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue