[TD]fix line standard drop downs

This commit is contained in:
wandererfan
2023-12-05 13:28:06 -05:00
committed by WandererFan
parent fb128a3f4d
commit efd3407dd8
7 changed files with 92 additions and 25 deletions

View File

@@ -55,6 +55,14 @@ using namespace TechDraw;
using DU = DrawUtil;
LineGenerator::LineGenerator()
{
reloadDescriptions();
// m_elementDefs = loadElements();
// m_lineDefs = getLineDefinitions();
// m_lineDescs = getLineDescriptions();
}
void LineGenerator::reloadDescriptions()
{
m_elementDefs = loadElements();
m_lineDefs = getLineDefinitions();

View File

@@ -63,6 +63,10 @@ public:
static std::vector<std::string> getAvailableLineStandards();
static std::string getLineStandardsBody();
//! if the line standard changes during a lineGenerator's life time
//! then the elements and line descriptions need to be reloaded using the
//! new standard.
void reloadDescriptions();
//! get line descriptions from memory
std::vector<std::string> getLoadedDescriptions();
//! get line descriptions from file

View File

@@ -425,6 +425,12 @@ int Preferences::lineStandard()
return getPreferenceGroup("Standards")->GetInt("LineStandard", 1);
}
//! update the line standard preference. used in the preferences dialog.
void Preferences::setLineStandard(int index)
{
getPreferenceGroup("Standards")->SetInt("LineStandard", index);
}
std::string Preferences::lineDefinitionLocation()
{
std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/LineGroup/";

View File

@@ -107,6 +107,7 @@ public:
static bool SectionUsePreviousCut();
static int lineStandard();
static void setLineStandard(int index);
static std::string lineDefinitionLocation();
static std::string lineElementsLocation();

View File

@@ -537,6 +537,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxVisibleItems">
<number>6</number>
</property>
<property name="iconSize">
<size>
<width>32</width>
@@ -574,6 +577,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxVisibleItems">
<number>6</number>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<property name="iconSize">
<size>
<width>32</width>
@@ -608,6 +617,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxVisibleItems">
<number>6</number>
</property>
<property name="iconSize">
<size>
<width>32</width>
@@ -736,6 +748,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxVisibleItems">
<number>6</number>
</property>
<property name="iconSize">
<size>
<width>32</width>

View File

@@ -49,15 +49,29 @@ DlgPrefsTechDrawAnnotationImp::DlgPrefsTechDrawAnnotationImp( QWidget* parent )
ui->pdsbBalloonKink->setUnit(Base::Unit::Length);
ui->pdsbBalloonKink->setMinimum(0);
// stylesheet override to defeat behaviour of non-editable combobox to ignore
// maxVisibleItems property
QString ssOverride = QString::fromUtf8("combobox-popup: 0;");
ui->pcbSectionStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->pcbSectionStyle->setStyleSheet(ssOverride);
ui->pcbCenterStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->pcbCenterStyle->setStyleSheet(ssOverride);
ui->pcbHighlightStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->pcbHighlightStyle->setStyleSheet(ssOverride);
ui->pcbHiddenStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->pcbHiddenStyle->setStyleSheet(ssOverride);
// connect the LineGroup the update the tooltip if index changed
connect(ui->pcbLineGroup, qOverload<int>(&QComboBox::currentIndexChanged),
this, &DlgPrefsTechDrawAnnotationImp::onLineGroupChanged);
m_lineGenerator = new LineGenerator();
}
DlgPrefsTechDrawAnnotationImp::~DlgPrefsTechDrawAnnotationImp()
{
// no need to delete child widgets, Qt does it all for us
delete m_lineGenerator;
}
void DlgPrefsTechDrawAnnotationImp::saveSettings()
@@ -80,8 +94,6 @@ void DlgPrefsTechDrawAnnotationImp::saveSettings()
ui->pcbHighlightStyle->onSave();
ui->cbEndCap->onSave();
ui->pcbHiddenStyle->onSave();
}
void DlgPrefsTechDrawAnnotationImp::loadSettings()
@@ -129,33 +141,16 @@ void DlgPrefsTechDrawAnnotationImp::loadSettings()
if (ui->pcbLineStandard->count() > Preferences::lineStandard()) {
ui->pcbLineStandard->setCurrentIndex(Preferences::lineStandard());
}
// we have to connect the slot after the inital load or the current standard will
// be set to index 0 when the widget is created
connect(ui->pcbLineStandard, qOverload<int>(&QComboBox::currentIndexChanged),
this, &DlgPrefsTechDrawAnnotationImp::onLineStandardChanged);
// note: line numbering starts at 1, not 0. we set the preference to the
// currentIndex in saveSettings, Preferences returns the actual line number,
// so we need to subtract 1 here to get the index.
ui->pcbSectionStyle->onRestore();
DrawGuiUtil::loadLineStyleChoices(ui->pcbSectionStyle, m_lineGenerator);
if (ui->pcbSectionStyle->count() > Preferences::SectionLineStyle()) {
ui->pcbSectionStyle->setCurrentIndex(Preferences::SectionLineStyle() - 1);
}
ui->pcbCenterStyle->onRestore();
DrawGuiUtil::loadLineStyleChoices(ui->pcbCenterStyle, m_lineGenerator);
if (ui->pcbCenterStyle->count() > Preferences::CenterLineStyle()) {
ui->pcbCenterStyle->setCurrentIndex(Preferences::CenterLineStyle() - 1);
}
ui->pcbHighlightStyle->onRestore();
DrawGuiUtil::loadLineStyleChoices(ui->pcbHighlightStyle, m_lineGenerator);
if (ui->pcbHighlightStyle->count() > Preferences::HighlightLineStyle()) {
ui->pcbHighlightStyle->setCurrentIndex(Preferences::HighlightLineStyle() - 1);
}
ui->pcbHiddenStyle->onRestore();
DrawGuiUtil::loadLineStyleChoices(ui->pcbHiddenStyle, m_lineGenerator);
if (ui->pcbHiddenStyle->count() > Preferences::HiddenLineStyle()) {
ui->pcbHiddenStyle->setCurrentIndex(Preferences::HiddenLineStyle() - 1);
}
loadLineStyleBoxes();
}
/**
@@ -195,7 +190,7 @@ void DlgPrefsTechDrawAnnotationImp::onLineGroupChanged(int index)
lgNames.push_back(lgRecord);
}
ui->pcbLineGroup->setToolTip(
QObject::tr("%1 defines these line widths:\n thin: %2\n graphic: %3\n "
QObject::tr("%1 defines these line widths:\n thin: %2\n graphic: %3\n"
"thick: %4")
.arg(QString::fromStdString(lgNames.at(0).substr(1)),
QString::fromStdString(lgNames.at(1)),
@@ -203,4 +198,40 @@ void DlgPrefsTechDrawAnnotationImp::onLineGroupChanged(int index)
QString::fromStdString(lgNames.at(3))));
}
//! we must save the current line group preference when it changes so that the
//! line style comboboxes are filled for the correct standard.
void DlgPrefsTechDrawAnnotationImp::onLineStandardChanged(int index)
{
Preferences::setLineStandard(index);
m_lineGenerator->reloadDescriptions();
loadLineStyleBoxes();
}
//! fill the various line style comboboxes
void DlgPrefsTechDrawAnnotationImp::loadLineStyleBoxes()
{
// note: line numbering starts at 1, not 0. we set the preference to the
// currentIndex in saveSettings, Preferences returns the actual line number,
// so we need to subtract 1 here to get the index.
DrawGuiUtil::loadLineStyleChoices(ui->pcbSectionStyle, m_lineGenerator);
if (ui->pcbSectionStyle->count() > Preferences::SectionLineStyle()) {
ui->pcbSectionStyle->setCurrentIndex(Preferences::SectionLineStyle() - 1);
}
DrawGuiUtil::loadLineStyleChoices(ui->pcbCenterStyle, m_lineGenerator);
if (ui->pcbCenterStyle->count() > Preferences::CenterLineStyle()) {
ui->pcbCenterStyle->setCurrentIndex(Preferences::CenterLineStyle() - 1);
}
DrawGuiUtil::loadLineStyleChoices(ui->pcbHighlightStyle, m_lineGenerator);
if (ui->pcbHighlightStyle->count() > Preferences::HighlightLineStyle()) {
ui->pcbHighlightStyle->setCurrentIndex(Preferences::HighlightLineStyle() - 1);
}
DrawGuiUtil::loadLineStyleChoices(ui->pcbHiddenStyle, m_lineGenerator);
if (ui->pcbHiddenStyle->count() > Preferences::HiddenLineStyle()) {
ui->pcbHiddenStyle->setCurrentIndex(Preferences::HiddenLineStyle() - 1);
}
}
#include <Mod/TechDraw/Gui/moc_DlgPrefsTechDrawAnnotationImp.cpp>

View File

@@ -46,6 +46,7 @@ public:
public Q_SLOTS:
void onLineGroupChanged(int);
void onLineStandardChanged(int);
protected:
void saveSettings() override;
@@ -53,6 +54,7 @@ protected:
void changeEvent(QEvent *e) override;
int prefBalloonArrow() const;
void loadLineStyleBoxes();
private:
std::unique_ptr<Ui_DlgPrefsTechDrawAnnotationImp> ui;