mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Allow multiple selection in the Model List Dialog. Fixes #419.
This commit is contained in:
parent
636f84ad6c
commit
7425c41673
3 changed files with 125 additions and 54 deletions
|
@ -33,12 +33,30 @@ int lcQModelListDialog::GetActiveModelIndex() const
|
|||
|
||||
void lcQModelListDialog::UpdateButtons()
|
||||
{
|
||||
int CurrentModel = ui->ModelList->currentRow();
|
||||
int NumModels = ui->ModelList->count();
|
||||
int ModelCount = ui->ModelList->count();
|
||||
|
||||
ui->DeleteModel->setEnabled(NumModels > 1);
|
||||
ui->MoveUp->setEnabled(NumModels > 1 && CurrentModel > 0);
|
||||
ui->MoveDown->setEnabled(NumModels > 1 && CurrentModel < NumModels - 1);
|
||||
ui->DeleteModel->setEnabled(ModelCount > 1);
|
||||
ui->SetActiveModel->setEnabled(ui->ModelList->currentItem() != nullptr);
|
||||
|
||||
bool MoveUp = false;
|
||||
bool MoveDown = false;
|
||||
|
||||
for (int Row = 0; Row < ui->ModelList->count(); Row++)
|
||||
{
|
||||
QListWidgetItem* Item = ui->ModelList->item(Row);
|
||||
|
||||
if (!Item->isSelected())
|
||||
continue;
|
||||
|
||||
if (Row > 0 && !ui->ModelList->item(Row - 1)->isSelected())
|
||||
MoveUp = true;
|
||||
|
||||
if (Row < ModelCount - 1 && !ui->ModelList->item(Row + 1)->isSelected())
|
||||
MoveDown = true;
|
||||
}
|
||||
|
||||
ui->MoveUp->setEnabled(MoveUp);
|
||||
ui->MoveDown->setEnabled(MoveDown);
|
||||
}
|
||||
|
||||
void lcQModelListDialog::accept()
|
||||
|
@ -76,25 +94,35 @@ void lcQModelListDialog::on_DeleteModel_clicked()
|
|||
{
|
||||
if (ui->ModelList->count() == 1)
|
||||
{
|
||||
QMessageBox::information(this, tr("Error"), tr("The model cannot be empty."));
|
||||
QMessageBox::information(this, tr("Delete Submodel"), tr("The model cannot be empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QListWidgetItem*> SelectedItems = ui->ModelList->selectedItems();
|
||||
|
||||
if (SelectedItems.isEmpty())
|
||||
{
|
||||
QMessageBox::information(this, tr("Delete Submodel"), tr("No submodel selected."));
|
||||
return;
|
||||
}
|
||||
|
||||
QString Prompt;
|
||||
if (SelectedItems.size() == 1)
|
||||
Prompt = tr("Are you sure you want to delete the submodel '%1'?").arg(SelectedItems[0]->text());
|
||||
else
|
||||
Prompt = tr("Are you sure you want to delete %1 submodels?").arg(QString::number(SelectedItems.size()));
|
||||
|
||||
QString Prompt = tr("Are you sure you want to delete the submodel '%1'?").arg(SelectedItems[0]->text());
|
||||
if (QMessageBox::question(this, tr("Delete Submodel"), Prompt, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
QListWidgetItem* SelectedItem = SelectedItems.first();
|
||||
for (QListWidgetItem* SelectedItem : SelectedItems)
|
||||
{
|
||||
if (mActiveModelItem == SelectedItem)
|
||||
mActiveModelItem = nullptr;
|
||||
|
||||
if (mActiveModelItem == SelectedItem)
|
||||
mActiveModelItem = nullptr;
|
||||
delete SelectedItem;
|
||||
}
|
||||
|
||||
delete SelectedItem;
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
|
@ -103,78 +131,119 @@ void lcQModelListDialog::on_RenameModel_clicked()
|
|||
QList<QListWidgetItem*> SelectedItems = ui->ModelList->selectedItems();
|
||||
|
||||
if (SelectedItems.isEmpty())
|
||||
{
|
||||
QMessageBox::information(this, tr("Rename Submodel"), tr("No submodel selected."));
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList ModelNames;
|
||||
for (QListWidgetItem* CurrentItem : SelectedItems)
|
||||
{
|
||||
QStringList ModelNames;
|
||||
|
||||
for (int ItemIdx = 0; ItemIdx < ui->ModelList->count(); ItemIdx++)
|
||||
ModelNames.append(ui->ModelList->item(ItemIdx)->text());
|
||||
for (int ItemIdx = 0; ItemIdx < ui->ModelList->count(); ItemIdx++)
|
||||
ModelNames.append(ui->ModelList->item(ItemIdx)->text());
|
||||
|
||||
QString Name = lcGetActiveProject()->GetNewModelName(this, tr("Rename Submodel"), SelectedItems[0]->text(), ModelNames);
|
||||
QString Name = lcGetActiveProject()->GetNewModelName(this, tr("Rename Submodel"), CurrentItem->text(), ModelNames);
|
||||
|
||||
if (!Name.isEmpty())
|
||||
SelectedItems[0]->setText(Name);
|
||||
if (!Name.isEmpty())
|
||||
CurrentItem->setText(Name);
|
||||
}
|
||||
}
|
||||
|
||||
void lcQModelListDialog::on_ExportModel_clicked()
|
||||
{
|
||||
QListWidgetItem* CurrentItem = ui->ModelList->currentItem();
|
||||
QList<QListWidgetItem*> SelectedItems = ui->ModelList->selectedItems();
|
||||
|
||||
if (!CurrentItem)
|
||||
return;
|
||||
|
||||
lcModel* Model = (lcModel*)CurrentItem->data(Qt::UserRole).value<uintptr_t>();
|
||||
|
||||
if (!Model)
|
||||
if (SelectedItems.isEmpty())
|
||||
{
|
||||
QMessageBox::information(this, tr("LeoCAD"), tr("Nothing to export."));
|
||||
QMessageBox::information(this, tr("Export Submodel"), tr("No submodel selected."));
|
||||
return;
|
||||
}
|
||||
|
||||
QString SaveFileName = QFileInfo(QDir(lcGetProfileString(LC_PROFILE_PROJECTS_PATH)), CurrentItem->text()).absoluteFilePath();
|
||||
if (SelectedItems.size() == 1)
|
||||
{
|
||||
QListWidgetItem* CurrentItem = SelectedItems[0];
|
||||
lcModel* Model = (lcModel*)CurrentItem->data(Qt::UserRole).value<uintptr_t>();
|
||||
|
||||
SaveFileName = QFileDialog::getSaveFileName(this, tr("Save Model"), SaveFileName, tr("Supported Files (*.ldr *.dat);;All Files (*.*)"));
|
||||
if (!Model)
|
||||
{
|
||||
QMessageBox::information(this, tr("LeoCAD"), tr("Nothing to export."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (SaveFileName.isEmpty())
|
||||
return;
|
||||
QString SaveFileName = QFileInfo(QDir(lcGetProfileString(LC_PROFILE_PROJECTS_PATH)), CurrentItem->text()).absoluteFilePath();
|
||||
|
||||
lcGetActiveProject()->ExportModel(SaveFileName, Model);
|
||||
SaveFileName = QFileDialog::getSaveFileName(this, tr("Save Model"), SaveFileName, tr("Supported Files (*.ldr *.dat);;All Files (*.*)"));
|
||||
|
||||
lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(SaveFileName).absolutePath());
|
||||
if (SaveFileName.isEmpty())
|
||||
return;
|
||||
|
||||
lcGetActiveProject()->ExportModel(SaveFileName, Model);
|
||||
|
||||
lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(SaveFileName).absolutePath());
|
||||
}
|
||||
else
|
||||
{
|
||||
QString Folder = QFileDialog::getExistingDirectory(this, tr("Select Parts Library Folder"), lcGetProfileString(LC_PROFILE_PROJECTS_PATH));
|
||||
|
||||
for (QListWidgetItem* CurrentItem : SelectedItems)
|
||||
{
|
||||
lcModel* Model = (lcModel*)CurrentItem->data(Qt::UserRole).value<uintptr_t>();
|
||||
|
||||
if (Model)
|
||||
{
|
||||
QString SaveFileName = QFileInfo(QDir(Folder), CurrentItem->text()).absoluteFilePath();
|
||||
lcGetActiveProject()->ExportModel(SaveFileName, Model);
|
||||
}
|
||||
}
|
||||
|
||||
lcSetProfileString(LC_PROFILE_PROJECTS_PATH, Folder);
|
||||
}
|
||||
}
|
||||
|
||||
void lcQModelListDialog::on_MoveUp_clicked()
|
||||
{
|
||||
QList<QListWidgetItem*> SelectedItems = ui->ModelList->selectedItems();
|
||||
bool Blocked = ui->ModelList->blockSignals(true);
|
||||
|
||||
if (SelectedItems.isEmpty())
|
||||
return;
|
||||
for (int Row = 1; Row < ui->ModelList->count(); Row++)
|
||||
{
|
||||
QListWidgetItem* Item = ui->ModelList->item(Row);
|
||||
|
||||
QListWidgetItem* Item = SelectedItems[0];
|
||||
int Row = ui->ModelList->row(Item);
|
||||
if (!Item->isSelected())
|
||||
continue;
|
||||
|
||||
if (Row == 0)
|
||||
return;
|
||||
if (ui->ModelList->item(Row - 1)->isSelected())
|
||||
continue;
|
||||
|
||||
ui->ModelList->takeItem(Row);
|
||||
ui->ModelList->insertItem(Row - 1, Item);
|
||||
ui->ModelList->setCurrentItem(Item);
|
||||
ui->ModelList->takeItem(Row);
|
||||
ui->ModelList->insertItem(Row - 1, Item);
|
||||
Item->setSelected(true);
|
||||
}
|
||||
|
||||
ui->ModelList->blockSignals(Blocked);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
void lcQModelListDialog::on_MoveDown_clicked()
|
||||
{
|
||||
QList<QListWidgetItem*> SelectedItems = ui->ModelList->selectedItems();
|
||||
bool Blocked = ui->ModelList->blockSignals(true);
|
||||
|
||||
if (SelectedItems.isEmpty())
|
||||
return;
|
||||
for (int Row = ui->ModelList->count() - 2; Row >= 0; Row--)
|
||||
{
|
||||
QListWidgetItem* Item = ui->ModelList->item(Row);
|
||||
|
||||
QListWidgetItem* Item = SelectedItems[0];
|
||||
int Row = ui->ModelList->row(Item);
|
||||
if (!Item->isSelected())
|
||||
continue;
|
||||
|
||||
ui->ModelList->takeItem(Row);
|
||||
ui->ModelList->insertItem(Row + 1, Item);
|
||||
ui->ModelList->setCurrentItem(Item);
|
||||
if (ui->ModelList->item(Row + 1)->isSelected())
|
||||
continue;
|
||||
|
||||
ui->ModelList->takeItem(Row);
|
||||
ui->ModelList->insertItem(Row + 1, Item);
|
||||
Item->setSelected(true);
|
||||
}
|
||||
|
||||
ui->ModelList->blockSignals(Blocked);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
|
@ -190,9 +259,7 @@ void lcQModelListDialog::on_ModelList_itemDoubleClicked(QListWidgetItem* Item)
|
|||
accept();
|
||||
}
|
||||
|
||||
void lcQModelListDialog::on_ModelList_currentRowChanged(int CurrentRow)
|
||||
void lcQModelListDialog::on_ModelList_itemSelectionChanged()
|
||||
{
|
||||
Q_UNUSED(CurrentRow);
|
||||
|
||||
UpdateButtons();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public slots:
|
|||
void on_MoveDown_clicked();
|
||||
void on_SetActiveModel_clicked();
|
||||
void on_ModelList_itemDoubleClicked(QListWidgetItem* Item);
|
||||
void on_ModelList_currentRowChanged(int CurrentRow);
|
||||
void on_ModelList_itemSelectionChanged();
|
||||
|
||||
private:
|
||||
QListWidgetItem* mActiveModelItem;
|
||||
|
|
|
@ -17,7 +17,11 @@
|
|||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="ModelList"/>
|
||||
<widget class="QListWidget" name="ModelList">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
|
|
Loading…
Reference in a new issue