Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/actionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ void ActionManager::initialize()
A("edit_mergeitems", QT_TR_NOOP("Consolidate Items..."), QT_TR_NOOP("Ctrl+L", "Edit|Consolidate Items"), NeedSelection(2));
A("edit_partoutitems", QT_TR_NOOP("Part out Item..."), NeedInventory | NeedSelection(1) | NeedQuantity);
A("edit_copy_fields", QT_TR_NOOP("Copy Values from Document..."), NeedDocument | NeedLots);
A("edit_additems_from_documents", QT_TR_NOOP("Add Items from Documents..."), NeedDocument);
A("edit_select_all", QT_TR_NOOP("Select All"), QKeySequence::SelectAll, NeedDocument | NeedLots);
A("edit_select_none", QT_TR_NOOP("Select None"), QT_TR_NOOP("Ctrl+Shift+A", "Edit|Select None"), NeedDocument | NeedLots);
// ^^ QKeySequence::Deselect is only mapped on Linux
Expand Down
2 changes: 1 addition & 1 deletion src/common/documentmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ void DocumentModel::setCurrencyCode(const QString &ccode, double crate)
m_undo->push(new CurrencyCmd(this, ccode, crate));
}

void DocumentModel::adjustLotCurrencyToModel(BrickLink::LotList &lots, const QString &fromCurrency)
void DocumentModel::adjustLotCurrencyToModel(BrickLink::LotList &lots, const QString &fromCurrency) const
{
if (currencyCode() != fromCurrency) {
double r = Currency::inst()->crossRate(fromCurrency, currencyCode());
Expand Down
2 changes: 1 addition & 1 deletion src/common/documentmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public slots:
QString currencyCode() const;
void setCurrencyCode(const QString &code, double crate = 1.);

void adjustLotCurrencyToModel(LotList &lots, const QString &fromCurrency);
void adjustLotCurrencyToModel(LotList &lots, const QString &fromCurrency) const;

Filter::Parser *filterParser();

Expand Down
2 changes: 2 additions & 0 deletions src/desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ void MainWindow::setupMenuBar()
"edit_reserved",
"edit_marker",
"-",
"edit_additems_from_documents",
"-",
"edit_copy_fields",
"-",
"bricklink_catalog",
Expand Down
119 changes: 72 additions & 47 deletions src/desktop/selectdocumentdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
#include "selectdocumentdialog.h"


SelectDocument::SelectDocument(const DocumentModel *self, QWidget *parent)
SelectDocument::SelectDocument(const DocumentModel *self, bool multipleDocuments, QWidget *parent)
: QWidget(parent)
{
m_clipboard = new QRadioButton(tr("Items from Clipboard"));
m_document = new QRadioButton(tr("Items from an already open document:"));
m_document = new QRadioButton(tr(multipleDocuments ? "Items from already open documents:" : "Items from an already open document:"));
m_documentList = new QListWidget();
m_documentList->setTextElideMode(Qt::ElideMiddle);
if (multipleDocuments) {
m_documentList->setSelectionMode(QListWidget::MultiSelection);
}

auto layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -83,27 +86,41 @@ SelectDocument::SelectDocument(const DocumentModel *self, QWidget *parent)
setFocusProxy(hasClip ? m_clipboard : m_document);
}

LotList SelectDocument::lots() const
LotList SelectDocument::lots(const DocumentModel *model) const
{
LotList srcList;

if (!isDocumentSelected())
return srcList;
return LotList();

if (m_clipboard->isChecked()) {
srcList = m_lotsFromClipboard;
LotList list;
list.reserve(m_lotsFromClipboard.size());
for (const Lot *lot : std::as_const(m_lotsFromClipboard)) {
list << new Lot(*lot);
}
if (model) {
model->adjustLotCurrencyToModel(list, m_currencyCodeFromClipboard);
}
return list;
} else {
const auto *model = m_documentList->selectedItems().constFirst()
->data(Qt::UserRole).value<DocumentModel *>();
if (model)
srcList = model->lots();
LotList list;

for (auto &&item: m_documentList->selectedItems()) {
const auto *from_model = item->data(Qt::UserRole).value<DocumentModel *>();
if (from_model) {
LotList model_list;
auto lots = from_model->lots();
model_list.reserve( lots.size());
for (const Lot *lot : lots) {
model_list << new Lot(*lot);
}
if (model) {
model->adjustLotCurrencyToModel(model_list, from_model->currencyCode());
}
list.append(model_list);
}
}
return list;
}

LotList list;
list.reserve(srcList.size());
for (const Lot *lot : std::as_const(srcList))
list << new Lot(*lot);
return list;
}

QString SelectDocument::currencyCode() const
Expand Down Expand Up @@ -142,7 +159,7 @@ SelectDocumentDialog::SelectDocumentDialog(const DocumentModel *self, const QStr
QWidget *parent)
: QDialog(parent)
{
m_sd = new SelectDocument(self);
m_sd = new SelectDocument(self, false);

auto label = new QLabel(headertext);
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
Expand Down Expand Up @@ -171,7 +188,7 @@ SelectDocumentDialog::~SelectDocumentDialog()

LotList SelectDocumentDialog::lots() const
{
return m_sd->lots();
return m_sd->lots(nullptr);
}

QString SelectDocumentDialog::currencyCode() const
Expand Down Expand Up @@ -212,15 +229,15 @@ bool WizardPage::isComplete() const


SelectCopyMergeDialog::SelectCopyMergeDialog(const DocumentModel *self, const QString &chooseDocText,
const QString &chooseFieldsText, QWidget *parent)
const QString &chooseFieldsText, bool addDocuments, QWidget *parent)
: QWizard(parent)
{
setOptions(QWizard::IndependentPages);
setWizardStyle(QWizard::ModernStyle);
QString title = tr("Copy or merge values");
QString title = tr(addDocuments ? "Add items" : "Copy or merge values");

m_sd = new SelectDocument(self);
m_mm = new SelectMergeMode(DocumentModel::MergeMode::Merge);
m_sd = new SelectDocument(self, addDocuments);
m_mm = nullptr;

auto *dpage = new WizardPage();
dpage->setTitle(title);
Expand All @@ -230,14 +247,20 @@ SelectCopyMergeDialog::SelectCopyMergeDialog(const DocumentModel *self, const QS
dpage->setFocusProxy(m_sd);
addPage(dpage);

auto *mpage = new WizardPage();
mpage->setTitle(title);
mpage->setSubTitle(chooseFieldsText);
mpage->setFinalPage(true);
mpage->setComplete(true);
auto *mlayout = new QVBoxLayout(mpage);
mlayout->addWidget(m_mm);
addPage(mpage);
WizardPage *mpage = nullptr;

if (!addDocuments) {
m_mm = new SelectMergeMode(DocumentModel::MergeMode::Merge);

mpage = new WizardPage();
mpage->setTitle(title);
mpage->setSubTitle(chooseFieldsText);
mpage->setFinalPage(true);
mpage->setComplete(true);
auto *mlayout = new QVBoxLayout(mpage);
mlayout->addWidget(m_mm);
addPage(mpage);
}

connect(m_sd, &SelectDocument::documentSelected,
dpage, &WizardPage::setComplete);
Expand All @@ -247,31 +270,33 @@ SelectCopyMergeDialog::SelectCopyMergeDialog(const DocumentModel *self, const QS
restoreGeometry(ba);

dpage->adjustSize();
mpage->adjustSize();
QSize s = mpage->size().expandedTo(dpage->size());
dpage->setFixedSize(s);
mpage->setFixedSize(s);

ba = Config::inst()->value(u"MainWindow/SelectCopyMergeDialog/MergeMode"_qs)
.toByteArray();
m_mm->restoreState(ba);

if (mpage) {
mpage->adjustSize();
QSize s = mpage->size().expandedTo(dpage->size());
dpage->setFixedSize(s);
mpage->setFixedSize(s);
}

if (m_mm) {
ba = Config::inst()->value(u"MainWindow/SelectCopyMergeDialog/MergeMode"_qs)
.toByteArray();
m_mm->restoreState(ba);
}
}

SelectCopyMergeDialog::~SelectCopyMergeDialog()
{
Config::inst()->setValue(u"MainWindow/SelectCopyMergeDialog/Geometry"_qs, saveGeometry());
Config::inst()->setValue(u"MainWindow/SelectCopyMergeDialog/MergeMode"_qs, m_mm->saveState());
if (m_mm) {
Config::inst()->setValue(u"MainWindow/SelectCopyMergeDialog/MergeMode"_qs, m_mm->saveState());
}
}


LotList SelectCopyMergeDialog::lots() const
LotList SelectCopyMergeDialog::lots(const DocumentModel &model) const
{
return m_sd->lots();
}

QString SelectCopyMergeDialog::currencyCode() const
{
return m_sd->currencyCode();
return m_sd->lots(&model);
}

QHash<DocumentModel::Field, DocumentModel::MergeMode> SelectCopyMergeDialog::fieldMergeModes() const
Expand Down
9 changes: 4 additions & 5 deletions src/desktop/selectdocumentdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class SelectDocument : public QWidget
{
Q_OBJECT
public:
SelectDocument(const DocumentModel *self, QWidget *parent = nullptr);
SelectDocument(const DocumentModel *self, bool multipleDocuments, QWidget *parent = nullptr);
~SelectDocument() override;

bool isDocumentSelected() const;
BrickLink::LotList lots() const;
BrickLink::LotList lots(const DocumentModel *model) const;
QString currencyCode() const;

signals:
Expand Down Expand Up @@ -62,11 +62,10 @@ class SelectCopyMergeDialog : public QWizard
Q_OBJECT
public:
SelectCopyMergeDialog(const DocumentModel *self, const QString &chooseDocText,
const QString &chooseFieldsText, QWidget *parent = nullptr);
const QString &chooseFieldsText, bool addDocuments, QWidget *parent = nullptr);
~SelectCopyMergeDialog() override;

LotList lots() const;
QString currencyCode() const;
LotList lots(const DocumentModel &model) const;
QHash<DocumentModel::Field, DocumentModel::MergeMode> fieldMergeModes() const;

protected:
Expand Down
20 changes: 14 additions & 6 deletions src/desktop/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,27 @@ View::View(Document *document, QWidget *parent)

m_actionTable = {
{ "edit_partoutitems", [this](bool) { partOutItems(); } },
{ "edit_additems_from_documents", [this](bool) -> QCoro::Task<> {
SelectCopyMergeDialog dlg(model(),
tr("Select the documents whose items will be appended to the current document"),
QString(), true, this);
dlg.setWindowModality(Qt::ApplicationModal);
dlg.show();

if (co_await qCoro(&dlg, &QDialog::finished) == QDialog::Accepted) {
m_model->addLots(dlg.lots(*m_model), DocumentModel::AddLotMode::AddAsNew);
}
} },
{ "edit_copy_fields", [this](bool) -> QCoro::Task<> {
SelectCopyMergeDialog dlg(model(),
tr("Select the document that should serve as a source to fill in the corresponding fields in the current document"),
tr("Choose how fields are getting copied or merged."), this);
tr("Choose how fields are getting copied or merged."), false, this);
dlg.setWindowModality(Qt::ApplicationModal);
dlg.show();

if (co_await qCoro(&dlg, &QDialog::finished) == QDialog::Accepted) {
LotList lots = dlg.lots();
if (!lots.empty()) {
m_model->adjustLotCurrencyToModel(lots, dlg.currencyCode());
m_document->copyFields(lots, dlg.fieldMergeModes());
}
LotList lots = dlg.lots(*m_model);
m_document->copyFields(lots, dlg.fieldMergeModes());
qDeleteAll(lots);
}
} },
Expand Down