mirror of
https://github.com/leozide/leocad.git
synced 2026-07-28 04:07:11 +00:00
Use QString for group names.
This commit is contained in:
+20
-22
@@ -15,34 +15,24 @@ lcGroup::~lcGroup()
|
||||
void lcGroup::FileLoad(lcFile* File)
|
||||
{
|
||||
lcint32 GroupIndex;
|
||||
char Name[LC_MAX_GROUP_NAME + 1];
|
||||
|
||||
File->ReadU8();
|
||||
File->ReadBuffer(m_strName, 65);
|
||||
File->ReadBuffer(Name, sizeof(Name));
|
||||
mName = QString::fromUtf8(Name);
|
||||
File->ReadVector3();
|
||||
File->ReadS32(&GroupIndex, 1);
|
||||
mGroup = (lcGroup*)(long)GroupIndex;
|
||||
}
|
||||
|
||||
void lcGroup::FileSave(lcFile* File, const lcArray<lcGroup*>& Groups)
|
||||
{
|
||||
lcuint8 Version = 1; // LeoCAD 0.60
|
||||
|
||||
File->WriteU8(Version);
|
||||
File->WriteBuffer(m_strName, 65);
|
||||
File->WriteVector3(lcVector3(0.0f, 0.0f, 0.0f));
|
||||
|
||||
lcint32 GroupIndex = Groups.FindIndex(mGroup);
|
||||
File->WriteS32(&GroupIndex, 1);
|
||||
}
|
||||
|
||||
void lcGroup::CreateName(const lcArray<lcGroup*>& Groups)
|
||||
{
|
||||
if (m_strName[0])
|
||||
if (!mName.isEmpty())
|
||||
{
|
||||
bool Found = false;
|
||||
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
|
||||
{
|
||||
if (!strcmp(Groups[GroupIdx]->m_strName, m_strName))
|
||||
if (Groups[GroupIdx]->mName == mName)
|
||||
{
|
||||
Found = true;
|
||||
break;
|
||||
@@ -53,14 +43,22 @@ void lcGroup::CreateName(const lcArray<lcGroup*>& Groups)
|
||||
return;
|
||||
}
|
||||
|
||||
int i, max = 0;
|
||||
const char* Prefix = "Group ";
|
||||
int Max = 0;
|
||||
QString Prefix = QApplication::tr("Group #");
|
||||
int Length = Prefix.length();
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
|
||||
if (strncmp(Groups[GroupIdx]->m_strName, Prefix, strlen(Prefix)) == 0)
|
||||
if (sscanf(Groups[GroupIdx]->m_strName + strlen(Prefix), " %d", &i) == 1)
|
||||
if (i > max)
|
||||
max = i;
|
||||
{
|
||||
const QString& Name = Groups[GroupIdx]->mName;
|
||||
|
||||
sprintf(m_strName, "%s %d", Prefix, max+1);
|
||||
if (Name.startsWith(Prefix))
|
||||
{
|
||||
bool Ok = false;
|
||||
int GroupNumber = Name.mid(Length).toInt(&Ok);
|
||||
if (Ok && GroupNumber > Max)
|
||||
Max = GroupNumber;
|
||||
}
|
||||
}
|
||||
|
||||
mName = Prefix + QString::number(Max + 1);
|
||||
}
|
||||
|
||||
+1
-2
@@ -17,11 +17,10 @@ public:
|
||||
}
|
||||
|
||||
void FileLoad(lcFile* File);
|
||||
void FileSave(lcFile* File, const lcArray<lcGroup*>& Groups);
|
||||
void CreateName(const lcArray<lcGroup*>& Groups);
|
||||
|
||||
lcGroup* mGroup;
|
||||
char m_strName[LC_MAX_GROUP_NAME + 1];
|
||||
QString mName;
|
||||
};
|
||||
|
||||
#endif // _GROUP_H_
|
||||
|
||||
@@ -19,7 +19,6 @@ enum LC_DIALOG_TYPE
|
||||
LC_DIALOG_SELECT_BY_NAME,
|
||||
LC_DIALOG_MINIFIG,
|
||||
LC_DIALOG_PIECE_ARRAY,
|
||||
LC_DIALOG_PIECE_GROUP,
|
||||
LC_DIALOG_EDIT_GROUPS,
|
||||
LC_DIALOG_PREFERENCES,
|
||||
LC_DIALOG_CHECK_UPDATES,
|
||||
|
||||
@@ -1066,7 +1066,6 @@ void lcMainWindow::ShowPrintDialog()
|
||||
#include "lc_qselectdialog.h"
|
||||
#include "lc_qminifigdialog.h"
|
||||
#include "lc_qarraydialog.h"
|
||||
#include "lc_qgroupdialog.h"
|
||||
#include "lc_qeditgroupsdialog.h"
|
||||
#include "lc_qpreferencesdialog.h"
|
||||
#include "lc_qupdatedialog.h"
|
||||
@@ -1124,12 +1123,6 @@ bool lcMainWindow::DoDialog(LC_DIALOG_TYPE Type, void* Data)
|
||||
return Dialog.exec() == QDialog::Accepted;
|
||||
} break;
|
||||
|
||||
case LC_DIALOG_PIECE_GROUP:
|
||||
{
|
||||
lcQGroupDialog Dialog(this, Data);
|
||||
return Dialog.exec() == QDialog::Accepted;
|
||||
} break;
|
||||
|
||||
case LC_DIALOG_EDIT_GROUPS:
|
||||
{
|
||||
lcQEditGroupsDialog Dialog(this, Data);
|
||||
@@ -1521,8 +1514,8 @@ void lcMainWindow::UpdateSelectedObjects(int Flags, int SelectedCount, lcObject*
|
||||
Message.append(QString(" - %1 (ID: %2)").arg(Focus->GetName(), ((lcPiece*)Focus)->mPieceInfo->m_strName));
|
||||
|
||||
const lcGroup* Group = ((lcPiece*)Focus)->GetGroup();
|
||||
if (Group && Group->m_strName[0])
|
||||
Message.append(QString(" in group '%1'").arg(Group->m_strName));
|
||||
if (Group && !Group->mName.isEmpty())
|
||||
Message.append(QString(" in group '%1'").arg(Group->mName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
-25
@@ -13,6 +13,7 @@
|
||||
#include "view.h"
|
||||
#include "preview.h"
|
||||
#include "minifig.h"
|
||||
#include "lc_qgroupdialog.h"
|
||||
|
||||
void lcModelProperties::LoadDefaults()
|
||||
{
|
||||
@@ -360,7 +361,7 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool MPD, bool SelectedOnly) const
|
||||
{
|
||||
lcGroup* Group = PieceParents[ParentIdx];
|
||||
CurrentGroups.Add(Group);
|
||||
Stream << QLatin1String("0 !LEOCAD GROUP BEGIN ") << Group->m_strName << LineEnding;
|
||||
Stream << QLatin1String("0 !LEOCAD GROUP BEGIN ") << Group->mName << LineEnding;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -714,7 +715,9 @@ bool lcModel::LoadBinary(lcFile* file)
|
||||
|
||||
if (fv < 1.0f)
|
||||
{
|
||||
file->ReadBuffer(Group->m_strName, 65);
|
||||
char Name[LC_MAX_GROUP_NAME + 1];
|
||||
file->ReadBuffer(Name, sizeof(Name));
|
||||
Group->mName = QString::fromUtf8(Name);
|
||||
file->ReadBuffer(&ch, 1);
|
||||
Group->mGroup = (lcGroup*)-1;
|
||||
}
|
||||
@@ -1424,35 +1427,33 @@ void lcModel::RemoveStep(lcStep Step)
|
||||
SetCurrentStep(mCurrentStep);
|
||||
}
|
||||
|
||||
lcGroup* lcModel::AddGroup(const char* Prefix, lcGroup* Parent)
|
||||
lcGroup* lcModel::AddGroup(const QString& Prefix, lcGroup* Parent)
|
||||
{
|
||||
lcGroup* Group = new lcGroup();
|
||||
mGroups.Add(Group);
|
||||
|
||||
GetGroupName(Prefix, Group->m_strName);
|
||||
Group->mName = GetGroupName(Prefix);
|
||||
Group->mGroup = Parent;
|
||||
|
||||
return Group;
|
||||
}
|
||||
|
||||
lcGroup* lcModel::GetGroup(const char* Name, bool CreateIfMissing)
|
||||
lcGroup* lcModel::GetGroup(const QString& Name, bool CreateIfMissing)
|
||||
{
|
||||
for (int GroupIdx = 0; GroupIdx < mGroups.GetSize(); GroupIdx++)
|
||||
{
|
||||
lcGroup* Group = mGroups[GroupIdx];
|
||||
|
||||
if (!strcmp(Group->m_strName, Name))
|
||||
if (Group->mName == Name)
|
||||
return Group;
|
||||
}
|
||||
|
||||
if (CreateIfMissing)
|
||||
{
|
||||
lcGroup* Group = new lcGroup();
|
||||
Group->mName = Name;
|
||||
mGroups.Add(Group);
|
||||
|
||||
strncpy(Group->m_strName, Name, sizeof(Group->m_strName));
|
||||
Group->m_strName[sizeof(Group->m_strName) - 1] = 0;
|
||||
|
||||
return Group;
|
||||
}
|
||||
|
||||
@@ -1473,14 +1474,11 @@ void lcModel::GroupSelection()
|
||||
return;
|
||||
}
|
||||
|
||||
char GroupName[LC_MAX_GROUP_NAME + 1];
|
||||
|
||||
GetGroupName("Group #", GroupName);
|
||||
|
||||
if (!gMainWindow->DoDialog(LC_DIALOG_PIECE_GROUP, GroupName))
|
||||
lcQGroupDialog Dialog(gMainWindow, GetGroupName(tr("Group #")));
|
||||
if (Dialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
lcGroup* NewGroup = GetGroup(GroupName, true);
|
||||
lcGroup* NewGroup = GetGroup(Dialog.mName, true);
|
||||
|
||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
||||
{
|
||||
@@ -1646,23 +1644,25 @@ void lcModel::ShowEditGroupsDialog()
|
||||
}
|
||||
}
|
||||
|
||||
void lcModel::GetGroupName(const char* Prefix, char* GroupName)
|
||||
QString lcModel::GetGroupName(const QString& Prefix)
|
||||
{
|
||||
int Length = strlen(Prefix);
|
||||
int Length = Prefix.length();
|
||||
int Max = 0;
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < mGroups.GetSize(); GroupIdx++)
|
||||
{
|
||||
lcGroup* Group = mGroups[GroupIdx];
|
||||
int GroupNumber;
|
||||
const QString& Name = mGroups[GroupIdx]->mName;
|
||||
|
||||
if (strncmp(Group->m_strName, Prefix, Length) == 0)
|
||||
if (sscanf(Group->m_strName + Length, "%d", &GroupNumber) == 1)
|
||||
if (GroupNumber > Max)
|
||||
Max = GroupNumber;
|
||||
if (Name.startsWith(Prefix))
|
||||
{
|
||||
bool Ok = false;
|
||||
int GroupNumber = Name.mid(Length).toInt(&Ok);
|
||||
if (Ok && GroupNumber > Max)
|
||||
Max = GroupNumber;
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(GroupName, "%s%.2d", Prefix, Max + 1);
|
||||
return Prefix + QString::number(Max + 1);
|
||||
}
|
||||
|
||||
void lcModel::RemoveEmptyGroups()
|
||||
@@ -3665,7 +3665,7 @@ void lcModel::ShowMinifigDialog()
|
||||
|
||||
gMainWindow->mPreviewWidget->MakeCurrent();
|
||||
|
||||
lcGroup* Group = AddGroup("Minifig #", NULL);
|
||||
lcGroup* Group = AddGroup(tr("Minifig #"), NULL);
|
||||
lcArray<lcObject*> Pieces(LC_MFW_NUMITEMS);
|
||||
|
||||
for (int PartIdx = 0; PartIdx < LC_MFW_NUMITEMS; PartIdx++)
|
||||
|
||||
+3
-3
@@ -199,8 +199,8 @@ public:
|
||||
void ShowSelectedPiecesLater();
|
||||
void SetPieceSteps(const QList<QPair<lcPiece*, lcStep>>& PieceSteps);
|
||||
|
||||
lcGroup* AddGroup(const char* Prefix, lcGroup* Parent);
|
||||
lcGroup* GetGroup(const char* Name, bool CreateIfMissing);
|
||||
lcGroup* AddGroup(const QString& Prefix, lcGroup* Parent);
|
||||
lcGroup* GetGroup(const QString& Name, bool CreateIfMissing);
|
||||
void RemoveGroup(lcGroup* Group);
|
||||
void GroupSelection();
|
||||
void UngroupSelection();
|
||||
@@ -321,7 +321,7 @@ protected:
|
||||
void SaveCheckpoint(const QString& Description);
|
||||
void LoadCheckPoint(lcModelHistoryEntry* CheckPoint);
|
||||
|
||||
void GetGroupName(const char* Prefix, char* GroupName);
|
||||
QString GetGroupName(const QString& Prefix);
|
||||
void RemoveEmptyGroups();
|
||||
bool RemoveSelectedObjects();
|
||||
|
||||
|
||||
@@ -58,11 +58,11 @@ void lcQEditGroupsDialog::on_newGroup_clicked()
|
||||
|
||||
lcGroup* ParentGroup = (lcGroup*)CurrentItem->data(0, GroupRole).value<uintptr_t>();
|
||||
|
||||
lcGroup* NewGroup = lcGetActiveModel()->AddGroup("Group #", ParentGroup);
|
||||
lcGroup* NewGroup = lcGetActiveModel()->AddGroup(tr("Group #"), ParentGroup);
|
||||
mOptions->GroupParents[NewGroup] = ParentGroup;
|
||||
mOptions->NewGroups.append(NewGroup);
|
||||
|
||||
QTreeWidgetItem* GroupItem = new QTreeWidgetItem(CurrentItem, QStringList(NewGroup->m_strName));
|
||||
QTreeWidgetItem* GroupItem = new QTreeWidgetItem(CurrentItem, QStringList(NewGroup->mName));
|
||||
GroupItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable);
|
||||
GroupItem->setData(0, GroupRole, qVariantFromValue<uintptr_t>((uintptr_t)NewGroup));
|
||||
}
|
||||
@@ -121,8 +121,7 @@ void lcQEditGroupsDialog::UpdateParents(QTreeWidgetItem* ParentItem, lcGroup* Pa
|
||||
lcGroup* Group = (lcGroup*)ChildItem->data(0, GroupRole).value<uintptr_t>();
|
||||
|
||||
// todo: validate unique group name
|
||||
strncpy(Group->m_strName, ChildItem->text(0).toLatin1(), sizeof(Group->m_strName)); // todo: qstring
|
||||
Group->m_strName[sizeof(Group->m_strName) - 1] = 0;
|
||||
Group->mName = ChildItem->text(0);
|
||||
|
||||
mOptions->GroupParents[Group] = ParentGroup;
|
||||
|
||||
@@ -141,7 +140,7 @@ void lcQEditGroupsDialog::AddChildren(QTreeWidgetItem* ParentItem, lcGroup* Pare
|
||||
if (Parent != ParentGroup)
|
||||
continue;
|
||||
|
||||
QTreeWidgetItem* GroupItem = new QTreeWidgetItem(ParentItem, QStringList(Group->m_strName));
|
||||
QTreeWidgetItem* GroupItem = new QTreeWidgetItem(ParentItem, QStringList(Group->mName));
|
||||
GroupItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable);
|
||||
GroupItem->setData(0, GroupRole, qVariantFromValue<uintptr_t>((uintptr_t)Group));
|
||||
|
||||
|
||||
@@ -3,17 +3,13 @@
|
||||
#include "ui_lc_qgroupdialog.h"
|
||||
#include "group.h"
|
||||
|
||||
lcQGroupDialog::lcQGroupDialog(QWidget *parent, void *data) :
|
||||
lcQGroupDialog::lcQGroupDialog(QWidget *parent, const QString& Name) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::lcQGroupDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->name->setMaxLength(LC_MAX_GROUP_NAME);
|
||||
|
||||
options = (char*)data;
|
||||
|
||||
ui->name->setText(options);
|
||||
ui->name->setText(Name);
|
||||
}
|
||||
|
||||
lcQGroupDialog::~lcQGroupDialog()
|
||||
@@ -23,15 +19,15 @@ lcQGroupDialog::~lcQGroupDialog()
|
||||
|
||||
void lcQGroupDialog::accept()
|
||||
{
|
||||
QString name = ui->name->text();
|
||||
QString Name = ui->name->text();
|
||||
|
||||
if (name.isEmpty())
|
||||
if (Name.isEmpty())
|
||||
{
|
||||
QMessageBox::information(this, "LeoCAD", tr("Name cannot be empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(options, name.toLocal8Bit().data());
|
||||
mName = Name;
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ class lcQGroupDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit lcQGroupDialog(QWidget *parent, void *data);
|
||||
explicit lcQGroupDialog(QWidget *parent, const QString& Name);
|
||||
~lcQGroupDialog();
|
||||
|
||||
char *options;
|
||||
QString mName;
|
||||
|
||||
public slots:
|
||||
void accept();
|
||||
|
||||
@@ -183,7 +183,7 @@ void lcQSelectDialog::AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGr
|
||||
if (Group->mGroup != ParentGroup)
|
||||
continue;
|
||||
|
||||
QTreeWidgetItem* GroupItem = new QTreeWidgetItem(ParentItem, QStringList(Group->m_strName));
|
||||
QTreeWidgetItem* GroupItem = new QTreeWidgetItem(ParentItem, QStringList(Group->mName));
|
||||
|
||||
AddChildren(GroupItem, Group);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user