From 5547c973624c44f65939ac5480861f9d26754b98 Mon Sep 17 00:00:00 2001 From: Ake Hedman Date: Fri, 13 Oct 2023 18:26:14 +0200 Subject: [PATCH] Added manufacturer contact editin --- .vscode/settings.json | 10 +- CMakeLists.txt | 7 + src/cdlgmdfcontact.cpp | 298 ++++++++++---- src/cdlgmdfcontact.h | 77 ++-- src/cdlgmdfcontact.ui | 267 ++++++++++++- src/cdlgmdfcontactlist.cpp | 345 ++++++++++++++++ src/cdlgmdfcontactlist.h | 119 ++++++ src/cdlgmdfcontactlist.ui | 188 +++++++++ src/cdlgmdfmanufacturer.cpp | 25 -- src/cdlgmdfmodule.cpp | 22 +- src/cfrmmdf.cpp | 778 ++++++++++++++++++++++++++++-------- src/cfrmmdf.h | 61 +++ src/cfrmnodeconfig.cpp | 10 +- 13 files changed, 1872 insertions(+), 335 deletions(-) create mode 100644 src/cdlgmdfcontactlist.cpp create mode 100644 src/cdlgmdfcontactlist.h create mode 100644 src/cdlgmdfcontactlist.ui diff --git a/.vscode/settings.json b/.vscode/settings.json index 05104942..731281dc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -73,7 +73,8 @@ "climits": "cpp", "regex": "cpp", "any": "cpp", - "numbers": "cpp" + "numbers": "cpp", + "span": "cpp" }, "python.pythonPath": "/usr/bin/python3", "files.exclude": { @@ -86,9 +87,10 @@ "**/.firebase": true }, "files.watcherExclude": { - "**/.git/objects/**": true, - "**/.git/subtree-cache/**": true, - "**/node_modules/**": true + "**/.git/objects/**": true, + "**/.git/subtree-cache/**": true, + "**/node_modules/*/**": true, + "**/.hg/store/**": true }, "cmake.configureArgs": [ "-DVCPKG_HOST_TRIPLET=x64-windows-static", diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fe005f0..11b76869 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -258,6 +258,7 @@ qt5_wrap_ui(UI src/mainwindow.ui src/cdlgeditmap.ui src/cdlgmdfmanufacturer.ui src/cdlgmdfcontact.ui + src/cdlgmdfcontactlist.ui ) add_executable(${PROJECT_NAME} @@ -513,6 +514,12 @@ add_executable(${PROJECT_NAME} src/cdlgmdfcontact.cpp src/cdlgmdfcontact.h + build/ui_cdlgmdfcontactlist.h + src/cdlgmdfcontactlist.ui + src/cdlgmdfcontactlist.cpp + src/cdlgmdfcontactlist.h + + ${VSCP_PATH}/src/vscp/common/version.h ${VSCP_PATH}/src/vscp/common/vscp.h ${VSCP_PATH}/src/vscp/common/vscpremotetcpif.h diff --git a/src/cdlgmdfcontact.cpp b/src/cdlgmdfcontact.cpp index 7376cd16..9713fd4f 100644 --- a/src/cdlgmdfcontact.cpp +++ b/src/cdlgmdfcontact.cpp @@ -38,6 +38,9 @@ #include "cdlgmdfcontact.h" #include "ui_cdlgmdfcontact.h" +#include "cdlgmdfdescription.h" +#include "cdlgmdfinfourl.h" + #include #include #include @@ -59,8 +62,15 @@ CDlgMdfContact::CDlgMdfContact(QWidget* parent) vscpworks* pworks = (vscpworks*)QCoreApplication::instance(); - // QShortcut* shortcut = new QShortcut(QKeySequence(tr("Ctrl+E", "Edit")), ui->editDate); - // connect(shortcut, &QShortcut::activated, this, &CDlgMdfContact::editDesc); + connect(ui->btnAddDesc, &QToolButton::clicked, this, &CDlgMdfContact::addDesc); + connect(ui->btnEditDesc, &QToolButton::clicked, this, &CDlgMdfContact::editDesc); + connect(ui->btnDupDesc, &QToolButton::clicked, this, &CDlgMdfContact::dupDesc); + connect(ui->btnDelDesc, &QToolButton::clicked, this, &CDlgMdfContact::deleteDesc); + + connect(ui->btnAddInfo, &QToolButton::clicked, this, &CDlgMdfContact::addInfo); + connect(ui->btnEditInfo, &QToolButton::clicked, this, &CDlgMdfContact::editInfo); + connect(ui->btnDupInfo, &QToolButton::clicked, this, &CDlgMdfContact::dupInfo); + connect(ui->btnDelInfo, &QToolButton::clicked, this, &CDlgMdfContact::deleteInfo); setInitialFocus(); } @@ -79,84 +89,68 @@ CDlgMdfContact::~CDlgMdfContact() // void -CDlgMdfContact::initDialogData(const CMDF_Object* pmdfobj) +CDlgMdfContact::initDialogData(const CMDF_Object* pitemobj, mdf_dlg_contact_type type, QString title) { QString str; - if (nullptr == pmdfobj) { - spdlog::error("MDF module information - Invalid MDF object (initDialogData)"); + if (nullptr == pitemobj) { + spdlog::error("MDF contact information - Invalid MDF object (initDialogData)"); return; } - m_pmdf = (CMDF*)pmdfobj; + setWindowTitle(title); - // ui->editName->setText(m_pmdf->getModuleName().c_str()); - // ui->editModel->setText(m_pmdf->getModuleModel().c_str()); - // ui->comboModuleLevel->setCurrentIndex(m_pmdf->getModuleLevel()); - // ui->editVersion->setText(m_pmdf->getModuleVersion().c_str()); - // str = m_pmdf->getModuleChangeDate().c_str(); - // ui->editDate->setDate(QDate::fromString(str, Qt::ISODate)); - // ui->editBufferSize->setValue(m_pmdf->getModuleBufferSize()); - // ui->editCopyright->setText(m_pmdf->getModuleCopyright().c_str()); + m_pitemobj = (CMDF_Item*)pitemobj; - // switch (index) { - // case index_module_model: - // ui->editModel->setFocus(); - // break; + int idx = static_cast(type); + ui->comboType->setCurrentIndex(idx); + ui->comboType->setEnabled(false); - // case index_module_version: - // ui->editVersion->setFocus(); - // break; + ui->editValue->setText(m_pitemobj->getName().c_str()); - // case index_module_level: - // ui->comboModuleLevel->setFocus(); - // break; - - // case index_module_change_date: - // ui->editDate->setFocus(); - // break; + // Fill in descriptions + fillDescription(); - // case index_module_buffer_size: - // ui->editBufferSize->setFocus(); - // break; + // Fill in help URL's + fillInfoUrl(); +} - // case index_module_copyright: - // ui->editCopyright->setFocus(); - // break; +/////////////////////////////////////////////////////////////////////////////// +// fillDescription +// - // case index_module_name: - // default: - // ui->editName->setFocus(); - // break; - // } +void +CDlgMdfContact::fillDescription(void) +{ + std::map* pmapDescription = m_pitemobj->getDescriptionMap(); + std::map::iterator itDesc = pmapDescription->begin(); + while (itDesc != pmapDescription->end()) { + std::string lang = itDesc->first; // key + std::string description = itDesc->second; + QString str = lang.c_str() + tr(" - ") + description.c_str(); + ui->listDescription->addItem(str); + itDesc++; + } +} - // Fill in descriptions - //fillDescription(); - - // std::map* pmapDescription = m_pmdf->getModuleDescriptionMap(); - // std::map::iterator itDesc = pmapDescription->begin(); - // while (itDesc != pmapDescription->end()) { - // std::string lang = itDesc->first; // key - // std::string description = itDesc->second; - // str = lang.c_str() + tr(" - ") + description.c_str(); - // ui->listDescription->addItem(str); - // itDesc++; - // } +/////////////////////////////////////////////////////////////////////////////// +// fillInfoUrl +// - // Fill in help URL's - //fillInfoUrl(); - // std::map* pmapHelpUrl = m_pmdf->getModuleHelpUrlMap(); - // std::map::iterator itInfo = pmapHelpUrl->begin(); - // while (itInfo != pmapHelpUrl->end()) { - // std::string lang = itInfo->first; // key - // std::string info = itInfo->second; - // str = lang.c_str() + tr(" - ") + info.c_str(); - // ui->listInfo->addItem(str); - // itInfo++; - // } +void +CDlgMdfContact::fillInfoUrl(void) +{ + std::map* pmapHelpUrl = m_pitemobj->getInfoUrlMap(); + std::map::iterator itInfo = pmapHelpUrl->begin(); + while (itInfo != pmapHelpUrl->end()) { + std::string lang = itInfo->first; // key + std::string info = itInfo->second; + QString str = lang.c_str() + tr(" - ") + info.c_str(); + ui->listInfo->addItem(str); + itInfo++; + } } - /////////////////////////////////////////////////////////////////////////////// // setInitialFocus // @@ -167,7 +161,6 @@ CDlgMdfContact::setInitialFocus(void) // ui->editGuid->setFocus(); } - // ---------------------------------------------------------------------------- // Getters & Setters // ---------------------------------------------------------------------------- @@ -177,7 +170,7 @@ CDlgMdfContact::setInitialFocus(void) // QString -CDlgMdfContact::getName(void) +CDlgMdfContact::getValue(void) { return (ui->editValue->text()); } @@ -187,11 +180,182 @@ CDlgMdfContact::getName(void) // void -CDlgMdfContact::setName(const QString& str) +CDlgMdfContact::setValue(const QString& str) { ui->editValue->setText(str); } +/////////////////////////////////////////////////////////////////////////////// +// addDesc +// + +void +CDlgMdfContact::addDesc(void) +{ + QString selstr = "en"; // Default language + + CDlgMdfDescription dlg(this); + dlg.initDialogData(m_pitemobj->getDescriptionMap() /*, &selstr*/); + if (QDialog::Accepted == dlg.exec()) { + ui->listDescription->clear(); + fillDescription(); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// editDesc +// + +void +CDlgMdfContact::editDesc(void) +{ + if (-1 != ui->listDescription->currentRow()) { + + // Save the row + int idx = ui->listDescription->currentRow(); + + QListWidgetItem* pitem = ui->listDescription->currentItem(); + QString selstr = pitem->text().split('_').first().left(2); + + CDlgMdfDescription dlg(this); + dlg.initDialogData(m_pitemobj->getDescriptionMap(), &selstr); + if (QDialog::Accepted == dlg.exec()) { + ui->listDescription->clear(); + fillDescription(); + ui->listDescription->setCurrentRow(idx); + } + } + else { + QMessageBox::warning(this, tr("vscpworks+"), tr("An item must be selected"), QMessageBox::Ok); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// dupDesc +// + +void +CDlgMdfContact::dupDesc(void) +{ + if (-1 != ui->listDescription->currentRow()) { + CDlgMdfDescription dlg(this); + dlg.initDialogData(m_pitemobj->getDescriptionMap()); + if (QDialog::Accepted == dlg.exec()) { + ui->listDescription->clear(); + fillDescription(); + } + } + else { + QMessageBox::warning(this, tr("vscpworks+"), tr("An item must be selected"), QMessageBox::Ok); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// deleteDesc +// + +void +CDlgMdfContact::deleteDesc(void) +{ + if (-1 != ui->listDescription->currentRow()) { + + // Save the row + int idx = ui->listDescription->currentRow(); + + QListWidgetItem* pitem = ui->listDescription->currentItem(); + QString selstr = pitem->text().split('_').first().left(2); + + m_pitemobj->getDescriptionMap()->erase(selstr.toStdString()); + ui->listDescription->clear(); + fillDescription(); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// addInfo +// + +void +CDlgMdfContact::addInfo(void) +{ + QString selstr = "en"; // Default language + + CDlgMdfInfoUrl dlg(this); + dlg.initDialogData(m_pitemobj->getInfoUrlMap() /*, &selstr*/); + if (QDialog::Accepted == dlg.exec()) { + ui->listInfo->clear(); + fillInfoUrl(); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// editInfo +// + +void +CDlgMdfContact::editInfo(void) +{ + if (-1 != ui->listInfo->currentRow()) { + + // Save the row + int idx = ui->listInfo->currentRow(); + + QListWidgetItem* pitem = ui->listInfo->currentItem(); + QString selstr = pitem->text().split('_').first().left(2); + + CDlgMdfInfoUrl dlg(this); + dlg.initDialogData(m_pitemobj->getInfoUrlMap(), &selstr); + if (QDialog::Accepted == dlg.exec()) { + ui->listInfo->clear(); + fillInfoUrl(); + ui->listInfo->setCurrentRow(idx); + } + } + else { + QMessageBox::warning(this, tr("vscpworks+"), tr("An item must be selected"), QMessageBox::Ok); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// dupInfo +// + +void +CDlgMdfContact::dupInfo(void) +{ + if (-1 != ui->listInfo->currentRow()) { + CDlgMdfInfoUrl dlg(this); + dlg.initDialogData(m_pitemobj->getInfoUrlMap()); + if (QDialog::Accepted == dlg.exec()) { + ui->listInfo->clear(); + fillInfoUrl(); + } + } + else { + QMessageBox::warning(this, tr("vscpworks+"), tr("An item must be selected"), QMessageBox::Ok); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// deleteInfo +// + +void +CDlgMdfContact::deleteInfo(void) +{ + if (-1 != ui->listInfo->currentRow()) { + + // Save the row + int idx = ui->listInfo->currentRow(); + + QListWidgetItem* pitem = ui->listInfo->currentItem(); + QString selstr = pitem->text().split('_').first().left(2); + + m_pitemobj->getInfoUrlMap()->erase(selstr.toStdString()); + ui->listInfo->clear(); + fillInfoUrl(); + } +} /////////////////////////////////////////////////////////////////////////////// // accept @@ -201,7 +365,7 @@ void CDlgMdfContact::accept() { std::string str; - if (nullptr != m_pmdf) { + if (nullptr != m_pitemobj) { // str = ui->editName->text().toStdString(); // m_pmdf->setModuleName(str); diff --git a/src/cdlgmdfcontact.h b/src/cdlgmdfcontact.h index 69a60130..0ac82ca6 100644 --- a/src/cdlgmdfcontact.h +++ b/src/cdlgmdfcontact.h @@ -34,6 +34,15 @@ #include +typedef enum mdf_dlg_contact_type { + dlg_type_contact_none, + dlg_type_contact_phone, + dlg_type_contact_fax, + dlg_type_contact_email, + dlg_type_contact_web, + dlg_type_contact_social, +} mdf_dlg_contact_type; + namespace Ui { class CDlgMdfContact; @@ -61,63 +70,51 @@ class CDlgMdfContact : public QDialog { /*! Init dialog data @param pmdfobject Pointer to MDF object - @param index The index for the field that will get focus - */ - void initDialogData(const CMDF_Object* pmdfobj); - - - // ---------------------------------------------------------------------------- - // Getters & Setters - // ---------------------------------------------------------------------------- - - /*! - Name getter/setters - */ - void setName(const QString& name); - QString getName(void); - - /*! - GUID getter/setters - */ - void setModel(const QString& guid); - QString getModel(void); - - /*! - GUID getter/setters + @param type Contact type + @param title Dialog title */ - void setVersion(const QString& guid); - QString getVersion(void); + void initDialogData(const CMDF_Object* pitemobj, + mdf_dlg_contact_type type, + QString title); /*! - GUID getter/setters + Fill in contact descriptions */ - void setChangeDate(const QString& guid); - QString getChangeDate(void); + void fillDescription(void); /*! - GUID getter/setters + Fill in contact info URL's */ - void setBufferSize(int size); - int getBufferSize(void); + void fillInfoUrl(void); - /*! - GUID getter/setters - */ - void setCopyright(const QString& guid); - QString getCopyright(void); + // ---------------------------------------------------------------------------- + // Getters & Setters + // ---------------------------------------------------------------------------- /*! - GUID getter/setters + Name getter/setters */ - void setDescription(const QString& guid); - QString getDescription(void); + void setValue(const QString& name); + QString getValue(void); public slots: void accept(void); + // Description buttons + void addDesc(void); + void editDesc(void); + void dupDesc(void); + void deleteDesc(void); + + // Info URL buttons + void addInfo(void); + void editInfo(void); + void dupInfo(void); + void deleteInfo(void); + private: Ui::CDlgMdfContact* ui; - CMDF* m_pmdf; + CMDF_Item* m_pitemobj; }; #endif // CDLGMDFCONTACT_H diff --git a/src/cdlgmdfcontact.ui b/src/cdlgmdfcontact.ui index ee003b1e..8a0e4302 100644 --- a/src/cdlgmdfcontact.ui +++ b/src/cdlgmdfcontact.ui @@ -6,8 +6,8 @@ 0 0 - 487 - 128 + 660 + 528 @@ -16,9 +16,9 @@ - 10 - 90 - 471 + 0 + 490 + 651 32 @@ -37,8 +37,8 @@ 9 9 - 471 - 71 + 641 + 471 @@ -53,17 +53,17 @@ - Email + Phone - Phone + Fax - Fax + Email @@ -81,16 +81,257 @@ - Type + Value + + + + Description + + + + + + + Info + + + + + + + + + + + + + + + + Add description item + + + ... + + + + :/add.png:/add.png + + + Ctrl+A + + + + + + + Edit description item + + + ... + + + + :/pencil.svg:/pencil.svg + + + Ctrl+E + + + + + + + Duplicate description item + + + ... + + + + :/images/svg/copy.svg:/images/svg/copy.svg + + + Ctrl+D + + + + + + + Delete Description item + + + ... + + + + :/remove.png:/remove.png + + + Ctrl+X + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + + + + + + Add description item + + + ... + + + + :/add.png:/add.png + + + Ctrl+A + + + + + + + Edit description item + + + ... + + + + :/pencil.svg:/pencil.svg + + + Ctrl+E + + + + + + + Duplicate description item + + + ... + + + + :/images/svg/copy.svg:/images/svg/copy.svg + + + Ctrl+D + + + + + + + Delete Description item + + + ... + + + + :/remove.png:/remove.png + + + Ctrl+X + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + - - + + + + + + buttonBox + accepted() + CDlgMdfContact + accept() + + + 325 + 505 + + + 329 + 263 + + + + + buttonBox + rejected() + CDlgMdfContact + reject() + + + 325 + 505 + + + 329 + 263 + + + + diff --git a/src/cdlgmdfcontactlist.cpp b/src/cdlgmdfcontactlist.cpp new file mode 100644 index 00000000..e830a655 --- /dev/null +++ b/src/cdlgmdfcontactlist.cpp @@ -0,0 +1,345 @@ +// cdlgmdfcontactlist.cpp +// +// This file is part of the VSCP (https://www.vscp.org) +// +// The MIT License (MIT) +// +// Copyright © 2000-2023 Ake Hedman, Grodans Paradis AB +// +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +#ifdef WIN32 +#include +#endif + +#include +#include + +#include + +#include "cdlgmdfcontact.h" +#include "cdlgmdfcontactlist.h" +#include "ui_cdlgmdfcontactlist.h" + +// #include "cdlgmdfdescription.h" +// #include "cdlgmdfinfourl.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +// CTor +// + +CDlgMdfContactList::CDlgMdfContactList(QWidget* parent) + : QDialog(parent) + , ui(new Ui::CDlgMdfContactList) +{ + m_pManufacturer = nullptr; + m_pContactList = nullptr; + + ui->setupUi(this); + + vscpworks* pworks = (vscpworks*)QCoreApplication::instance(); + + connect(ui->btnAddContact, &QToolButton::clicked, this, &CDlgMdfContactList::addContact); + connect(ui->btnEditContact, &QToolButton::clicked, this, &CDlgMdfContactList::editContact); + connect(ui->btnDupContact, &QToolButton::clicked, this, &CDlgMdfContactList::dupContact); + connect(ui->btnDelContact, &QToolButton::clicked, this, &CDlgMdfContactList::deleteContact); + + setInitialFocus(); +} + +/////////////////////////////////////////////////////////////////////////////// +// DTor +// + +CDlgMdfContactList::~CDlgMdfContactList() +{ + delete ui; +} + +/////////////////////////////////////////////////////////////////////////////// +// initDialogData +// + +void +CDlgMdfContactList::initDialogData(CMDF_Manufacturer* pManufacturer, + mdf_dlg_contact_type type, + QString title) +{ + QString str; + + if (nullptr == pManufacturer) { + QMessageBox::critical(this, tr("MDF contact information"), tr("Invalid MDF manufacturing object")); + spdlog::error("MDF contact information - Invalid MDF manufacturing object"); + return; + } + + // Save type + m_type = type; + + setWindowTitle(title); + + m_pManufacturer = pManufacturer; + + switch (type) { + + case dlg_type_contact_phone: + m_pContactList = m_pManufacturer->getPhoneContactList(); + break; + + case dlg_type_contact_fax: + m_pContactList = m_pManufacturer->getFaxContactList(); + break; + + case dlg_type_contact_email: + m_pContactList = m_pManufacturer->getEmailContactList(); + break; + + case dlg_type_contact_web: + m_pContactList = m_pManufacturer->getWebContactList(); + break; + + case dlg_type_contact_social: + m_pContactList = m_pManufacturer->getSocialContactList(); + break; + + default: + m_pContactList = nullptr; + break; + } + + // Fill in defined contact items + fillContactItems(); +} + +/////////////////////////////////////////////////////////////////////////////// +// fillContactItems +// + +void +CDlgMdfContactList::fillContactItems(void) +{ + if (nullptr == m_pContactList) { + return; + } + + for (auto it = m_pContactList->cbegin(); it != m_pContactList->cend(); ++it) { + ui->listContact->addItem((*it)->getValue().c_str()); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// setInitialFocus +// + +void +CDlgMdfContactList::setInitialFocus(void) +{ + // ui->editGuid->setFocus(); +} + +// ---------------------------------------------------------------------------- +// Getters & Setters +// ---------------------------------------------------------------------------- + + +/////////////////////////////////////////////////////////////////////////////// +// addContact +// + +void +CDlgMdfContactList::addContact(void) +{ + bool ok; + std::string str = QInputDialog::getText(this, + tr("Add contact item"), + tr("Contact value:"), + QLineEdit::Normal, + "", + &ok) + .toStdString(); + + if (ok && str.length()) { + CMDF_Item* pitem = new CMDF_Item(); + if (nullptr != pitem) { + pitem->setValue(str); + m_pContactList->push_back(pitem); + ui->listContact->clear(); + fillContactItems(); + } + else { + QMessageBox::warning(this, tr(APPNAME), tr("Memory problem could not add item"), QMessageBox::Ok); + } + } +} + +/////////////////////////////////////////////////////////////////////////////// +// editContact +// + +void +CDlgMdfContactList::editContact(void) +{ + bool ok; + + if (-1 != ui->listContact->currentRow()) { + + // Save the selected row + int idx = ui->listContact->currentRow(); + + QListWidgetItem* pitem = ui->listContact->currentItem(); + + std::string str = QInputDialog::getText(this, + tr("Edit contact item"), + tr("Contact value:"), + QLineEdit::Normal, + pitem->text(), + &ok) + .toStdString(); + + if (ok && str.length()) { + pitem->setText(str.c_str()); + CMDF_Item* pitem = m_pContactList->at(idx); + if (nullptr != pitem) { + pitem->setValue(str); + } + else { + QMessageBox::warning(this, tr(APPNAME), tr("Contact item was not found"), QMessageBox::Ok); + } + ui->listContact->clear(); + fillContactItems(); + ui->listContact->setCurrentRow(idx); + } + } + else { + QMessageBox::warning(this, tr(APPNAME), tr("An item must be selected"), QMessageBox::Ok); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// dupContact +// + +void +CDlgMdfContactList::dupContact(void) +{ + bool ok; + + if (-1 != ui->listContact->currentRow()) { + + // Save the selected row + int idx = ui->listContact->currentRow(); + + QListWidgetItem* pitem = ui->listContact->currentItem(); + QString selstr = pitem->text().split('_').first().left(2); + + std::string str = QInputDialog::getText(this, + tr("Edit contact item"), + tr("Contact value:"), + QLineEdit::Normal, + pitem->text(), + &ok) + .toStdString(); + + if (ok && str.length()) { + + CMDF_Item* pitem = new CMDF_Item(); + if (nullptr != pitem) { + pitem->setValue(str); + m_pContactList->push_back(pitem); + ui->listContact->clear(); + fillContactItems(); + } + else { + QMessageBox::warning(this, tr(APPNAME), tr("Memory problem could not add item"), QMessageBox::Ok); + } + } + } + else { + QMessageBox::warning(this, tr("vscpworks+"), tr("An item must be selected"), QMessageBox::Ok); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// deleteContact +// + +void +CDlgMdfContactList::deleteContact(void) +{ + if (-1 != ui->listContact->currentRow()) { + + // Save the row + int idx = ui->listContact->currentRow(); + + QListWidgetItem* pitem = ui->listContact->currentItem(); + ui->listContact->removeItemWidget(pitem); + m_pContactList->erase(m_pContactList->cbegin()+idx); + + ui->listContact->clear(); + fillContactItems(); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// accept +// + +void +CDlgMdfContactList::accept() +{ + std::string str; + if (nullptr != m_pManufacturer) { + + // str = ui->editName->text().toStdString(); + // m_pmdf->setModuleName(str); + + // str = ui->editModel->text().toStdString(); + // m_pmdf->setModuleModel(str); + + // m_pmdf->setModuleLevel(ui->comboModuleLevel->currentIndex()); + + // str = ui->editVersion->text().toStdString(); + // m_pmdf->setModuleVersion(str); + + // str = ui->editDate->text().toStdString(); + // m_pmdf->setModuleChangeDate(str); + + // m_pmdf->setModuleBufferSize(ui->editBufferSize->value()); + + // str = ui->editCopyright->text().toStdString(); + // m_pmdf->setModuleCopyright(str); + } + else { + spdlog::error("MDF module information - Invalid MDF object (accept)"); + } + + QDialog::accept(); +} diff --git a/src/cdlgmdfcontactlist.h b/src/cdlgmdfcontactlist.h new file mode 100644 index 00000000..72052154 --- /dev/null +++ b/src/cdlgmdfcontactlist.h @@ -0,0 +1,119 @@ +// cdlgmdfcontactlist.h +// +// This file is part of the VSCP (https://www.vscp.org) +// +// The MIT License (MIT) +// +// Copyright © 2000-2023 Ake Hedman, Grodans Paradis AB +// +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +#ifndef CDLGMDFCONTACTLIST_H +#define CDLGMDFCONTACTLIST_H + +#include +#include + +#include "cdlgmdfcontact.h" + +#include + +// typedef enum mdf_dlg_contact_type { +// dlg_type_contact_none, +// dlg_type_contact_phone, +// dlg_type_contact_fax, +// dlg_type_contact_email, +// dlg_type_contact_web, +// dlg_type_contact_social, +// } mdf_dlg_contact_type; + + +namespace Ui { +class CDlgMdfContactList; +} + +class CDlgMdfContactList : public QDialog { + Q_OBJECT + +public: + explicit CDlgMdfContactList(QWidget* parent = nullptr); + ~CDlgMdfContactList(); + + /*! + Set inital focus to description + */ + void setInitialFocus(void); + + /*! + Set edit mode. + GUID will be READ ONLY + */ + void setEditMode(); + + /*! + Init dialog data + @param pmdfobject Pointer to MDF object + @param type Contact type + @param title Dialog title + */ + void initDialogData(CMDF_Manufacturer* pManufacturer, + mdf_dlg_contact_type type, + QString title); + + /*! + Fill in contact items + */ + void fillContactItems(void); + + + // ---------------------------------------------------------------------------- + // Getters & Setters + // ---------------------------------------------------------------------------- + + /*! + Name getter/setters + */ + // void setValue(const QString& name); + // QString getValue(void); + +public slots: + void accept(void); + + // Description buttons + void addContact(void); + void editContact(void); + void dupContact(void); + void deleteContact(void); + +private: + Ui::CDlgMdfContactList* ui; + + /// Type of contact item in this list + mdf_dlg_contact_type m_type; + + /// Holds pointer to manufacturer item + CMDF_Manufacturer* m_pManufacturer; + + /// Hold pointer to contact item + std::deque *m_pContactList; +}; + +#endif // CDLGMDFCONTACTList_H diff --git a/src/cdlgmdfcontactlist.ui b/src/cdlgmdfcontactlist.ui new file mode 100644 index 00000000..fd3e5a12 --- /dev/null +++ b/src/cdlgmdfcontactlist.ui @@ -0,0 +1,188 @@ + + + CDlgMdfContactList + + + + 0 + 0 + 661 + 445 + + + + Dialog + + + + + 0 + 410 + 651 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok + + + false + + + + + + 9 + 19 + 641 + 381 + + + + + + + Contact items + + + + + + + + + + + + + + + + Add description item + + + ... + + + + :/add.png:/add.png + + + Ctrl+A + + + + + + + Edit description item + + + ... + + + + :/pencil.svg:/pencil.svg + + + Ctrl+E + + + + + + + Duplicate description item + + + ... + + + + :/images/svg/copy.svg:/images/svg/copy.svg + + + Ctrl+D + + + + + + + Delete Description item + + + ... + + + + :/remove.png:/remove.png + + + Ctrl+X + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + + buttonBox + accepted() + CDlgMdfContactList + accept() + + + 325 + 425 + + + 330 + 222 + + + + + buttonBox + rejected() + CDlgMdfContactList + reject() + + + 325 + 425 + + + 330 + 222 + + + + + diff --git a/src/cdlgmdfmanufacturer.cpp b/src/cdlgmdfmanufacturer.cpp index bc20b24c..79ca9f69 100644 --- a/src/cdlgmdfmanufacturer.cpp +++ b/src/cdlgmdfmanufacturer.cpp @@ -146,31 +146,6 @@ CDlgMdfManufacturer::initDialogData(const CMDF_Object* pmdfobj, mdf_manufacturer ui->editName->setFocus(); break; } - - // Fill in descriptions - //fillDescription(); - - // std::map* pmapDescription = m_pmdf->getModuleDescriptionMap(); - // std::map::iterator itDesc = pmapDescription->begin(); - // while (itDesc != pmapDescription->end()) { - // std::string lang = itDesc->first; // key - // std::string description = itDesc->second; - // str = lang.c_str() + tr(" - ") + description.c_str(); - // ui->listDescription->addItem(str); - // itDesc++; - // } - - // Fill in help URL's - //fillInfoUrl(); - // std::map* pmapHelpUrl = m_pmdf->getModuleHelpUrlMap(); - // std::map::iterator itInfo = pmapHelpUrl->begin(); - // while (itInfo != pmapHelpUrl->end()) { - // std::string lang = itInfo->first; // key - // std::string info = itInfo->second; - // str = lang.c_str() + tr(" - ") + info.c_str(); - // ui->listInfo->addItem(str); - // itInfo++; - // } } diff --git a/src/cdlgmdfmodule.cpp b/src/cdlgmdfmodule.cpp index 68aee819..a6920b5a 100644 --- a/src/cdlgmdfmodule.cpp +++ b/src/cdlgmdfmodule.cpp @@ -182,7 +182,7 @@ CDlgMdfModule::fillDescription() QString str; // Fill in descriptions - std::map* pmapDescription = m_pmdf->getModuleDescriptionMap(); + std::map* pmapDescription = m_pmdf->getDescriptionMap(); std::map::iterator itDesc = pmapDescription->begin(); while (itDesc != pmapDescription->end()) { std::string lang = itDesc->first; // key @@ -203,10 +203,10 @@ CDlgMdfModule::fillInfoUrl() QString str; // Fill in help URL's - std::map* pmapHelpUrl = m_pmdf->getModuleHelpUrlMap(); + std::map* pmapHelpUrl = m_pmdf->getHelpUrlMap(); std::map::iterator itInfo = pmapHelpUrl->begin(); while (itInfo != pmapHelpUrl->end()) { - std::string lang = itInfo->first; // key + std::string lang = itInfo->first; // key std::string info = itInfo->second; str = lang.c_str() + tr(" - ") + info.c_str(); ui->listInfo->addItem(str); @@ -306,7 +306,7 @@ CDlgMdfModule::addDesc(void) QString selstr = "en"; // Default language CDlgMdfDescription dlg(this); - dlg.initDialogData(m_pmdf->getModuleDescriptionMap()/*, &selstr*/); + dlg.initDialogData(m_pmdf->getDescriptionMap()/*, &selstr*/); if (QDialog::Accepted == dlg.exec()) { ui->listDescription->clear(); fillDescription(); @@ -329,7 +329,7 @@ CDlgMdfModule::editDesc(void) QString selstr = pitem->text().split('_').first().left(2); CDlgMdfDescription dlg(this); - dlg.initDialogData(m_pmdf->getModuleDescriptionMap(), &selstr); + dlg.initDialogData(m_pmdf->getDescriptionMap(), &selstr); if (QDialog::Accepted == dlg.exec()) { ui->listDescription->clear(); fillDescription(); @@ -350,7 +350,7 @@ CDlgMdfModule::dupDesc(void) { if (-1 != ui->listDescription->currentRow()) { CDlgMdfDescription dlg(this); - dlg.initDialogData(m_pmdf->getModuleDescriptionMap()); + dlg.initDialogData(m_pmdf->getDescriptionMap()); if (QDialog::Accepted == dlg.exec()) { ui->listDescription->clear(); fillDescription(); @@ -376,7 +376,7 @@ CDlgMdfModule::deleteDesc(void) QListWidgetItem* pitem = ui->listDescription->currentItem(); QString selstr = pitem->text().split('_').first().left(2); - m_pmdf->getModuleDescriptionMap()->erase(selstr.toStdString()); + m_pmdf->getDescriptionMap()->erase(selstr.toStdString()); ui->listDescription->clear(); fillDescription(); @@ -393,7 +393,7 @@ CDlgMdfModule::addInfo(void) QString selstr = "en"; // Default language CDlgMdfInfoUrl dlg(this); - dlg.initDialogData(m_pmdf->getModuleHelpUrlMap()/*, &selstr*/); + dlg.initDialogData(m_pmdf->getHelpUrlMap()/*, &selstr*/); if (QDialog::Accepted == dlg.exec()) { ui->listInfo->clear(); fillInfoUrl(); @@ -416,7 +416,7 @@ CDlgMdfModule::editInfo(void) QString selstr = pitem->text().split('_').first().left(2); CDlgMdfInfoUrl dlg(this); - dlg.initDialogData(m_pmdf->getModuleHelpUrlMap(), &selstr); + dlg.initDialogData(m_pmdf->getHelpUrlMap(), &selstr); if (QDialog::Accepted == dlg.exec()) { ui->listInfo->clear(); fillInfoUrl(); @@ -437,7 +437,7 @@ CDlgMdfModule::dupInfo(void) { if (-1 != ui->listInfo->currentRow()) { CDlgMdfInfoUrl dlg(this); - dlg.initDialogData(m_pmdf->getModuleHelpUrlMap()); + dlg.initDialogData(m_pmdf->getHelpUrlMap()); if (QDialog::Accepted == dlg.exec()) { ui->listInfo->clear(); fillInfoUrl(); @@ -463,7 +463,7 @@ CDlgMdfModule::deleteInfo(void) QListWidgetItem* pitem = ui->listInfo->currentItem(); QString selstr = pitem->text().split('_').first().left(2); - m_pmdf->getModuleHelpUrlMap()->erase(selstr.toStdString()); + m_pmdf->getHelpUrlMap()->erase(selstr.toStdString()); ui->listInfo->clear(); fillInfoUrl(); diff --git a/src/cfrmmdf.cpp b/src/cfrmmdf.cpp index 1c180d03..c1e103c2 100644 --- a/src/cfrmmdf.cpp +++ b/src/cfrmmdf.cpp @@ -49,6 +49,7 @@ #include "cdlgeditmap.h" #include "cdlgmdfcontact.h" +#include "cdlgmdfcontactlist.h" #include "cdlgmdfmanufacturer.h" #include "cdlgmdfmodule.h" @@ -383,7 +384,7 @@ CFrmMdf::showMdfContextMenu(const QPoint& pos) case mdf_type_manufacturer: // menu->addAction(QString(tr("Manufacturer")), this, SLOT(loadSelectedMdf())); - menu->addAction(QString(tr("Edit")), this, SLOT(editManufacturerData())); + menu->addAction(QString(tr("Edit manufacturer")), this, SLOT(editManufacturerData())); break; case mdf_type_manufacturer_item: @@ -391,6 +392,46 @@ CFrmMdf::showMdfContextMenu(const QPoint& pos) menu->addAction(QString(tr("Edit")), this, SLOT(editManufacturerData())); break; + case mdf_type_email: + menu->addAction(QString(tr("Edit email")), this, SLOT(editContact())); + break; + + case mdf_type_email_item: + menu->addAction(QString(tr("Edit email item")), this, SLOT(editContact())); + break; + + case mdf_type_phone: + menu->addAction(QString(tr("Edit phone")), this, SLOT(editContact())); + break; + + case mdf_type_phone_item: + menu->addAction(QString(tr("Edit phone item")), this, SLOT(editContact())); + break; + + case mdf_type_fax: + menu->addAction(QString(tr("Edit fax")), this, SLOT(editContact())); + break; + + case mdf_type_fax_item: + menu->addAction(QString(tr("Edit fax item")), this, SLOT(editContact())); + break; + + case mdf_type_web: + menu->addAction(QString(tr("Edit web")), this, SLOT(editContact())); + break; + + case mdf_type_web_item: + menu->addAction(QString(tr("Edit web item")), this, SLOT(editContact())); + break; + + case mdf_type_social: + menu->addAction(QString(tr("Edit social")), this, SLOT(editContact())); + break; + + case mdf_type_social_item: + menu->addAction(QString(tr("Edit social item")), this, SLOT(editContact())); + break; + case mdf_type_file: menu->addAction(QString(tr("File")), this, SLOT(loadSelectedMdf())); break; @@ -443,26 +484,6 @@ CFrmMdf::showMdfContextMenu(const QPoint& pos) menu->addAction(QString(tr("Manual item")), this, SLOT(loadSelectedMdf())); break; - case mdf_type_email: - menu->addAction(QString(tr("email")), this, SLOT(loadSelectedMdf())); - break; - - case mdf_type_phone: - menu->addAction(QString(tr("phone")), this, SLOT(loadSelectedMdf())); - break; - - case mdf_type_fax: - menu->addAction(QString(tr("fax")), this, SLOT(loadSelectedMdf())); - break; - - case mdf_type_web: - menu->addAction(QString(tr("web")), this, SLOT(loadSelectedMdf())); - break; - - case mdf_type_social: - menu->addAction(QString(tr("social")), this, SLOT(loadSelectedMdf())); - break; - case mdf_type_generic_string: menu->addAction(QString(tr("string")), this, SLOT(loadSelectedMdf())); break; @@ -896,6 +917,169 @@ CFrmMdf::fillRegisterInfo(QTreeWidgetItem* pParent, CMDF_Register* preg) fillHelpUrlItems(pParent, preg, preg->getMapDescription()); } +/////////////////////////////////////////////////////////////////////////////// +// renderManufacturerEmail +// + +void +CFrmMdf::renderManufacturerEmail(QMdfTreeWidgetItem* pItemEmailHead) +{ + int index = 0; + QMdfTreeWidgetItem* pItem; + CMDF_Item* pItemEmail; + + do { + pItemEmail = m_mdf.getManufacturer()->getEmailObj(index); + if (nullptr != pItemEmail) { + pItem = new QMdfTreeWidgetItem(pItemEmailHead, pItemEmail, mdf_type_email_item, index); + pItem->setText(0, pItemEmail->getName().c_str()); + pItemEmailHead->addChild(pItem); + fillDescriptionItems(pItem, + pItemEmail, + pItemEmail->getDescriptionMap()); + fillHelpUrlItems(pItem, + pItemEmail, + pItemEmail->getInfoUrlMap()); + index++; + } + } while (nullptr != pItemEmail); +} + +/////////////////////////////////////////////////////////////////////////////// +// renderManufacturerPhone +// + +void +CFrmMdf::renderManufacturerPhone(QMdfTreeWidgetItem* pItemPhoneHead) +{ + int index = 0; + QMdfTreeWidgetItem* pItem; + CMDF_Item* pItemPhone; + + do { + pItemPhone = m_mdf.getManufacturer()->getPhoneObj(index); + if (nullptr != pItemPhone) { + pItem = new QMdfTreeWidgetItem(pItemPhoneHead, pItemPhone, mdf_type_phone_item, index); + pItem->setText(0, pItemPhone->getName().c_str()); + pItemPhoneHead->addChild(pItem); + fillDescriptionItems(pItem, + pItemPhone, + pItemPhone->getDescriptionMap()); + fillHelpUrlItems(pItem, + pItemPhone, + pItemPhone->getInfoUrlMap()); + index++; + } + } while (nullptr != pItemPhone); +} + +/////////////////////////////////////////////////////////////////////////////// +// renderManufacturerFax +// + +void +CFrmMdf::renderManufacturerFax(QMdfTreeWidgetItem* pItemFaxHead) +{ + int index = 0; + QMdfTreeWidgetItem* pItem; + CMDF_Item* pItemFax; + + do { + pItemFax = m_mdf.getManufacturer()->getFaxObj(index); + if (nullptr != pItemFax) { + pItem = new QMdfTreeWidgetItem(pItemFaxHead, pItemFax, mdf_type_phone_item, index); + pItem->setText(0, pItemFax->getName().c_str()); + pItemFaxHead->addChild(pItem); + fillDescriptionItems(pItem, + pItemFax, + pItemFax->getDescriptionMap()); + fillHelpUrlItems(pItem, + pItemFax, + pItemFax->getInfoUrlMap()); + index++; + } + } while (nullptr != pItemFax); +} + +/////////////////////////////////////////////////////////////////////////////// +// renderManufacturerWeb +// + +void +CFrmMdf::renderManufacturerWeb(QMdfTreeWidgetItem* pItemWebHead) +{ + int index = 0; + QMdfTreeWidgetItem* pItem; + CMDF_Item* pItemWeb; + + do { + pItemWeb = m_mdf.getManufacturer()->getWebObj(index); + if (nullptr != pItemWeb) { + pItem = new QMdfTreeWidgetItem(pItemWebHead, pItemWeb, mdf_type_phone_item, index); + pItem->setText(0, pItemWeb->getName().c_str()); + pItemWebHead->addChild(pItem); + fillDescriptionItems(pItem, + pItemWeb, + pItemWeb->getDescriptionMap()); + fillHelpUrlItems(pItem, + pItemWeb, + pItemWeb->getInfoUrlMap()); + index++; + } + } while (nullptr != pItemWeb); +} + +/////////////////////////////////////////////////////////////////////////////// +// renderManufacturerSocial +// + +void +CFrmMdf::renderManufacturerSocial(QMdfTreeWidgetItem* pItemSocialHead) +{ + int index = 0; + QMdfTreeWidgetItem* pItem; + CMDF_Item* pItemSocial; + + do { + pItemSocial = m_mdf.getManufacturer()->getSocialObj(index); + if (nullptr != pItemSocial) { + pItem = new QMdfTreeWidgetItem(pItemSocialHead, pItemSocial, mdf_type_phone_item, index); + pItem->setText(0, pItemSocial->getName().c_str()); + pItemSocialHead->addChild(pItem); + fillDescriptionItems(pItem, + pItemSocial, + pItemSocial->getDescriptionMap()); + fillHelpUrlItems(pItem, + pItemSocial, + pItemSocial->getInfoUrlMap()); + index++; + } + } while (nullptr != pItemSocial); +} + +/////////////////////////////////////////////////////////////////////////////// +// removeSubItems +// + +void +CFrmMdf::removeSubItems(QMdfTreeWidgetItem* pItem, mdf_record_type type) +{ + // Save expansion state + bool bExpanded = pItem->isExpanded(); + + // Expand to make traversion possible + pItem->setExpanded(true); + + QMdfTreeWidgetItem* piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + while (type == piter->getObjectType()) { + pItem->removeChild(piter); + delete piter; + piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + } + + pItem->setExpanded(bExpanded); +} + /////////////////////////////////////////////////////////////////////////////// // loadMdf // @@ -973,14 +1157,14 @@ CFrmMdf::loadMdf(void) pItem->setText(0, str); pItemModule->addChild(pItem); - fillDescriptionItems(pItemModule, &m_mdf, m_mdf.getModuleDescriptionMap()); - fillHelpUrlItems(pItemModule, &m_mdf, m_mdf.getModuleHelpUrlMap()); + fillDescriptionItems(pItemModule, &m_mdf, m_mdf.getDescriptionMap()); + fillHelpUrlItems(pItemModule, &m_mdf, m_mdf.getHelpUrlMap()); // * * * Manufacturer info * * * - QMdfTreeWidgetItem* pItemManufacturer = new QMdfTreeWidgetItem(pItemModule, - m_mdf.getManufacturer(), - mdf_type_manufacturer); + QMdfTreeWidgetItem* pItemManufacturer = new QMdfTreeWidgetItem(pItemModule, + m_mdf.getManufacturer(), + mdf_type_manufacturer); pItemManufacturer->setFont(0, fontTopItem); pItemManufacturer->setForeground(0, greenBrush); pItemManufacturer->setText(0, tr("Manufacturer")); @@ -990,66 +1174,66 @@ CFrmMdf::loadMdf(void) if (nullptr != pManufacturer) { str = QString("Name: ") + m_mdf.getManufacturerName().c_str(); - pItem = new QMdfTreeWidgetItem(pItemManufacturer, - m_mdf.getManufacturer(), - mdf_type_manufacturer_item, - index_manufacturer_name); + pItem = new QMdfTreeWidgetItem(pItemManufacturer, + m_mdf.getManufacturer(), + mdf_type_manufacturer_item, + index_manufacturer_name); pItem->setText(0, str); pItemModule->addChild(pItem); str = QString("Street: ") + m_mdf.getManufacturerStreetAddress().c_str(); - pItem = new QMdfTreeWidgetItem(pItemManufacturer, - m_mdf.getManufacturer(), - mdf_type_manufacturer_item, - index_manufacturer_street); + pItem = new QMdfTreeWidgetItem(pItemManufacturer, + m_mdf.getManufacturer(), + mdf_type_manufacturer_item, + index_manufacturer_street); pItem->setText(0, str); pItemModule->addChild(pItem); str = QString("City: ") + m_mdf.getManufacturerCityAddress().c_str(); - pItem = new QMdfTreeWidgetItem(pItemManufacturer, - m_mdf.getManufacturer(), - mdf_type_manufacturer_item, - index_manufacturer_city); + pItem = new QMdfTreeWidgetItem(pItemManufacturer, + m_mdf.getManufacturer(), + mdf_type_manufacturer_item, + index_manufacturer_city); pItem->setText(0, str); pItemModule->addChild(pItem); str = QString("Town: ") + m_mdf.getManufacturerTownAddress().c_str(); - pItem = new QMdfTreeWidgetItem(pItemManufacturer, - m_mdf.getManufacturer(), - mdf_type_manufacturer_item, - index_manufacturer_town); + pItem = new QMdfTreeWidgetItem(pItemManufacturer, + m_mdf.getManufacturer(), + mdf_type_manufacturer_item, + index_manufacturer_town); pItem->setText(0, str); pItemModule->addChild(pItem); str = QString("Post Code: ") + m_mdf.getManufacturerPostCodeAddress().c_str(); - pItem = new QMdfTreeWidgetItem(pItemManufacturer, - m_mdf.getManufacturer(), - mdf_type_manufacturer_item, - index_manufacturer_post_code); + pItem = new QMdfTreeWidgetItem(pItemManufacturer, + m_mdf.getManufacturer(), + mdf_type_manufacturer_item, + index_manufacturer_post_code); pItem->setText(0, str); pItemModule->addChild(pItem); str = QString("Region: ") + m_mdf.getManufacturerRegionAddress().c_str(); - pItem = new QMdfTreeWidgetItem(pItemManufacturer, - m_mdf.getManufacturer(), - mdf_type_manufacturer_item, - index_manufacturer_region); + pItem = new QMdfTreeWidgetItem(pItemManufacturer, + m_mdf.getManufacturer(), + mdf_type_manufacturer_item, + index_manufacturer_region); pItem->setText(0, str); pItemModule->addChild(pItem); str = QString("State: ") + m_mdf.getManufacturerStateAddress().c_str(); - pItem = new QMdfTreeWidgetItem(pItemManufacturer, - m_mdf.getManufacturer(), - mdf_type_manufacturer_item, - index_manufacturer_state); + pItem = new QMdfTreeWidgetItem(pItemManufacturer, + m_mdf.getManufacturer(), + mdf_type_manufacturer_item, + index_manufacturer_state); pItem->setText(0, str); pItemModule->addChild(pItem); str = QString("Country: ") + m_mdf.getManufacturerCountryAddress().c_str(); - pItem = new QMdfTreeWidgetItem(pItemManufacturer, - m_mdf.getManufacturer(), - mdf_type_manufacturer_item, - index_manufacturer_country); + pItem = new QMdfTreeWidgetItem(pItemManufacturer, + m_mdf.getManufacturer(), + mdf_type_manufacturer_item, + index_manufacturer_country); pItem->setText(0, str); pItemModule->addChild(pItem); @@ -1063,24 +1247,29 @@ CFrmMdf::loadMdf(void) pItemEmailHead->setText(0, tr("Email")); pItemModule->addChild(pItemEmailHead); + renderManufacturerEmail(pItemEmailHead); + + /* index = 0; CMDF_Item* pItemEmail; do { - pItemEmail = pManufacturer->getEmailObj(index++); + pItemEmail = pManufacturer->getEmailObj(index); if (nullptr != pItemEmail) { // str = QString("Email ") + QString::number(index) + ": " + pItemEmail->getName().c_str(); - pItem = new QMdfTreeWidgetItem(pItemEmailHead, mdf_type_email_item); + pItem = new QMdfTreeWidgetItem(pItemEmailHead, pItemEmail, mdf_type_email_item, index); pItem->setText(0, pItemEmail->getName().c_str()); pItemEmailHead->addChild(pItem); fillDescriptionItems(pItem, - pManufacturer->getEmailObj(), - pManufacturer->getEmailObj()->getDescriptionMap()); + pItemEmail, + pItemEmail->getDescriptionMap()); fillHelpUrlItems(pItem, - pManufacturer->getEmailObj(), - pManufacturer->getEmailObj()->getInfoUrlMap()); + pItemEmail, + pItemEmail->getInfoUrlMap()); + index++; } } while (nullptr != pItemEmail); + */ QMdfTreeWidgetItem* pItemPhoneHead = new QMdfTreeWidgetItem(pItemManufacturer, m_mdf.getManufacturer(), @@ -1090,24 +1279,25 @@ CFrmMdf::loadMdf(void) pItemPhoneHead->setText(0, tr("Phone")); pItemModule->addChild(pItemPhoneHead); - CMDF_Item* pItemPhone; - index = 0; - - do { - pItemPhone = pManufacturer->getPhoneObj(index++); - if (nullptr != pItemPhone) { - // str = QString("Phone ") + QString::number(index) + ": " + pItemPhone->getName().c_str(); - pItem = new QMdfTreeWidgetItem(pItemPhoneHead, mdf_type_phone_item); - pItem->setText(0, pItemPhone->getName().c_str()); - pItemPhoneHead->addChild(pItem); - fillDescriptionItems(pItem, - pManufacturer->getPhoneObj(), - pManufacturer->getPhoneObj()->getDescriptionMap()); - fillHelpUrlItems(pItem, - pManufacturer->getPhoneObj(), - pManufacturer->getPhoneObj()->getInfoUrlMap()); - } - } while (nullptr != pItemPhone); + renderManufacturerPhone(pItemPhoneHead); + // CMDF_Item* pItemPhone; + // index = 0; + + // do { + // pItemPhone = pManufacturer->getPhoneObj(index++); + // if (nullptr != pItemPhone) { + // // str = QString("Phone ") + QString::number(index) + ": " + pItemPhone->getName().c_str(); + // pItem = new QMdfTreeWidgetItem(pItemPhoneHead, pItemPhone, mdf_type_phone_item, index); + // pItem->setText(0, pItemPhone->getName().c_str()); + // pItemPhoneHead->addChild(pItem); + // fillDescriptionItems(pItem, + // pManufacturer->getPhoneObj(), + // pManufacturer->getPhoneObj()->getDescriptionMap()); + // fillHelpUrlItems(pItem, + // pManufacturer->getPhoneObj(), + // pManufacturer->getPhoneObj()->getInfoUrlMap()); + // } + // } while (nullptr != pItemPhone); QMdfTreeWidgetItem* pItemFaxHead = new QMdfTreeWidgetItem(pItemManufacturer, m_mdf.getManufacturer(), @@ -1117,24 +1307,25 @@ CFrmMdf::loadMdf(void) pItemFaxHead->setText(0, tr("Fax")); pItemModule->addChild(pItemFaxHead); - CMDF_Item* pItemFax; - index = 0; - - do { - pItemFax = pManufacturer->getFaxObj(index++); - if (nullptr != pItemFax) { - // str = QString("Fax ") + QString::number(index) + ": " + pItemFax->getName().c_str(); - pItem = new QMdfTreeWidgetItem(pItemFaxHead, mdf_type_fax_item); - pItem->setText(0, pItemFax->getName().c_str()); - pItemFaxHead->addChild(pItem); - fillDescriptionItems(pItem, - pManufacturer->getFaxObj(), - pManufacturer->getFaxObj()->getDescriptionMap()); - fillHelpUrlItems(pItem, - pManufacturer->getFaxObj(), - pManufacturer->getFaxObj()->getInfoUrlMap()); - } - } while (nullptr != pItemFax); + renderManufacturerFax(pItemFaxHead); + // CMDF_Item* pItemFax; + // index = 0; + + // do { + // pItemFax = pManufacturer->getFaxObj(index++); + // if (nullptr != pItemFax) { + // // str = QString("Fax ") + QString::number(index) + ": " + pItemFax->getName().c_str(); + // pItem = new QMdfTreeWidgetItem(pItemFaxHead, pItemFax, mdf_type_fax_item, index); + // pItem->setText(0, pItemFax->getName().c_str()); + // pItemFaxHead->addChild(pItem); + // fillDescriptionItems(pItem, + // pManufacturer->getFaxObj(), + // pManufacturer->getFaxObj()->getDescriptionMap()); + // fillHelpUrlItems(pItem, + // pManufacturer->getFaxObj(), + // pManufacturer->getFaxObj()->getInfoUrlMap()); + // } + // } while (nullptr != pItemFax); QMdfTreeWidgetItem* pItemWebHead = new QMdfTreeWidgetItem(pItemManufacturer, m_mdf.getManufacturer(), @@ -1144,24 +1335,25 @@ CFrmMdf::loadMdf(void) pItemWebHead->setText(0, tr("Web")); pItemModule->addChild(pItemWebHead); - CMDF_Item* pItemWeb; - index = 0; - - do { - pItemWeb = pManufacturer->getWebObj(index++); - if (nullptr != pItemWeb) { - // str = QString("Web ") + QString::number(index) + ": " + pItemWeb->getName().c_str(); - pItem = new QMdfTreeWidgetItem(pItemWebHead, mdf_type_web); - pItem->setText(0, pItemWeb->getName().c_str()); - pItemWebHead->addChild(pItem); - fillDescriptionItems(pItem, - pManufacturer->getWebObj(), - pManufacturer->getWebObj()->getDescriptionMap()); - fillHelpUrlItems(pItem, - pManufacturer->getWebObj(), - pManufacturer->getWebObj()->getInfoUrlMap()); - } - } while (nullptr != pItemWeb); + renderManufacturerWeb(pItemWebHead); + // CMDF_Item* pItemWeb; + // index = 0; + + // do { + // pItemWeb = pManufacturer->getWebObj(index++); + // if (nullptr != pItemWeb) { + // // str = QString("Web ") + QString::number(index) + ": " + pItemWeb->getName().c_str(); + // pItem = new QMdfTreeWidgetItem(pItemWebHead, pItemWeb, mdf_type_web_item, index); + // pItem->setText(0, pItemWeb->getName().c_str()); + // pItemWebHead->addChild(pItem); + // fillDescriptionItems(pItem, + // pManufacturer->getWebObj(), + // pManufacturer->getWebObj()->getDescriptionMap()); + // fillHelpUrlItems(pItem, + // pManufacturer->getWebObj(), + // pManufacturer->getWebObj()->getInfoUrlMap()); + // } + // } while (nullptr != pItemWeb); QMdfTreeWidgetItem* pItemSocialHead = new QMdfTreeWidgetItem(pItemManufacturer, m_mdf.getManufacturer(), @@ -1171,20 +1363,21 @@ CFrmMdf::loadMdf(void) pItemSocialHead->setText(0, tr("Social")); pItemModule->addChild(pItemSocialHead); - CMDF_Item* pItemSocial; - index = 0; - - do { - pItemSocial = pManufacturer->getSocialObj(index++); - if (nullptr != pItemSocial) { - // str = QString("Social ") + QString::number(index) + ": " + pItemSocial->getName().c_str(); - pItem = new QMdfTreeWidgetItem(pItemSocialHead, mdf_type_social_item); - pItem->setText(0, pItemSocial->getName().c_str()); - pItemSocialHead->addChild(pItem); - fillDescriptionItems(pItem, pManufacturer->getSocialObj(), pManufacturer->getSocialObj()->getDescriptionMap()); - fillHelpUrlItems(pItem, pManufacturer->getSocialObj(), pManufacturer->getSocialObj()->getInfoUrlMap()); - } - } while (nullptr != pItemSocial); + renderManufacturerSocial(pItemSocialHead); + // CMDF_Item* pItemSocial; + // index = 0; + + // do { + // pItemSocial = pManufacturer->getSocialObj(index++); + // if (nullptr != pItemSocial) { + // // str = QString("Social ") + QString::number(index) + ": " + pItemSocial->getName().c_str(); + // pItem = new QMdfTreeWidgetItem(pItemSocialHead, pItemSocial, mdf_type_social_item, index); + // pItem->setText(0, pItemSocial->getName().c_str()); + // pItemSocialHead->addChild(pItem); + // fillDescriptionItems(pItem, pManufacturer->getSocialObj(), pManufacturer->getSocialObj()->getDescriptionMap()); + // fillHelpUrlItems(pItem, pManufacturer->getSocialObj(), pManufacturer->getSocialObj()->getInfoUrlMap()); + // } + // } while (nullptr != pItemSocial); } else { spdlog::error("No manufacturer object when reading MDF"); @@ -2395,6 +2588,7 @@ CFrmMdf::onItemDoubleClicked(QTreeWidgetItem* item, int column) QMdfTreeWidgetItem* CFrmMdf::findMdfWidgetItem(QMdfTreeWidgetItem* pItem, mdf_record_type type) { + pItem->setExpanded(true); QMdfTreeWidgetItem* piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); while (nullptr != piter) { @@ -2537,6 +2731,46 @@ CFrmMdf::editData() editManufacturerData(); break; + case mdf_type_email: + editContact(); + break; + + case mdf_type_email_item: + editContact(); + break; + + case mdf_type_phone: + editContact(); + break; + + case mdf_type_phone_item: + editContact(); + break; + + case mdf_type_fax: + editContact(); + break; + + case mdf_type_fax_item: + editContact(); + break; + + case mdf_type_web: + editContact(); + break; + + case mdf_type_web_item: + editContact(); + break; + + case mdf_type_social: + editContact(); + break; + + case mdf_type_social_item: + editContact(); + break; + case mdf_type_file: break; @@ -2576,21 +2810,6 @@ CFrmMdf::editData() case mdf_type_manual_item: break; - case mdf_type_email: - break; - - case mdf_type_phone: - break; - - case mdf_type_fax: - break; - - case mdf_type_web: - break; - - case mdf_type_social: - break; - case mdf_type_generic_string: break; @@ -2738,8 +2957,8 @@ CFrmMdf::editModuleData() break; case index_module_level: { - QString str = "%1"; - str = PREFIX_MDF_MODULE_LEVEL + str.arg(m_mdf.getModuleLevel() + 1); + QString str; + str = PREFIX_MDF_MODULE_LEVEL + str.arg(m_mdf.getModuleLevel() + 1); piter->setText(0, str); } break; @@ -2778,10 +2997,10 @@ CFrmMdf::editModuleData() // } deleteMdfWidgetChildItems(pItemDescription, mdf_type_generic_description_item); - fillDescriptionItems(pItemDescription, &m_mdf, m_mdf.getModuleDescriptionMap(), true); + fillDescriptionItems(pItemDescription, &m_mdf, m_mdf.getDescriptionMap(), true); deleteMdfWidgetChildItems(pItemItemInfoURL, mdf_type_generic_help_url_item); - fillHelpUrlItems(pItemItemInfoURL, &m_mdf, m_mdf.getModuleHelpUrlMap(), true); + fillHelpUrlItems(pItemItemInfoURL, &m_mdf, m_mdf.getHelpUrlMap(), true); } // accept } @@ -2839,12 +3058,12 @@ CFrmMdf::editDescription() QMdfTreeWidgetItem* piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItemDescription); CDlgEditMap dlg(this); - dlg.initDialogData(m_mdf.getModuleDescriptionMap(), map_type_description, &selstr); + dlg.initDialogData(m_mdf.getDescriptionMap(), map_type_description, &selstr); if (QDialog::Accepted == dlg.exec()) { // Update Module items deleteMdfWidgetChildItems(pItemDescription, mdf_type_generic_description_item); - fillDescriptionItems(pItemDescription, &m_mdf, m_mdf.getModuleDescriptionMap(), true); + fillDescriptionItems(pItemDescription, &m_mdf, m_mdf.getDescriptionMap(), true); QMdfTreeWidgetItem* piter = nullptr; } @@ -2903,13 +3122,13 @@ CFrmMdf::editInfoUrl() QMdfTreeWidgetItem* piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItemInfoUrl); CDlgEditMap dlg(this); - dlg.initDialogData(m_mdf.getModuleHelpUrlMap(), map_type_info_url, &selstr); + dlg.initDialogData(m_mdf.getHelpUrlMap(), map_type_info_url, &selstr); if (QDialog::Accepted == dlg.exec()) { // Update Module items deleteMdfWidgetChildItems(pItemInfoUrl, mdf_type_generic_help_url_item); - fillHelpUrlItems(pItemInfoUrl, &m_mdf, m_mdf.getModuleHelpUrlMap(), true); + fillHelpUrlItems(pItemInfoUrl, &m_mdf, m_mdf.getHelpUrlMap(), true); QMdfTreeWidgetItem* piter = nullptr; } @@ -2929,14 +3148,14 @@ CFrmMdf::editManufacturerData() // Item must be selected if (nullptr == pItem) { - int ret = QMessageBox::critical(this, tr("MDF module edit"), tr("No MDF module item selected")); + int ret = QMessageBox::critical(this, tr("MDF manufacturer edit"), tr("No MDF manufacturer item selected")); return; } // Must have an object if (nullptr == pItem->getObject()) { - int ret = QMessageBox::critical(this, tr("MDF module edit"), tr("Internal error: Invalid module object")); - spdlog::error("MDF module edit - object has nullptr"); + int ret = QMessageBox::critical(this, tr("MDF manufacturer edit"), tr("Internal error: Invalid manufacturer object")); + spdlog::error("MDF manufacturer edit - object has nullptr"); return; } @@ -2970,8 +3189,8 @@ CFrmMdf::editManufacturerData() if (QDialog::Accepted == dlg.exec()) { // Update Module items - - CMDF_Manufacturer *pmanufacturer = (CMDF_Manufacturer*)pItem->getObject(); + + CMDF_Manufacturer* pmanufacturer = (CMDF_Manufacturer*)pItem->getObject(); pmanufacturer->setName(dlg.getName().toStdString()); pmanufacturer->getAddressObj()->setStreet(dlg.getStreet().toStdString()); pmanufacturer->getAddressObj()->setTown(dlg.getTown().toStdString()); @@ -2982,7 +3201,7 @@ CFrmMdf::editManufacturerData() pmanufacturer->getAddressObj()->setCountry(dlg.getCountry().toStdString()); QMdfTreeWidgetItem* piter = nullptr; - piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItemManufacturer); + piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItemManufacturer); do { switch (piter->getElementIndex()) { @@ -2993,35 +3212,256 @@ CFrmMdf::editManufacturerData() case index_manufacturer_street: piter->setText(0, PREFIX_MDF_MANUFACTURER_STREET + pmanufacturer->getAddressObj()->getStreet().c_str()); - break; + break; case index_manufacturer_town: piter->setText(0, PREFIX_MDF_MANUFACTURER_TOWN + pmanufacturer->getAddressObj()->getTown().c_str()); - break; + break; case index_manufacturer_city: piter->setText(0, PREFIX_MDF_MANUFACTURER_CITY + pmanufacturer->getAddressObj()->getCity().c_str()); - break; + break; case index_manufacturer_post_code: piter->setText(0, PREFIX_MDF_MANUFACTURER_POST_CODE + pmanufacturer->getAddressObj()->getPostCode().c_str()); - break; + break; case index_manufacturer_state: piter->setText(0, PREFIX_MDF_MANUFACTURER_STATE + pmanufacturer->getAddressObj()->getState().c_str()); - break; + break; case index_manufacturer_region: piter->setText(0, PREFIX_MDF_MANUFACTURER_REGION + pmanufacturer->getAddressObj()->getRegion().c_str()); - break; + break; case index_manufacturer_country: piter->setText(0, PREFIX_MDF_MANUFACTURER_COUNTRY + pmanufacturer->getAddressObj()->getCountry().c_str()); - break; + break; } piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(piter); - + } while (mdf_type_manufacturer_item == piter->getObjectType()); } +} + +/////////////////////////////////////////////////////////////////////////////// +// showContactDialog +// + +void +CFrmMdf::showContactDialog(QMdfTreeWidgetItem* pItem, mdf_dlg_contact_type type, QString title) +{ + CMDF_Item* pContactObj = (CMDF_Item*)pItem->getObject(); + if (nullptr == pContactObj) { + int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("No contact item object")); + return; + } + + CDlgMdfContact dlg(this); + dlg.setWindowTitle(title); + dlg.initDialogData(pContactObj, type, title); + if (QDialog::Accepted == dlg.exec()) { + + pItem->setText(0, dlg.getValue()); + QMdfTreeWidgetItem* pItemDescription = findMdfWidgetItem(pItem, mdf_type_generic_description); // findDocumentItem(pItemModule); + QMdfTreeWidgetItem* pItemItemInfoURL = findMdfWidgetItem(pItem, mdf_type_generic_help_url); // findInfoUrlItem(pItemModule); + + deleteMdfWidgetChildItems(pItemDescription, mdf_type_generic_description_item); + fillDescriptionItems(pItemDescription, + (CMDF_Item*)pItem->getObject(), + ((CMDF_Item*)pItem->getObject())->getDescriptionMap(), + true); + fillHelpUrlItems(pItemItemInfoURL, + (CMDF_Item*)pItem->getObject(), + ((CMDF_Item*)pItem->getObject())->getInfoUrlMap(), + true); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// editContact +// + +void +CFrmMdf::editContact(void) +{ + QMdfTreeWidgetItem* pItem = (QMdfTreeWidgetItem*)ui->treeMDF->currentItem(); + + // Item must be selected + if (nullptr == pItem) { + int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("No MDF contact item selected")); + return; + } + + // Must have an object + if (nullptr == pItem->getObject()) { + int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("Internal error: Invalid contact object")); + spdlog::error("MDF contact edit - object has nullptr"); + return; + } + + // Must be correct object type + // if ((mdf_type_phone != pItem->getObjectType()) && (mdf_type_phone_item != pItem->getObjectType()) && + // (mdf_type_fax != pItem->getObjectType()) && (mdf_type_fax_item != pItem->getObjectType()) && + // (mdf_type_email != pItem->getObjectType()) && (mdf_type_email_item != pItem->getObjectType()) && + // (mdf_type_web != pItem->getObjectType()) && (mdf_type_web_item != pItem->getObjectType()) && + // (mdf_type_social != pItem->getObjectType()) && (mdf_type_social_item != pItem->getObjectType())) { + // int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("This is not a contact item")); + // spdlog::error("MDF contact edit - Not a contact item"); + // return; + // } + + switch (pItem->getObjectType()) { + + case mdf_type_phone: { + CMDF_Manufacturer* pManufacturer = (CMDF_Manufacturer*)pItem->getObject(); + if (nullptr == pManufacturer) { + int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("No contact item object")); + return; + } + + CDlgMdfContactList dlg(this); + dlg.initDialogData(pManufacturer, dlg_type_contact_phone, "Edit phone contact items"); + if (QDialog::Accepted == dlg.exec()) { + + // Expand to make traversion possible + pItem->setExpanded(true); + + QMdfTreeWidgetItem* piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + while (mdf_type_phone_item == piter->getObjectType()) { + pItem->removeChild(piter); + delete piter; + piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + } + + renderManufacturerPhone(pItem); + } + } break; + + case mdf_type_phone_item: + showContactDialog(pItem, dlg_type_contact_phone, "Edit phone contacts"); + break; + + case mdf_type_fax: { + CMDF_Manufacturer* pManufacturer = (CMDF_Manufacturer*)pItem->getObject(); + if (nullptr == pManufacturer) { + int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("No contact item object")); + return; + } + + CDlgMdfContactList dlg(this); + dlg.initDialogData(pManufacturer, dlg_type_contact_fax, "Edit fax contact items"); + if (QDialog::Accepted == dlg.exec()) { + + // Expand to make traversion possible + pItem->setExpanded(true); + + QMdfTreeWidgetItem* piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + while (mdf_type_fax_item == piter->getObjectType()) { + pItem->removeChild(piter); + delete piter; + piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + } + + renderManufacturerFax(pItem); + } + } break; + + case mdf_type_fax_item: + showContactDialog(pItem, dlg_type_contact_fax, "Edit fax contacts"); + break; + + case mdf_type_email: { + CMDF_Manufacturer* pManufacturer = (CMDF_Manufacturer*)pItem->getObject(); + if (nullptr == pManufacturer) { + int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("No contact item object")); + return; + } + + CDlgMdfContactList dlg(this); + dlg.initDialogData(pManufacturer, dlg_type_contact_email, "Edit email contact items"); + if (QDialog::Accepted == dlg.exec()) { + + // Expand to make traversion possible + pItem->setExpanded(true); + + QMdfTreeWidgetItem* piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + while (mdf_type_email_item == piter->getObjectType()) { + pItem->removeChild(piter); + delete piter; + piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + } + + renderManufacturerEmail(pItem); + } + } break; + + case mdf_type_email_item: + showContactDialog(pItem, dlg_type_contact_social, "Edit email contacts"); + break; + + case mdf_type_web: { + CMDF_Manufacturer* pManufacturer = (CMDF_Manufacturer*)pItem->getObject(); + if (nullptr == pManufacturer) { + int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("No contact item object")); + return; + } + + CDlgMdfContactList dlg(this); + dlg.initDialogData(pManufacturer, dlg_type_contact_web, "Edit web contact items"); + if (QDialog::Accepted == dlg.exec()) { + + // Expand to make traversion possible + pItem->setExpanded(true); + + QMdfTreeWidgetItem* piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + while (mdf_type_web_item == piter->getObjectType()) { + pItem->removeChild(piter); + delete piter; + piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + } + + renderManufacturerWeb(pItem); + } + } break; + + case mdf_type_web_item: + showContactDialog(pItem, dlg_type_contact_web, "Edit fax contacts"); + break; + + case mdf_type_social: { + CMDF_Manufacturer* pManufacturer = (CMDF_Manufacturer*)pItem->getObject(); + if (nullptr == pManufacturer) { + int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("No contact item object")); + return; + } + + CDlgMdfContactList dlg(this); + dlg.initDialogData(pManufacturer, dlg_type_contact_social, "Edit social contact items"); + if (QDialog::Accepted == dlg.exec()) { + + // Expand to make traversion possible + pItem->setExpanded(true); + + QMdfTreeWidgetItem* piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + while (mdf_type_social_item == piter->getObjectType()) { + pItem->removeChild(piter); + delete piter; + piter = (QMdfTreeWidgetItem*)ui->treeMDF->itemBelow(pItem); + } + + renderManufacturerSocial(pItem); + } + } break; + + case mdf_type_social_item: + showContactDialog(pItem, dlg_type_contact_social, "Edit social contacts"); + break; + + default: + int ret = QMessageBox::critical(this, tr("MDF contact edit"), tr("This is not a contact item")); + spdlog::error("MDF contact edit - Not a contact item"); + break; + } } \ No newline at end of file diff --git a/src/cfrmmdf.h b/src/cfrmmdf.h index 279f790a..789a4882 100644 --- a/src/cfrmmdf.h +++ b/src/cfrmmdf.h @@ -37,6 +37,8 @@ #include #include +#include "cdlgmdfcontact.h" + #include #include @@ -196,6 +198,17 @@ public slots: /// Edit MDF manufacturer data void editManufacturerData(void); + /*! + Show contact dialog (alow editing) + @param pItem Pointer to selected item + @param type Type of contact (phone/fax/email/web/social) + @param title Title text on dialog + */ + void showContactDialog(QMdfTreeWidgetItem* pItem, mdf_dlg_contact_type type, QString title); + + /// Edit phone/fax/email/web/social data + void editContact(void); + /*! Fill in data from info map as children to parent item @@ -250,6 +263,54 @@ public slots: void fillRegisterInfo(QTreeWidgetItem* pParent, CMDF_Register* preg); + /*! + Remove all subitems of a head item that have a speciified type. + @param pItem Pointer to head item + @param type Type subitems should have + */ + void + removeSubItems(QMdfTreeWidgetItem* pItem, mdf_record_type type); + + /*! + Render manufacturer email info + @param pItemEmailHead Pointer to header item + */ + + void + renderManufacturerEmail(QMdfTreeWidgetItem *pItemEmailHead); + + /*! + Render manufacturer phone info + @param pItemPhoneHead Pointer to header item + */ + + void + renderManufacturerPhone(QMdfTreeWidgetItem *pItemPhoneHead); + + /*! + Render manufacturer fax info + @param pItemPhoneHead Pointer to fax item + */ + + void + renderManufacturerFax(QMdfTreeWidgetItem *pItemFaxHead); + + /*! + Render manufacturer web info + @param pItemWebHead Pointer to fax item + */ + + void + renderManufacturerWeb(QMdfTreeWidgetItem *pItemWebHead); + + /*! + Render manufacturer social info + @param pItemSocialHead Pointer to fax item + */ + + void + renderManufacturerSocial(QMdfTreeWidgetItem *pItemSocialHead); + /// Do the new operation void newMdf(void); diff --git a/src/cfrmnodeconfig.cpp b/src/cfrmnodeconfig.cpp index 360a59b5..b94b957e 100644 --- a/src/cfrmnodeconfig.cpp +++ b/src/cfrmnodeconfig.cpp @@ -5409,13 +5409,12 @@ CFrmNodeConfig::renderMdfFiles(void) // void -CFrmNodeConfig::fillMdfFileHtmlInfo(QTreeWidgetItem *item, int column) +CFrmNodeConfig::fillMdfFileHtmlInfo(QTreeWidgetItem *widgetItem, int column) { - //int idx; std::string html; - std::string str; - CMdfFileWidgetItem* pitem = (CMdfFileWidgetItem*)item; - if (nullptr != item) { + + CMdfFileWidgetItem* pitem = (CMdfFileWidgetItem*)widgetItem; + if (nullptr != pitem) { spdlog::critical("MDF file item is NULL {0}", pitem->text(0).toStdString()); ui->infoArea->setHtml(tr("MDF file item is NULL")); return; @@ -5435,7 +5434,6 @@ CFrmNodeConfig::fillMdfFileHtmlInfo(QTreeWidgetItem *item, int column) html += ""; html += ""; - str += pitem->text(0).toStdString(); switch (/*pitem->m_mdfFileType*/pitem->type()) { case (QTreeWidgetItem::UserType + static_cast(mdf_file_type_picture)):