Files
qt5-legatus-legacy/Lts/Plugins/PlanEditor/lookup_symbol_dlg.cpp
T
2026-08-13 18:33:10 +02:00

316 lines
9.9 KiB
C++
Executable File

/**
**
** @RDE_HEADER@
** lookup_symbol_dlg.cpp
** $Id$
** $HeadURL$
** $Author$
**
** -----------------------------------------------------------------------------------------------
**
** Hardware-Environment: Intel-PC
** Software-Environment: Windows 7, Qt 5.4. ArcGIS 10.2.5
**
** Language ........: C++ 11
**
** -----------------------------------------------------------------------------------------------
**
** Author ...........: Jörg Turla, SPD G, Tel. 3132
**
** -----------------------------------------------------------------------------------------------
**
** Notes .........:
**
** 14.06.2016, JT : First edition for use with Qt5
**
** -----------------------------------------------------------------------------------------------
*/
#include "lookup_symbol_dlg.h"
#include "icon_names.h"
#include "lookup_symbol_manager.h"
#include "plan_editor_utils.h"
#include "plan_editor.h"
#include "plan_editor_internal.h"
#include <SymbologyImpl/symbol_dictionary_impl.h>
#include <SymbologyGui/base_symbol_lookup_widget.h>
#include <LtsWidgets/lts_combo_box.h>
#include <LtsWidgets/lts_message_dialog.h>
#include <QtGui/QDrag>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QTableView>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QHeaderView>
namespace PlanEditor
{
using ComboBox = LtsWidgets::LtsComboBox;
class DragTableView : public QTableView
{
Q_OBJECT
public:
explicit DragTableView(QWidget *parent = nullptr) : QTableView(parent)
{}
~DragTableView() = default;
protected:
void startDrag(Qt::DropActions)
{
const QModelIndexList &indexes = this->selectedIndexes();
QMimeData *data = this->model()->mimeData(indexes);
if (data)
{
QDrag *drag = new QDrag(this);
QPixmap dragIcon(data->imageData().value<QPixmap>());
drag->setPixmap(dragIcon);
drag->setMimeData(data);
drag->setHotSpot(QPoint(dragIcon.width() / 2, dragIcon.height() / 2));
drag->exec(Qt::DropAction::CopyAction);
}
} // void startDrag( Qt::DropActions )
}; // DragTableView
class LookupSymbolDlg::InternalData
{
public:
QString m_widgetId;
PlanEditor *m_planEditor;
QPointer<LookupSymbolManager> m_lookupSymMgr;
QPointer<AdvancedSymbology::Gui::BaseSymbolLookupWidget> m_baseSymbolLookupWidget;
QPushButton *m_pbAdd2Map;
QPushButton *m_pbAdd2Favourites;
ComboBox *m_cbSymbolScopes;
QString m_title;
static QHash<QString, QString> m_valueStoreMap;
InternalData(PlanEditor *planEditor, const QString &widgetId)
: m_widgetId(widgetId)
, m_planEditor(planEditor)
, m_cbSymbolScopes(nullptr)
, m_title()
{
if (m_widgetId.isEmpty())
m_widgetId = QStringLiteral("PlanEditor_LookupSymbolDlg");
}
~InternalData()
{
m_valueStoreMap[m_widgetId] = m_cbSymbolScopes->currentText();
}
void setStoredValues()
{
m_cbSymbolScopes->setCurrentText(m_valueStoreMap[m_widgetId]);
}
};
// LookupSymbolDlg::InternalData
QHash<QString, QString> LookupSymbolDlg::InternalData::m_valueStoreMap;
LookupSymbolDlg::LookupSymbolDlg(LookupSymbolManager *lookupSymMgr
, PlanEditor *planEditor
, const QString &widgetId
, const QPointer<AdvancedSymbology::Gui::BaseSymbolLookupWidget> &baseSymbolLookupWidget)
: LtsWidgets::LtsDialog(nullptr), m_internal(new InternalData(planEditor, widgetId))
{
m_internal->m_lookupSymMgr = lookupSymMgr;
m_internal->m_title = tr("Symbol Lookup");
setUnchangeable();
m_internal->m_cbSymbolScopes = new ComboBox(this);
m_internal->m_cbSymbolScopes->setEditable(true);
connect(m_internal->m_cbSymbolScopes, &ComboBox::currentTextChanged, this, &LookupSymbolDlg::enaDisa);
m_internal->m_pbAdd2Map = new QPushButton(Utils::getIcon(QLatin1String(SYMBOL_ADD_TO_MAP_ICON)), tr("Add to Map"), this);
m_internal->m_pbAdd2Favourites = new QPushButton(Utils::getIcon(QLatin1String(SYMBOL_ADD_TO_FAVOURITES_ICON)), tr("Add to Favourites"), this);
connect(m_internal->m_pbAdd2Map, &QPushButton::clicked, this, &LookupSymbolDlg::onAddSymbolToMap);
connect(m_internal->m_pbAdd2Favourites, &QPushButton::clicked, this, &LookupSymbolDlg::onAddSymbolToFavourites);
m_internal->m_pbAdd2Map->setToolTip(tr("Create rubberband to add symbol to map"));
m_internal->m_pbAdd2Favourites->setToolTip(tr("Add symbol to favourite scope"));
m_internal->m_baseSymbolLookupWidget = baseSymbolLookupWidget;
if (!m_internal->m_baseSymbolLookupWidget)
{
AdvancedSymbology::SymbolDictionaryImpl &sdi = static_cast<AdvancedSymbology::SymbolDictionaryImpl &>(m_internal->m_lookupSymMgr->symbolDictionary());
AdvancedSymbology::BaseSymbolModel *bsmEsri = sdi.getBaseSymbolModelEsri();
AdvancedSymbology::BaseSymbolModel *bsmXml = sdi.getBaseSymbolModelXML();
AdvancedSymbology::BaseSymbolModel *bsmEts = sdi.getBaseSymbolModelEts();
AdvancedSymbology::Gui::MODEL_CONT modelCont;
modelCont.append(AdvancedSymbology::Gui::ModelItem(AdvancedSymbology::Gui::SYMBOL_TYPE::ESRI, QLatin1String("Esri"), bsmEsri));
modelCont.append(AdvancedSymbology::Gui::ModelItem(AdvancedSymbology::Gui::SYMBOL_TYPE::XML, QLatin1String("User-defined Symbols"), bsmXml));
modelCont.append(AdvancedSymbology::Gui::ModelItem(AdvancedSymbology::Gui::SYMBOL_TYPE::ETS, QLatin1String("Ets"), bsmEts));
m_internal->m_baseSymbolLookupWidget = new AdvancedSymbology::Gui::BaseSymbolLookupWidget(modelCont, this);
}
else
m_internal->m_baseSymbolLookupWidget->setParent(this); // re-parent
connect(m_internal->m_baseSymbolLookupWidget.data(), &AdvancedSymbology::Gui::BaseSymbolLookupWidget::symbolClicked,
this, &LookupSymbolDlg::enaDisa, Qt::UniqueConnection);
connect(m_internal->m_baseSymbolLookupWidget.data(), &AdvancedSymbology::Gui::BaseSymbolLookupWidget::symbolDoubleClicked,
this, &LookupSymbolDlg::symbolDoubleClicked, Qt::UniqueConnection);
QVBoxLayout *layout = new QVBoxLayout(this);
QHBoxLayout *layoutCtrl = new QHBoxLayout();
layout->addWidget(m_internal->m_baseSymbolLookupWidget, 2);
layout->addSpacing(5);
layout->addLayout(layoutCtrl, 0);
layoutCtrl->addSpacing(5);
layoutCtrl->addWidget(new QLabel(tr("Symbol Scope"), this), 0);
layoutCtrl->addSpacing(5);
layoutCtrl->addWidget(m_internal->m_cbSymbolScopes);
layoutCtrl->addSpacing(5);
layoutCtrl->addWidget(m_internal->m_pbAdd2Favourites, 0);
layoutCtrl->addSpacing(5);
layoutCtrl->addStretch(2);
layoutCtrl->addSpacing(5);
layoutCtrl->addWidget(m_internal->m_pbAdd2Map, 0);
layoutCtrl->addSpacing(5);
enaDisa();
}
QPointer<AdvancedSymbology::Gui::BaseSymbolLookupWidget> LookupSymbolDlg::detachAndTakeBaseSymbolLookupWidget()
{
if (!m_internal->m_baseSymbolLookupWidget)
return nullptr;
m_internal->m_baseSymbolLookupWidget->disconnect(this);
m_internal->m_baseSymbolLookupWidget->setParent(nullptr);
return m_internal->m_baseSymbolLookupWidget;
}
void LookupSymbolDlg::setParticipantMode(bool onOff)
{
if (!m_internal->m_baseSymbolLookupWidget)
return;
m_internal->m_baseSymbolLookupWidget->setParticipantMode(onOff);
}
void LookupSymbolDlg::setValidBaseSymbolCodes(const QSet<QString> &validBaseSymbolCodes)
{
if (!m_internal->m_baseSymbolLookupWidget)
return;
m_internal->m_baseSymbolLookupWidget->setValidBaseSymbolCodes(validBaseSymbolCodes);
}
void LookupSymbolDlg::enaDisa()
{
const QString &curSidc = getCurrentSidc();
const QString &curSymbolScope = m_internal->m_cbSymbolScopes->currentText();
// enable ComboBox if sidc and text:
m_internal->m_pbAdd2Favourites->setEnabled(!curSidc.isEmpty() && !curSymbolScope.isEmpty());
// enable add2Map if sidc:
m_internal->m_pbAdd2Map->setEnabled(!curSidc.isEmpty());
}
void LookupSymbolDlg::retranslate()
{
// lupdate doesn't like translate(tr("foo")) ...
translate(m_internal->m_title);
}
LookupSymbolDlg::~LookupSymbolDlg()
{
emit beginDestroy(); // this is the moment to call 'detachAndTakeBaseSymbolLookupWidget'
delete m_internal;
m_internal = nullptr;
}
void LookupSymbolDlg::setTitle(const QString &title)
{
m_internal->m_title = title;
retranslate();
}
void LookupSymbolDlg::onAddSymbolToMap()
{
const QString &sidc = getCurrentSidc();
if (!sidc.isEmpty())
m_internal->m_planEditor->onSymbolCreateRubberband(sidc, m_internal->m_baseSymbolLookupWidget->participantMode());
}
void LookupSymbolDlg::onAddSymbolToFavourites()
{
const QString &sidc = getCurrentSidc();
const QString &symbolScope = m_internal->m_cbSymbolScopes->currentText();
if (sidc.isEmpty()) return;
if (symbolScope.isEmpty())
{
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Select symbol scope name from list or type a new name to scope edit field"));
return;
}
emit addToSymbolFavourites(symbolScope, sidc);
}
void LookupSymbolDlg::onUpdateSymbolScopes(const QStringList &scopeList)
{
QString currentText = m_internal->m_cbSymbolScopes->currentText();
QStringList sortedScopeList = scopeList;
sortedScopeList.sort();
m_internal->m_cbSymbolScopes->clear();
m_internal->m_cbSymbolScopes->addItems(scopeList);
int currentIdx = m_internal->m_cbSymbolScopes->findText(currentText);
m_internal->m_cbSymbolScopes->setCurrentIndex(currentIdx);
if (currentIdx < 0)
m_internal->m_cbSymbolScopes->clearEditText();
}
QString LookupSymbolDlg::getCurrentSidc() const
{
return m_internal->m_baseSymbolLookupWidget->getCurrentSidc(); // getCurrentSidc->encodedCompleteSidc
}
} // namespace PlanEditor
#include "lookup_symbol_dlg.moc"