From 17911b8651965379994b50344000d64bf68173c4 Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Thu, 18 Feb 2021 15:21:53 +0300 Subject: [PATCH 1/4] Graphic UI objects names change, Ribbon init() now remember current tab --- CMakeLists.txt | 2 +- libs/application/ribbon.cpp | 8 ++++ libs/graphic/graphic.cpp | 96 ++++++++++++++++++------------------- libs/graphic/graphic.h | 28 +++++------ libs/graphic/graphic.ui | 42 ++++++++-------- 5 files changed, 93 insertions(+), 83 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f2ce01..5b78971 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(qad) set(qad_MAJOR 1) set(qad_MINOR 15) -set(qad_REVISION 0) +set(qad_REVISION 1) set(qad_SUFFIX ) set(qad_COMPANY SHS) set(qad_DOMAIN org.SHS) diff --git a/libs/application/ribbon.cpp b/libs/application/ribbon.cpp index a17ad7d..ea6a474 100644 --- a/libs/application/ribbon.cpp +++ b/libs/application/ribbon.cpp @@ -91,6 +91,12 @@ void Ribbon::init() { if (parent == 0) return; if (parent->menuBar() == 0) return; QList lm = parent->menuBar()->actions(), la; + QString prev_tab; + if (tab) { + if (tab->currentIndex() >= 0) + prev_tab = tab->tabText(tab->currentIndex()); + tab->deleteLater(); + } clear(); if (scroll_area) delete scroll_area; buttons.clear(); @@ -192,6 +198,8 @@ void Ribbon::init() { tl->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed)); //sa->widget()->setLayout(tl); tab->widget(tab->count() - 1)->setLayout(tl); + if (i->text() == prev_tab) + tab->setCurrentIndex(tab->count() - 1); } setFloatable(false); setMovable(false); diff --git a/libs/graphic/graphic.cpp b/libs/graphic/graphic.cpp index ae4cabd..036b13f 100644 --- a/libs/graphic/graphic.cpp +++ b/libs/graphic/graphic.cpp @@ -40,19 +40,19 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), ui = new Ui::Graphic(); ui->setupUi(this); QActionGroup * agroup = new QActionGroup(this); - agroup->addAction(ui->actionGuidesFree ); - agroup->addAction(ui->actionGuidesTraceX); - agroup->addAction(ui->actionGuidesTraceY); - ui->actionGuidesFree ->setProperty("_value", (int)Free ); - ui->actionGuidesTraceX->setProperty("_value", (int)TraceX); - ui->actionGuidesTraceY->setProperty("_value", (int)TraceY); - ui->actionGuidesFree->setChecked(true); + agroup->addAction(ui->graphic_actionGuidesFree ); + agroup->addAction(ui->graphic_actionGuidesTraceX); + agroup->addAction(ui->graphic_actionGuidesTraceY); + ui->graphic_actionGuidesFree ->setProperty("_value", (int)Free ); + ui->graphic_actionGuidesTraceX->setProperty("_value", (int)TraceX); + ui->graphic_actionGuidesTraceY->setProperty("_value", (int)TraceY); + ui->graphic_actionGuidesFree->setChecked(true); connect(agroup, SIGNAL(triggered(QAction*)), this, SLOT(actionGuidesTriggered(QAction*))); - ui->checkGuides->addAction(ui->actionGuidesFree ); - ui->checkGuides->addAction(ui->actionGuidesTraceX); - ui->checkGuides->addAction(ui->actionGuidesTraceY); - ui->buttonAutofit->addAction(ui->actionExpandX); - ui->buttonAutofit->addAction(ui->actionExpandY); + ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesFree ); + ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesTraceX); + ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesTraceY); + ui->graphic_buttonAutofit->addAction(ui->graphic_actionExpandX); + ui->graphic_buttonAutofit->addAction(ui->graphic_actionExpandY); line_x_min.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); line_x_max.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); ((QBoxLayout * )ui->widgetLY->layout())->insertWidget(0, &line_y_min); @@ -540,7 +540,7 @@ void Graphic::clear() { graphics[i].max_x = 0.; graphics[i].cvrect = QRectF(); } - if (isFit) on_buttonAutofit_clicked(); + if (isFit) on_graphic_buttonAutofit_clicked(); } @@ -553,9 +553,9 @@ void Graphic::setAntialiasing(bool enabled) { void Graphic::setPaused(bool yes) { pause_ = yes; - ui->checkPause->blockSignals(true); - ui->checkPause->setChecked(yes); - ui->checkPause->blockSignals(false); + ui->graphic_checkPause->blockSignals(true); + ui->graphic_checkPause->setChecked(yes); + ui->graphic_checkPause->blockSignals(false); for (int i = 0; i < graphics.size(); ++i) graphics[i].cvrect = QRectF(); if (!pause_) { @@ -592,17 +592,17 @@ void Graphic::setHistorySize(double val) { void Graphic::setMaxVisibleTime(double val) { visible_time = val; - if (isFit) on_buttonAutofit_clicked(); + if (isFit) on_graphic_buttonAutofit_clicked(); } void Graphic::setOnlyExpandY(bool yes) { - ui->actionExpandY->setChecked(yes); + ui->graphic_actionExpandY->setChecked(yes); } void Graphic::setOnlyExpandX(bool yes) { - ui->actionExpandX->setChecked(yes); + ui->graphic_actionExpandX->setChecked(yes); } @@ -649,25 +649,25 @@ void Graphic::setGraphicsDataRaw(const QByteArray & ba) { void Graphic::setFloatingAxisEnabled(bool on) { - ui->checkGuides->setChecked(on); + ui->graphic_checkGuides->setChecked(on); } void Graphic::setButtons(Graphic::Buttons b) { buttons_ = b; - ui->buttonAutofit->setVisible(b.testFlag(Autofit)); - ui->checkGrid->setVisible(b.testFlag(Grid)); - ui->checkGuides->setVisible(b.testFlag(CursorAxis)); - ui->buttonFullscreen->setVisible(b.testFlag(Fullscreen)); - ui->checkBorderInputs->setVisible(b.testFlag(BorderInputs)); - ui->checkLegend->setVisible(b.testFlag(Legend)); - ui->buttonClear->setVisible(b.testFlag(Clear)); - ui->buttonConfigure->setVisible(b.testFlag(Configure)); - ui->buttonSave->setVisible(b.testFlag(Save)); - ui->buttonClose->setVisible(b.testFlag(Close)); - ui->checkPause->setVisible(b.testFlag(Pause)); - if (ui->buttonAutofit->isVisible() || ui->checkGrid->isVisible() || ui->checkGuides->isVisible() || - ui->buttonConfigure->isVisible() || ui->buttonSave->isVisible() || ui->checkPause->isVisible()) + ui->graphic_buttonAutofit->setVisible(b.testFlag(Autofit)); + ui->graphic_checkGrid->setVisible(b.testFlag(Grid)); + ui->graphic_checkGuides->setVisible(b.testFlag(CursorAxis)); + ui->graphic_buttonFullscreen->setVisible(b.testFlag(Fullscreen)); + ui->graphic_checkBorderInputs->setVisible(b.testFlag(BorderInputs)); + ui->graphic_checkLegend->setVisible(b.testFlag(Legend)); + ui->graphic_buttonClear->setVisible(b.testFlag(Clear)); + ui->graphic_buttonConfigure->setVisible(b.testFlag(Configure)); + ui->graphic_buttonSave->setVisible(b.testFlag(Save)); + ui->graphic_buttonClose->setVisible(b.testFlag(Close)); + ui->graphic_checkPause->setVisible(b.testFlag(Pause)); + if (ui->graphic_buttonAutofit ->isVisible() || ui->graphic_checkGrid ->isVisible() || ui->graphic_checkGuides->isVisible() || + ui->graphic_buttonConfigure->isVisible() || ui->graphic_buttonSave->isVisible() || ui->graphic_checkPause ->isVisible()) ui->verticalSpacer->changeSize(0, 30, QSizePolicy::Preferred, QSizePolicy::Preferred); else ui->verticalSpacer->changeSize(0, 0, QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -1447,7 +1447,7 @@ void Graphic::tick(int index, bool slide, bool update_) { } -void Graphic::on_buttonAutofit_clicked() { +void Graphic::on_graphic_buttonAutofit_clicked() { isFit = true; bool isEmpty = true; foreach (const GraphicType & t, graphics) { @@ -1464,7 +1464,7 @@ void Graphic::on_buttonAutofit_clicked() { } -void Graphic::on_buttonConfigure_clicked() { +void Graphic::on_graphic_buttonConfigure_clicked() { conf->graphicItems.clear(); for (int i = 0; i < graphics.size(); i++) { GraphicConf::GraphicItem item; @@ -1510,7 +1510,7 @@ void Graphic::on_buttonConfigure_clicked() { } -void Graphic::on_checkGuides_toggled(bool checked) { +void Graphic::on_graphic_checkGuides_toggled(bool checked) { guides = checked; setGuidesCursor(); update(); @@ -1594,8 +1594,8 @@ void Graphic::graphicVisibleChange(bool checked) { QCheckBox * cb = qobject_cast(sender()); int i = cb->property("graphic_num").toInt(); graphics[i].visible = checked; - if (isFit) on_buttonAutofit_clicked(); - else update(); + if (isFit) on_graphic_buttonAutofit_clicked(); + else {update();} emit graphicSettingsChanged(); } @@ -1607,8 +1607,8 @@ void Graphic::graphicAllVisibleChange(bool checked) { graphics[i].pb->setChecked(checked); } visible_update = false; - if (isFit) on_buttonAutofit_clicked(); - else update(); + if (isFit) on_graphic_buttonAutofit_clicked(); + else {update();} emit graphicSettingsChanged(); } @@ -1759,14 +1759,14 @@ void Graphic::setCaption(const QString & str) { void Graphic::setGridEnabled(bool enabled) { - ui->checkGrid->setChecked(enabled); + ui->graphic_checkGrid->setChecked(enabled); } void Graphic::setBorderInputsVisible(bool visible) { ui->widgetLX->setVisible(visible); ui->widgetLY->setVisible(visible); - ui->checkBorderInputs->setChecked(visible); + ui->graphic_checkBorderInputs->setChecked(visible); if (visible) setRectToLines(); } @@ -1778,24 +1778,24 @@ void Graphic::setStatusVisible(bool visible) { void Graphic::setLegendVisible(bool visible) { ui->widgetLegend->setVisible(visible); - ui->checkLegend->setChecked(visible); + ui->graphic_checkLegend->setChecked(visible); updateLegend(); } -void Graphic::on_actionExpandX_triggered(bool checked) { +void Graphic::on_graphic_actionExpandX_triggered(bool checked) { only_expand_x = checked; - ui->actionExpandX->setIcon(checked ? icon_exp_x : icon_exp_sx); + ui->graphic_actionExpandX->setIcon(checked ? icon_exp_x : icon_exp_sx); } -void Graphic::on_actionExpandY_triggered(bool checked) { +void Graphic::on_graphic_actionExpandY_triggered(bool checked) { only_expand_y = checked; - ui->actionExpandY->setIcon(checked ? icon_exp_y : icon_exp_sy); + ui->graphic_actionExpandY->setIcon(checked ? icon_exp_y : icon_exp_sy); } void Graphic::actionGuidesTriggered(QAction * a) { - ui->checkGuides->setChecked(true); + ui->graphic_checkGuides->setChecked(true); setFloatingAxisType((FloatingAxisType)a->property("_value").toInt()); } diff --git a/libs/graphic/graphic.h b/libs/graphic/graphic.h index 5aca02f..7277244 100644 --- a/libs/graphic/graphic.h +++ b/libs/graphic/graphic.h @@ -313,7 +313,7 @@ public slots: void addGraphic(const GraphicType & gd, bool update = true) {graphics << gd; if (update) updateLegend();} void setVisualRect(const QRectF & rect); void setDefaultRect(const QRectF & rect); - void autofit() {on_buttonAutofit_clicked();} + void autofit() {on_graphic_buttonAutofit_clicked();} void saveImage(); void clear(); void update(bool force = false); @@ -416,19 +416,19 @@ protected slots: void lineXMaxChanged(double value) {selrect.setRight(value); checkLines();} void lineYMinChanged(double value) {selrect.setBottom(value); checkLines();} void lineYMaxChanged(double value) {selrect.setTop(value); checkLines();} - void on_buttonClose_clicked() {emit closeRequest(this);} - void on_buttonClear_clicked() {clear(); emit cleared();} - void on_buttonAutofit_clicked(); - void on_buttonConfigure_clicked(); - void on_buttonFullscreen_clicked() {fullscreen();} - void on_buttonSave_clicked() {saveImage();} - void on_checkGrid_toggled(bool checked) {grid = checked; update();} - void on_checkGuides_toggled(bool checked); - void on_actionExpandX_triggered(bool checked); - void on_actionExpandY_triggered(bool checked); - void on_checkBorderInputs_toggled(bool checked) {setBorderInputsVisible(checked);} - void on_checkLegend_toggled(bool checked) {setLegendVisible(checked);} - void on_checkPause_toggled(bool checked) {setPaused(checked);} + void on_graphic_buttonClose_clicked() {emit closeRequest(this);} + void on_graphic_buttonClear_clicked() {clear(); emit cleared();} + void on_graphic_buttonAutofit_clicked(); + void on_graphic_buttonConfigure_clicked(); + void on_graphic_buttonFullscreen_clicked() {fullscreen();} + void on_graphic_buttonSave_clicked() {saveImage();} + void on_graphic_checkGrid_toggled(bool checked) {grid = checked; update();} + void on_graphic_checkGuides_toggled(bool checked); + void on_graphic_actionExpandX_triggered(bool checked); + void on_graphic_actionExpandY_triggered(bool checked); + void on_graphic_checkBorderInputs_toggled(bool checked) {setBorderInputsVisible(checked);} + void on_graphic_checkLegend_toggled(bool checked) {setLegendVisible(checked);} + void on_graphic_checkPause_toggled(bool checked) {setPaused(checked);} void actionGuidesTriggered(QAction * a); void enterFullscreen(); void leaveFullscreen(); diff --git a/libs/graphic/graphic.ui b/libs/graphic/graphic.ui index 096f8a0..2de6978 100644 --- a/libs/graphic/graphic.ui +++ b/libs/graphic/graphic.ui @@ -48,7 +48,7 @@ 2 - + Autofit @@ -59,7 +59,7 @@ - + Grid @@ -76,7 +76,7 @@ - + Cursor axis @@ -90,7 +90,7 @@ - + Fullscreen @@ -101,7 +101,7 @@ - + Border inputs @@ -118,7 +118,7 @@ - + Legend @@ -135,7 +135,7 @@ - + Pause @@ -149,23 +149,23 @@ - + Configure ... - + :/icons/configure.png:/icons/configure.png - + Save image ... - + :/icons/document-save.png:/icons/document-save.png @@ -187,23 +187,23 @@ - + Clear - + :/icons/edit-clear.png:/icons/edit-clear.png - + Close - + :/icons/dialog-close.png:/icons/dialog-close.png @@ -397,7 +397,7 @@ - + true @@ -405,7 +405,7 @@ Free - + true @@ -413,7 +413,7 @@ Trace X - + true @@ -421,7 +421,7 @@ Trace Y - + true @@ -429,7 +429,7 @@ Only expand X - + true @@ -449,6 +449,8 @@ + + From 365568cad74fb94058031f485c847efc5444bd74 Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Thu, 18 Feb 2021 15:46:57 +0300 Subject: [PATCH 2/4] version 1.16.0 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b78971..f85853d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(qad) set(qad_MAJOR 1) -set(qad_MINOR 15) -set(qad_REVISION 1) +set(qad_MINOR 16) +set(qad_REVISION 0) set(qad_SUFFIX ) set(qad_COMPANY SHS) set(qad_DOMAIN org.SHS) From 45781dfc3e00e68fc3263cc81115e66099ff67ef Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Mon, 22 Feb 2021 11:27:40 +0300 Subject: [PATCH 3/4] SessionManager fix - obtain all mainwindow QSplitters in "addEntry" --- CMakeLists.txt | 2 +- libs/sql_table/sql_record_widget.cpp | 4 +- libs/widgets/session_manager.cpp | 15 +++++-- libs/widgets/session_manager.h | 67 ++++++++++++++-------------- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f85853d..7edd012 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(qad) set(qad_MAJOR 1) -set(qad_MINOR 16) +set(qad_MINOR 17) set(qad_REVISION 0) set(qad_SUFFIX ) set(qad_COMPANY SHS) diff --git a/libs/sql_table/sql_record_widget.cpp b/libs/sql_table/sql_record_widget.cpp index eac9bdc..e367aeb 100644 --- a/libs/sql_table/sql_record_widget.cpp +++ b/libs/sql_table/sql_record_widget.cpp @@ -322,8 +322,10 @@ bool SQLRecordWidget::isEmpty() const { void SQLRecordWidget::updateRelations() { relations.clear(); + QSqlDatabase db(QSqlDatabase::database(connection_name)); + if (!db.isOpen()) return; for (int i = 0; i < relations_src.size(); ++i) { - QSqlQuery q(QString("SELECT %1,%2 FROM %3").arg(relations_src[i].key, relations_src[i].ocol, relations_src[i].table), QSqlDatabase::database(connection_name)); + QSqlQuery q(QString("SELECT %1,%2 FROM %3").arg(relations_src[i].key, relations_src[i].ocol, relations_src[i].table), db); QList > cr; while (q.next()) cr << QPair(q.value(0).toInt(), q.value(1).toString()); diff --git a/libs/widgets/session_manager.cpp b/libs/widgets/session_manager.cpp index e05d830..0774eea 100644 --- a/libs/widgets/session_manager.cpp +++ b/libs/widgets/session_manager.cpp @@ -42,6 +42,12 @@ void SessionManager::removeMainWidget(QWidget * e) { } +void SessionManager::addEntry(const QString & name, QMainWindow * e) { + mwindows.push_back(QPair(name, e)); + mw_splitters[e] = e->findChildren(); +} + + void SessionManager::save() { if (file_.isEmpty()) { qDebug() << "[SessionManager] filename is empty"; @@ -54,8 +60,8 @@ void SessionManager::save() { sr.setValue(mwindows[i].first + " state", mwindows[i].second->saveState(), false); sr.setValue(mwindows[i].first + " window state", (int)mwindows[i].second->windowState(), false); sr.setValue(mwindows[i].first + " geometry " + QString::number((int)mwindows[i].second->windowState()), mwindows[i].second->saveGeometry(), false); - QList sp = mwindows[i].second->findChildren(); - foreach (QSplitter * s, sp) + QList spl = mw_splitters[mwindows[i].second]; + foreach (QSplitter * s, spl) sr.setValue(mwindows[i].first + " splitter " + s->objectName(), s->saveState(), false); } for (int i = 0; i < widgets.size(); ++i) { @@ -165,8 +171,8 @@ void SessionManager::load(bool onlyMainwindow) { QByteArray ba = sr.getValue(mwindows[i].first + " state").toByteArray(); if (!ba.isEmpty()) mw->restoreState(ba); - QList sp = mw->findChildren(); - foreach (QSplitter * s, sp) { + QList spl = mw_splitters[mw]; + foreach (QSplitter * s, spl) { ba = sr.getValue(mwindows[i].first + " splitter " + s->objectName()).toByteArray(); if (!ba.isEmpty()) s->restoreState(ba); @@ -261,6 +267,7 @@ void SessionManager::clear(bool with_filename) { bools.clear(); ints.clear(); floats.clear(); + mw_splitters.clear(); if (with_filename) setFile(""); } diff --git a/libs/widgets/session_manager.h b/libs/widgets/session_manager.h index b3c84fa..4d55e11 100644 --- a/libs/widgets/session_manager.h +++ b/libs/widgets/session_manager.h @@ -52,42 +52,42 @@ public: void setFile(const QString & file); - void addEntry(QMainWindow * e) {mwindows.push_back(QPair(e->objectName(), e));} - void addEntry(QCheckBox * e) {checks.push_back(QPair(e->objectName(), e));} - void addEntry(QLineEdit * e) {lines.push_back(QPair(e->objectName(), e));} - void addEntry(QComboBox * e) {combos.push_back(QPair(e->objectName(), e));} - void addEntry(QDoubleSpinBox * e) {dspins.push_back(QPair(e->objectName(), e));} - void addEntry(QSpinBox * e) {spins.push_back(QPair(e->objectName(), e));} - void addEntry(SpinSlider * e) {spinsliders.push_back(QPair(e->objectName(), e));} - void addEntry(EvalSpinBox * e) {evals.push_back(QPair(e->objectName(), e));} - void addEntry(QTabWidget * e) {tabs.push_back(QPair(e->objectName(), e));} - void addEntry(QGroupBox * e) {groups.push_back(QPair(e->objectName(), e));} - void addEntry(QAction * e) {actions.push_back(QPair(e->objectName(), e));} - void addEntry(QAbstractButton * e) {buttons.push_back(QPair(e->objectName(), e));} - void addEntry(QStackedWidget * e) {stacks.push_back(QPair(e->objectName(), e));} - void addMainWidget(QWidget * e) {widgets.push_back(QPair(e->objectName(), e));} + void addEntry(QMainWindow * e) {addEntry(e->objectName(), e);} + void addEntry(QCheckBox * e) {addEntry(e->objectName(), e);} + void addEntry(QLineEdit * e) {addEntry(e->objectName(), e);} + void addEntry(QComboBox * e) {addEntry(e->objectName(), e);} + void addEntry(QDoubleSpinBox * e) {addEntry(e->objectName(), e);} + void addEntry(QSpinBox * e) {addEntry(e->objectName(), e);} + void addEntry(SpinSlider * e) {addEntry(e->objectName(), e);} + void addEntry(EvalSpinBox * e) {addEntry(e->objectName(), e);} + void addEntry(QTabWidget * e) {addEntry(e->objectName(), e);} + void addEntry(QGroupBox * e) {addEntry(e->objectName(), e);} + void addEntry(QAction * e) {addEntry(e->objectName(), e);} + void addEntry(QAbstractButton * e) {addEntry(e->objectName(), e);} + void addEntry(QStackedWidget * e) {addEntry(e->objectName(), e);} + void addMainWidget(QWidget * e) {addMainWidget(e->objectName(), e);} void removeMainWidget(QWidget * e); - void addEntry(const QString & name, QMainWindow * e) {mwindows.push_back(QPair(name, e));} - void addEntry(const QString & name, QCheckBox * e) {checks.push_back(QPair(name, e));} - void addEntry(const QString & name, QLineEdit * e) {lines.push_back(QPair(name, e));} - void addEntry(const QString & name, QComboBox * e) {combos.push_back(QPair(name, e));} - void addEntry(const QString & name, QDoubleSpinBox * e) {dspins.push_back(QPair(name, e));} - void addEntry(const QString & name, QSpinBox * e) {spins.push_back(QPair(name, e));} - void addEntry(const QString & name, SpinSlider * e) {spinsliders.push_back(QPair(name, e));} - void addEntry(const QString & name, EvalSpinBox * e) {evals.push_back(QPair(name, e));} - void addEntry(const QString & name, QTabWidget * e) {tabs.push_back(QPair(name, e));} - void addEntry(const QString & name, QGroupBox * e) {groups.push_back(QPair(name, e));} + void addEntry(const QString & name, QMainWindow * e); + void addEntry(const QString & name, QCheckBox * e) {checks.push_back(QPair(name, e));} + void addEntry(const QString & name, QLineEdit * e) {lines.push_back(QPair(name, e));} + void addEntry(const QString & name, QComboBox * e) {combos.push_back(QPair(name, e));} + void addEntry(const QString & name, QDoubleSpinBox * e) {dspins.push_back(QPair(name, e));} + void addEntry(const QString & name, QSpinBox * e) {spins.push_back(QPair(name, e));} + void addEntry(const QString & name, SpinSlider * e) {spinsliders.push_back(QPair(name, e));} + void addEntry(const QString & name, EvalSpinBox * e) {evals.push_back(QPair(name, e));} + void addEntry(const QString & name, QTabWidget * e) {tabs.push_back(QPair(name, e));} + void addEntry(const QString & name, QGroupBox * e) {groups.push_back(QPair(name, e));} void addEntry(const QString & name, QAbstractButton * e) {buttons.push_back(QPair(name, e));} - void addEntry(const QString & name, QStackedWidget * e) {stacks.push_back(QPair(name, e));} - void addEntry(const QString & name, QAction * e) {actions.push_back(QPair(name, e));} - void addEntry(const QString & name, QStringList * e) {stringlists.push_back(QPair(name, e));} - void addEntry(const QString & name, QString * e) {strings.push_back(QPair(name, e));} - void addEntry(const QString & name, QColor * e) {colors.push_back(QPair(name, e));} - void addEntry(const QString & name, bool * e) {bools.push_back(QPair(name, e));} - void addEntry(const QString & name, int * e) {ints.push_back(QPair(name, e));} - void addEntry(const QString & name, float * e) {floats.push_back(QPair(name, e));} - void addMainWidget(const QString & name, QWidget * e) {widgets.push_back(QPair(name, e));} + void addEntry(const QString & name, QStackedWidget * e) {stacks.push_back(QPair(name, e));} + void addEntry(const QString & name, QAction * e) {actions.push_back(QPair(name, e));} + void addEntry(const QString & name, QStringList * e) {stringlists.push_back(QPair(name, e));} + void addEntry(const QString & name, QString * e) {strings.push_back(QPair(name, e));} + void addEntry(const QString & name, QColor * e) {colors.push_back(QPair(name, e));} + void addEntry(const QString & name, bool * e) {bools.push_back(QPair(name, e));} + void addEntry(const QString & name, int * e) {ints.push_back(QPair(name, e));} + void addEntry(const QString & name, float * e) {floats.push_back(QPair(name, e));} + void addMainWidget(const QString & name, QWidget * e) {widgets.push_back(QPair(name, e));} private: QMap metaFunctions(const QSet & objects, QByteArray fname); @@ -112,6 +112,7 @@ private: QVector > bools; QVector > ints; QVector > floats; + QMap > mw_splitters; QString file_; public slots: From 27811246174d49e772f4da3cc27826c4aef5429b Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Wed, 24 Feb 2021 17:15:12 +0300 Subject: [PATCH 4/4] Graphic legend improvements using scroll area --- CMakeLists.txt | 2 +- libs/graphic/graphic.cpp | 52 ++++++++++++++++++++++---- libs/graphic/graphic.ui | 80 +++++++++++++++++++++++----------------- 3 files changed, 92 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7edd012..298ac56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(qad) set(qad_MAJOR 1) set(qad_MINOR 17) -set(qad_REVISION 0) +set(qad_REVISION 1) set(qad_SUFFIX ) set(qad_COMPANY SHS) set(qad_DOMAIN org.SHS) diff --git a/libs/graphic/graphic.cpp b/libs/graphic/graphic.cpp index 036b13f..8470f91 100644 --- a/libs/graphic/graphic.cpp +++ b/libs/graphic/graphic.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) # include #endif @@ -25,6 +27,28 @@ const double rad2deg_qpie = 45. / atan(1.); __GraphicRegistrator__ __graphic_registrator__; +class LegendScrollArea: public QScrollArea { +public: + LegendScrollArea(QWidget * w): QScrollArea() { + setFrameShape(QFrame::NoFrame); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + setWidgetResizable(true); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); + setWidget(w); + viewport()->setAutoFillBackground(false); + w->setAutoFillBackground(false); + } +protected: + virtual QSize sizeHint() const { + QSize ret; + if (!widget()) return ret; + ret = widget()->sizeHint(); + return ret; + } +}; + Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), line_x_max(this), line_y_min(this), line_y_max(this) { canvas_gl = 0; @@ -39,6 +63,8 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), #endif ui = new Ui::Graphic(); ui->setupUi(this); + ui->scrollLegend->layout()->addWidget(new LegendScrollArea(ui->widgetLegend)); + ui->scrollLegend->hide(); QActionGroup * agroup = new QActionGroup(this); agroup->addAction(ui->graphic_actionGuidesFree ); agroup->addAction(ui->graphic_actionGuidesTraceX); @@ -143,7 +169,12 @@ void Graphic::changeEvent(QEvent * e) { void Graphic::resizeEvent(QResizeEvent *) { - if (leg_update) updateLegend(false); + if (leg_update) +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + QTimer::singleShot(0, this, [this](){updateLegend(false);}); +#else + updateLegend(false); +#endif } @@ -1530,7 +1561,7 @@ void Graphic::updateLegend(bool es) { p.end(); graphics[i].icon = QIcon(pix); } - if (!ui->widgetLegend->isVisibleTo(this)) { + if (!ui->scrollLegend->isVisibleTo(this)) { if (es) emit graphicSettingsChanged(); return; } @@ -1564,15 +1595,18 @@ void Graphic::updateLegend(bool es) { } int maxcol = qMax(ui->widgetLegend->width() / ps - 1, 1); int row = 0, col = 0; - bool lv = ui->widgetLegend->isVisibleTo(this); - ui->widgetLegend->hide(); + bool lv = ui->scrollLegend->isVisibleTo(this); + ui->scrollLegend->hide(); for (int i = 0; i < graphics.size(); i++) { ui->layoutLegend->addWidget(graphics[i].pb,row,col); graphics[i].pb->show(); col++; if (col > maxcol) {col = 0; row++;} } - ui->widgetLegend->setVisible(lv); + ui->gridLayout->invalidate(); + ui->scrollLegend->setVisible(lv); + ui->scrollLegend->layout()->itemAt(0)->widget()->updateGeometry(); + //ui->gridLayout->invalidate(); leg_update = true; if (es) emit graphicSettingsChanged(); } @@ -1672,7 +1706,7 @@ bool Graphic::statusVisible() const { bool Graphic::legendVisible() const { - return ui->widgetLegend->isVisible(); + return ui->scrollLegend->isVisible(); } @@ -1777,9 +1811,13 @@ void Graphic::setStatusVisible(bool visible) { void Graphic::setLegendVisible(bool visible) { - ui->widgetLegend->setVisible(visible); + ui->scrollLegend->setVisible(visible); ui->graphic_checkLegend->setChecked(visible); +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + QTimer::singleShot(0, this, [this](){updateLegend();}); +#else updateLegend(); +#endif } diff --git a/libs/graphic/graphic.ui b/libs/graphic/graphic.ui index 2de6978..0d00a0f 100644 --- a/libs/graphic/graphic.ui +++ b/libs/graphic/graphic.ui @@ -7,7 +7,7 @@ 0 0 564 - 433 + 484 @@ -32,6 +32,16 @@ 2 + + + + Qt::RichText + + + Qt::AlignCenter + + + @@ -216,7 +226,7 @@ 0 - 79 + 0 @@ -225,19 +235,16 @@ - - - - Qt::RichText - - - Qt::AlignCenter - - - + + + + Cursor: ( ; ) + + + @@ -359,39 +366,44 @@ + + + + + 1 + + + 1 + + + 1 + + + 1 + + + 4 + + + + - - - - Cursor: ( ; ) - - - - - - - 0 - 0 - - - + + - 1 + 0 - 1 + 0 - 1 + 0 - 1 - - - 4 + 0