/** ** ** @RDE_HEADER@ ** Dialog to define some meta data of a plan. ** $Id$ ** $HeadURL$ ** $Author$ ** ** ----------------------------------------------------------------------------------------------- ** ** Hardware-Environment: Intel-PC ** Software-Environment: Windows 7, Qt 5.4. ArcGIS 100 ** ** Language ........: C++ 11 ** ** ----------------------------------------------------------------------------------------------- ** ** Author ...........: Jörg Turla, SPD G, Tel. 3132 ** ** ----------------------------------------------------------------------------------------------- ** ** Notes .........: ** ** 24.02.2017, JT : First edition for use with Qt5 ** ** ----------------------------------------------------------------------------------------------- */ #include "metadata_dialog.h" #include "plan_editor.h" #include #include #include #include #include #include #include #include namespace PlanEditor { class MetaDataDialog::Internal { public: PlanEditor *m_planEditor; SituationMap::GeometryModel *m_geometryModel; SituationMap::Map *m_map; QLineEdit *m_leTitle; QLineEdit *m_leAuthor; QTextEdit *m_teDescription; QLineEdit *m_leMinScale; QLineEdit *m_leMaxScale; QPushButton *m_pbMinScale; QPushButton *m_pbMaxScale; explicit Internal(PlanEditor *planEditor, SituationMap::GeometryModel *geometryModel, SituationMap::Map *map) : m_planEditor(planEditor) , m_geometryModel(geometryModel) , m_map(map) , m_leTitle(nullptr) , m_leAuthor(nullptr) , m_teDescription(nullptr) , m_leMinScale(nullptr) , m_leMaxScale(nullptr) , m_pbMinScale(nullptr) , m_pbMaxScale(nullptr) {;} ~Internal() = default; }; // MetaDataDialog::Internal class ScaleValidator : public QDoubleValidator { Q_OBJECT public: explicit ScaleValidator(QLineEdit *leMinScale, QLineEdit *leMaxScale, QWidget *parent) : QDoubleValidator(0, std::numeric_limits::max(), 1, parent), m_leMinScale(leMinScale), m_leMaxScale(leMaxScale) { if (leMinScale) m_orgStyleSheet = leMinScale->styleSheet(); } QValidator::State validate(QString &input, int &pos) const override { QValidator::State state = QDoubleValidator::validate(input, pos); if (QValidator::State::Acceptable == state) { if (!m_leMinScale->text().isEmpty() && !m_leMaxScale->text().isEmpty()) { bool minOk; bool maxOk; double min = m_leMinScale->text().toDouble(&minOk); double max = m_leMaxScale->text().toDouble(&maxOk); if (!minOk || !maxOk || (min <= max)) state = QValidator::State::Invalid; } } if (m_leMinScale->text().isEmpty() || m_leMaxScale->text().isEmpty()) { m_leMinScale->setStyleSheet(m_orgStyleSheet); m_leMaxScale->setStyleSheet(m_orgStyleSheet); } else { switch(state) { case QValidator::State::Invalid: m_leMinScale->setStyleSheet(QLatin1String("QLineEdit { background-color: red;}")); m_leMaxScale->setStyleSheet(QLatin1String("QLineEdit { background-color: red;}")); break; case QValidator::State::Intermediate: m_leMinScale->setStyleSheet(QLatin1String("QLineEdit { background-color: orange;}")); m_leMaxScale->setStyleSheet(QLatin1String("QLineEdit { background-color: orange;}")); break; case QValidator::State::Acceptable: m_leMinScale->setStyleSheet(m_orgStyleSheet); m_leMaxScale->setStyleSheet(m_orgStyleSheet); break; } // switch } return state; } // QValidator::State validate(QString & input, int & pos) const override private: QLineEdit *m_leMinScale; QLineEdit *m_leMaxScale; QString m_orgStyleSheet; }; // ScaleValidator MetaDataDialog::MetaDataDialog(PlanEditor *planEditor , SituationMap::GeometryModel *geometryModel , SituationMap::Map *map , QWidget *parent) : LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkCancel) , m_internal(new Internal(planEditor, geometryModel, map)) { setObjectName(QLatin1String("PlanEditor::MetaData")); setOnlineHelpFilename(QStringLiteral("Plan_Editor-File_Management")); QGridLayout *layout = new QGridLayout(this); layout->addWidget(new QLabel(tr("Title:"), this), 0, 0, 1, 1, Qt::AlignLeft); layout->addWidget(new QLabel(tr("Author:"), this), 1, 0, 1, 1, Qt::AlignLeft); layout->addWidget(new QLabel(tr("Date:"), this), 1, 3, 1, 1, Qt::AlignRight); layout->addWidget(new QLabel(tr("Description:"), this), 2, 0, 1, 3, Qt::AlignLeft); layout->addWidget(new QLabel(tr("Min. Scale 1:"), this), 4, 0, 1, 1, Qt::AlignLeft); layout->addWidget(new QLabel(tr("Max. Scale 1:"), this), 4, 6, 1, 1, Qt::AlignRight); m_internal->m_leTitle = new QLineEdit(this); m_internal->m_leAuthor = new QLineEdit(this); m_internal->m_teDescription = new QTextEdit(this); m_internal->m_leMinScale = new QLineEdit(this); m_internal->m_leMaxScale = new QLineEdit(this); m_internal->m_pbMinScale = new QPushButton(tr("From Map"), this); m_internal->m_pbMaxScale = new QPushButton(tr("From Map"), this); QPushButton *pbMinScaleTo = new QPushButton(tr("Scale Map to"), this); QPushButton *pbMaxScaleTo = new QPushButton(tr("Scale Map to"), this); QHBoxLayout *layoutTitle = new QHBoxLayout(); QHBoxLayout *layoutAuthor = new QHBoxLayout(); QHBoxLayout *layoutDescription = new QHBoxLayout(); QHBoxLayout *layoutMinScale = new QHBoxLayout(); QHBoxLayout *layoutMaxScale = new QHBoxLayout(); layoutTitle -> addWidget(m_internal->m_leTitle, 2); layoutAuthor -> addWidget(m_internal->m_leAuthor, 2); layoutDescription -> addWidget(m_internal->m_teDescription, 2); layoutMinScale -> addWidget(m_internal->m_leMinScale, 2); layoutMaxScale -> addWidget(m_internal->m_leMaxScale, 2); layout->addLayout(layoutTitle, 0, 1, 1, 9, Qt::AlignJustify); layout->addLayout(layoutAuthor, 1, 1, 1, 9, Qt::AlignJustify); layout->addLayout(layoutDescription, 3, 0, 1, 10, Qt::AlignJustify); layout->addLayout(layoutMinScale, 4, 1, 1, 1, Qt::AlignJustify); layout->addWidget(m_internal->m_pbMinScale, 4, 2, 1, 1, Qt::AlignCenter); layout->addWidget(pbMinScaleTo, 4, 3, 1, 1, Qt::AlignCenter); layout->addLayout(layoutMaxScale, 4, 7, 1, 1, Qt::AlignJustify); layout->addWidget(m_internal->m_pbMaxScale, 4, 8, 1, 1, Qt::AlignCenter); layout->addWidget(pbMaxScaleTo, 4, 9, 1, 1, Qt::AlignCenter); layout->setColumnStretch(1, 2); layout->setColumnStretch(5, 2); layout->setRowStretch(3, 2); ScaleValidator *validator = new ScaleValidator(m_internal->m_leMinScale, m_internal->m_leMaxScale, this); m_internal->m_leMinScale->setValidator(validator); m_internal->m_leMaxScale->setValidator(validator); connect(m_internal->m_pbMinScale, &QPushButton::clicked, this, &MetaDataDialog::onGetMinScaleFromMap); connect(m_internal->m_pbMaxScale, &QPushButton::clicked, this, &MetaDataDialog::onGetMaxScaleFromMap); pbMinScaleTo->setObjectName(QStringLiteral("MinScaleTo")); pbMaxScaleTo->setObjectName(QStringLiteral("MaxScaleTo")); connect(pbMinScaleTo, &QPushButton::clicked, this, &MetaDataDialog::onScaleTo); connect(pbMaxScaleTo, &QPushButton::clicked, this, &MetaDataDialog::onScaleTo); const QString &title = m_internal->m_geometryModel->getModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataTitle).toString(); const QString &author = m_internal->m_geometryModel->getModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataAuthor).toString(); const QString &description = m_internal->m_geometryModel->getModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataDesciption).toString(); const QString &minScale = m_internal->m_geometryModel->getModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataMinScale).toString(); const QString &maxScale = m_internal->m_geometryModel->getModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataMaxScale).toString(); m_internal->m_leTitle->setText(title); m_internal->m_leAuthor->setText(author); m_internal->m_teDescription->setText(description); m_internal->m_leMinScale->setText(minScale); m_internal->m_leMaxScale->setText(maxScale); } // MetaDataDialog::MetaDataDialog MetaDataDialog::~MetaDataDialog() { delete m_internal; m_internal = nullptr; } // MetaDataDialog::~MetaDataDialog void MetaDataDialog::retranslate() { // FIXME: UI Retranslation does not work with the entire Plan Editor, as there are no UIs ... //translate(m_ui, tr("??")); // lupdate doesn't like translate(tr("foo")) ... const QString txt(tr("Edit Plan Meta Data")); translate(txt); } void MetaDataDialog::onGetMinScaleFromMap(bool) { double scale = m_internal->m_map->scale(); m_internal->m_leMinScale->setText(QString::number(scale)); } // void MetaDataDialog::onGetMinScaleFromMap( bool ) void MetaDataDialog::onGetMaxScaleFromMap(bool) { double scale = m_internal->m_map->scale(); m_internal->m_leMaxScale->setText(QString::number(scale)); } // void MetaDataDialog::onGetMaxScaleFromMap( bool ) void MetaDataDialog::onScaleTo(bool) { const QString &objName = QObject::sender()->objectName(); QString scaleText; if (QStringLiteral("MinScaleTo") == objName) scaleText = m_internal->m_leMinScale->text(); if (QStringLiteral("MaxScaleTo") == objName) scaleText = m_internal->m_leMaxScale->text(); if (scaleText.isEmpty()) return; bool ok = false; double scale = scaleText.toDouble(&ok); if (ok) m_internal->m_map->setScale(scale); } // void MetaDataDialog::onScaleTo( bool ) bool MetaDataDialog::apply() { const QString &title = m_internal->m_leTitle->text(); const QString &author = m_internal->m_leAuthor->text(); const QString &description = m_internal->m_teDescription->toPlainText(); const QString &minScale = m_internal->m_leMinScale->text(); const QString &maxScale = m_internal->m_leMaxScale->text(); m_internal->m_geometryModel->startUndoBlock(); { m_internal->m_geometryModel->setModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataTitle, title); m_internal->m_geometryModel->setModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataAuthor, author); m_internal->m_geometryModel->setModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataDesciption, description); m_internal->m_geometryModel->setModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataMinScale, minScale.isEmpty() ? QVariant() : minScale); m_internal->m_geometryModel->setModelAttribute(SituationMap::GeometryModel::Attribute::MetaDataMaxScale, maxScale.isEmpty() ? QVariant() : maxScale); } m_internal->m_geometryModel->endUndoBlock(tr("Plan Meta Data changed")); return true; } // bool MetaDataDialog::apply() } // namespace PlanEditor #include "metadata_dialog.moc"