mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Added button to import inventories to a palette.
This commit is contained in:
parent
7a78f86cd5
commit
220fb26a3a
3 changed files with 56 additions and 1 deletions
|
@ -2,24 +2,33 @@
|
||||||
#include "lc_partpalettedialog.h"
|
#include "lc_partpalettedialog.h"
|
||||||
#include "ui_lc_partpalettedialog.h"
|
#include "ui_lc_partpalettedialog.h"
|
||||||
#include "lc_partselectionwidget.h"
|
#include "lc_partselectionwidget.h"
|
||||||
|
#include "lc_setsdatabasedialog.h"
|
||||||
|
|
||||||
lcPartPaletteDialog::lcPartPaletteDialog(QWidget* Parent, std::vector<lcPartPalette>& PartPalettes)
|
lcPartPaletteDialog::lcPartPaletteDialog(QWidget* Parent, std::vector<lcPartPalette>& PartPalettes)
|
||||||
: QDialog(Parent), ui(new Ui::lcPartPaletteDialog), mPartPalettes(PartPalettes)
|
: QDialog(Parent), ui(new Ui::lcPartPaletteDialog), mPartPalettes(PartPalettes)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
||||||
|
ui->ImportButton->hide();
|
||||||
|
#endif
|
||||||
|
|
||||||
for (const lcPartPalette& Palette : PartPalettes)
|
for (const lcPartPalette& Palette : PartPalettes)
|
||||||
{
|
{
|
||||||
QListWidgetItem* Item = new QListWidgetItem(Palette.Name);
|
QListWidgetItem* Item = new QListWidgetItem(Palette.Name);
|
||||||
Item->setData(Qt::UserRole, qVariantFromValue<uintptr_t>(reinterpret_cast<uintptr_t>(&Palette)));
|
Item->setData(Qt::UserRole, qVariantFromValue<uintptr_t>(reinterpret_cast<uintptr_t>(&Palette)));
|
||||||
ui->PaletteList->addItem(Item);
|
ui->PaletteList->addItem(Item);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->PaletteList->setCurrentRow(0);
|
ui->PaletteList->setCurrentRow(0);
|
||||||
UpdateButtons();
|
UpdateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
lcPartPaletteDialog::~lcPartPaletteDialog()
|
lcPartPaletteDialog::~lcPartPaletteDialog()
|
||||||
{
|
{
|
||||||
|
for (lcPartPalette* Palette : mImportedPalettes)
|
||||||
|
delete Palette;
|
||||||
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +117,42 @@ void lcPartPaletteDialog::on_RenameButton_clicked()
|
||||||
SelectedItems[0]->setText(Name);
|
SelectedItems[0]->setText(Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcPartPaletteDialog::on_ImportButton_clicked()
|
||||||
|
{
|
||||||
|
lcSetsDatabaseDialog Dialog(this);
|
||||||
|
|
||||||
|
if (Dialog.exec() != QDialog::Accepted)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lcPartPalette* Palette = new lcPartPalette;
|
||||||
|
Palette->Name = Dialog.GetSetDescription();
|
||||||
|
mImportedPalettes.push_back(Palette);
|
||||||
|
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||||
|
QByteArray Inventory = Dialog.GetSetInventory();
|
||||||
|
QJsonDocument Document = QJsonDocument::fromJson(Inventory);
|
||||||
|
QJsonObject Root = Document.object();
|
||||||
|
QJsonArray Parts = Root["results"].toArray();
|
||||||
|
|
||||||
|
for (const QJsonValue& Part : Parts)
|
||||||
|
{
|
||||||
|
QJsonObject PartObject = Part.toObject();
|
||||||
|
QByteArray PartID = PartObject["part"].toObject()["part_num"].toString().toLatin1();
|
||||||
|
QJsonArray PartIDArray = PartObject["part"].toObject()["external_ids"].toObject()["LDraw"].toArray();
|
||||||
|
if (!PartIDArray.isEmpty())
|
||||||
|
PartID = PartIDArray.first().toString().toLatin1();
|
||||||
|
|
||||||
|
Palette->Parts.push_back(PartID.toUpper().toStdString() + ".DAT");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QListWidgetItem* Item = new QListWidgetItem(Palette->Name);
|
||||||
|
Item->setData(Qt::UserRole, qVariantFromValue<uintptr_t>(reinterpret_cast<uintptr_t>(Palette)));
|
||||||
|
ui->PaletteList->addItem(Item);
|
||||||
|
ui->PaletteList->setCurrentRow(ui->PaletteList->count() - 1);
|
||||||
|
UpdateButtons();
|
||||||
|
}
|
||||||
|
|
||||||
void lcPartPaletteDialog::on_MoveUpButton_clicked()
|
void lcPartPaletteDialog::on_MoveUpButton_clicked()
|
||||||
{
|
{
|
||||||
QList<QListWidgetItem*> SelectedItems = ui->PaletteList->selectedItems();
|
QList<QListWidgetItem*> SelectedItems = ui->PaletteList->selectedItems();
|
||||||
|
|
|
@ -19,6 +19,7 @@ protected slots:
|
||||||
void on_NewButton_clicked();
|
void on_NewButton_clicked();
|
||||||
void on_DeleteButton_clicked();
|
void on_DeleteButton_clicked();
|
||||||
void on_RenameButton_clicked();
|
void on_RenameButton_clicked();
|
||||||
|
void on_ImportButton_clicked();
|
||||||
void on_MoveUpButton_clicked();
|
void on_MoveUpButton_clicked();
|
||||||
void on_MoveDownButton_clicked();
|
void on_MoveDownButton_clicked();
|
||||||
void on_PaletteList_currentRowChanged(int CurrentRow);
|
void on_PaletteList_currentRowChanged(int CurrentRow);
|
||||||
|
@ -28,4 +29,5 @@ private:
|
||||||
|
|
||||||
Ui::lcPartPaletteDialog* ui;
|
Ui::lcPartPaletteDialog* ui;
|
||||||
std::vector<lcPartPalette>& mPartPalettes;
|
std::vector<lcPartPalette>& mPartPalettes;
|
||||||
|
std::vector<lcPartPalette*> mImportedPalettes;
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,6 +42,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="ImportButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Import...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="MoveUpButton">
|
<widget class="QPushButton" name="MoveUpButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -90,6 +97,7 @@
|
||||||
<tabstop>NewButton</tabstop>
|
<tabstop>NewButton</tabstop>
|
||||||
<tabstop>DeleteButton</tabstop>
|
<tabstop>DeleteButton</tabstop>
|
||||||
<tabstop>RenameButton</tabstop>
|
<tabstop>RenameButton</tabstop>
|
||||||
|
<tabstop>ImportButton</tabstop>
|
||||||
<tabstop>MoveUpButton</tabstop>
|
<tabstop>MoveUpButton</tabstop>
|
||||||
<tabstop>MoveDownButton</tabstop>
|
<tabstop>MoveDownButton</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
|
|
Loading…
Add table
Reference in a new issue