File indexing completed on 2025-01-05 03:35:40
0001 /* 0002 File : GoToDialog.cpp 0003 Project : LabPlot 0004 Description : Dialog to provide the cell coordinates to navigate to 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2020 Alexander Semke <alexander.semke@web.de> 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "GoToDialog.h" 0011 #include "backend/core/Settings.h" 0012 #include "backend/core/column/Column.h" 0013 #include "backend/lib/macros.h" 0014 #include "backend/spreadsheet/Spreadsheet.h" 0015 0016 #include <QDialogButtonBox> 0017 #include <QGridLayout> 0018 #include <QIntValidator> 0019 #include <QLabel> 0020 #include <QLineEdit> 0021 #include <QPushButton> 0022 #include <QWindow> 0023 0024 #include <KLocalizedString> 0025 #include <KWindowConfig> 0026 0027 /*! 0028 \class GoToDialog 0029 \brief Dialog to provide the cell coordinates to navigate to 0030 0031 \ingroup kdefrontend 0032 */ 0033 GoToDialog::GoToDialog(QWidget* parent) 0034 : QDialog(parent) { 0035 setWindowTitle(i18nc("@title:window", "Go to Cell")); 0036 0037 auto* layout = new QGridLayout(this); 0038 0039 // row 0040 auto* label = new QLabel(i18n("Row:")); 0041 layout->addWidget(label, 0, 0); 0042 0043 leRow = new QLineEdit(this); 0044 leRow->setValidator(new QIntValidator(leRow)); 0045 leRow->setText(QStringLiteral("1")); 0046 layout->addWidget(leRow, 0, 1); 0047 0048 // column 0049 label = new QLabel(i18n("Column:")); 0050 layout->addWidget(label, 1, 0); 0051 0052 leColumn = new QLineEdit(this); 0053 leColumn->setValidator(new QIntValidator(leColumn)); 0054 leColumn->setText(QStringLiteral("1")); 0055 layout->addWidget(leColumn, 1, 1); 0056 0057 auto* btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0058 connect(btnBox, &QDialogButtonBox::accepted, this, &GoToDialog::accept); 0059 connect(btnBox, &QDialogButtonBox::rejected, this, &GoToDialog::reject); 0060 layout->addWidget(btnBox, 2, 1); 0061 0062 // restore saved settings if available 0063 KConfigGroup conf = Settings::group(QLatin1String("GoToDialog")); 0064 0065 create(); // ensure there's a window created 0066 if (conf.exists()) { 0067 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0068 resize(windowHandle()->size()); // workaround for QTBUG-40584 0069 } else 0070 resize(QSize(200, 0).expandedTo(minimumSize())); 0071 } 0072 0073 GoToDialog::~GoToDialog() { 0074 // save the current settings 0075 KConfigGroup conf = Settings::group(QLatin1String("GoToDialog")); 0076 KWindowConfig::saveWindowSize(windowHandle(), conf); 0077 } 0078 0079 int GoToDialog::row() { 0080 bool ok; 0081 int row = QLocale().toInt(leRow->text(), &ok); 0082 0083 return ok ? row : 0; 0084 } 0085 0086 int GoToDialog::column() { 0087 bool ok; 0088 int col = QLocale().toInt(leColumn->text(), &ok); 0089 return ok ? col : 0; 0090 }