| 66 | |
| 67 | |
| 68 | NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString & url, QWidget *parent) |
| 69 | : QDialog(parent), ui(new Ui::NewInstanceDialog) |
| 70 | { |
| 71 | ui->setupUi(this); |
| 72 | |
| 73 | setWindowIcon(APPLICATION->getThemedIcon("new")); |
| 74 | |
| 75 | InstIconKey = "default"; |
| 76 | ui->iconButton->setIcon(APPLICATION->icons()->getIcon(InstIconKey)); |
| 77 | |
| 78 | #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) |
| 79 | auto groupList = APPLICATION->instances()->getGroups(); |
| 80 | auto groups = QSet<QString>(groupList.begin(), groupList.end()); |
| 81 | groupList = groups.values(); |
| 82 | #else |
| 83 | auto groups = APPLICATION->instances()->getGroups().toSet(); |
| 84 | auto groupList = QStringList(groups.toList()); |
| 85 | #endif |
| 86 | groupList.sort(Qt::CaseInsensitive); |
| 87 | groupList.removeOne(""); |
| 88 | groupList.push_front(initialGroup); |
| 89 | groupList.push_front(""); |
| 90 | ui->groupBox->addItems(groupList); |
| 91 | int index = groupList.indexOf(initialGroup); |
| 92 | if(index == -1) |
| 93 | { |
| 94 | index = 0; |
| 95 | } |
| 96 | ui->groupBox->setCurrentIndex(index); |
| 97 | ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); |
| 98 | |
| 99 | |
| 100 | // NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not move this below. |
| 101 | m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
| 102 | |
| 103 | m_container = new PageContainer(this); |
| 104 | m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding); |
| 105 | m_container->layout()->setContentsMargins(0, 0, 0, 0); |
| 106 | ui->verticalLayout->insertWidget(2, m_container); |
| 107 | |
| 108 | m_container->addButtons(m_buttons); |
| 109 | |
| 110 | // Bonk Qt over its stupid head and make sure it understands which button is the default one... |
| 111 | // See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button |
| 112 | auto OkButton = m_buttons->button(QDialogButtonBox::Ok); |
| 113 | OkButton->setDefault(true); |
| 114 | OkButton->setAutoDefault(true); |
| 115 | connect(OkButton, &QPushButton::clicked, this, &NewInstanceDialog::accept); |
| 116 | |
| 117 | auto CancelButton = m_buttons->button(QDialogButtonBox::Cancel); |
| 118 | CancelButton->setDefault(false); |
| 119 | CancelButton->setAutoDefault(false); |
| 120 | connect(CancelButton, &QPushButton::clicked, this, &NewInstanceDialog::reject); |
| 121 | |
| 122 | auto HelpButton = m_buttons->button(QDialogButtonBox::Help); |
| 123 | HelpButton->setDefault(false); |
| 124 | HelpButton->setAutoDefault(false); |
| 125 | connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help); |
nothing calls this directly
no test coverage detected