#include "download_add_widget.h" #include #include #include #include #include #include #include #include #include #include "marked_class.h" download_add_widget::download_add_widget(std::list &modules_, QWidget *parent) : QWidget(parent), modules(modules_) { QGridLayout *l = new QGridLayout(this); layout_settings = new QGridLayout; //must be created before first entry added to combobox to avoid crash QLabel *lbl_modules = new QLabel(tr("module:")); QComboBox *combo_modules = new QComboBox; connect(combo_modules, SIGNAL(currentIndexChanged(QString)), this, SLOT(combo_modules_currentIndexChanged(QString))); QHBoxLayout *layout_modules = new QHBoxLayout; layout_modules->addWidget(lbl_modules); QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding); layout_modules->addItem(spacer); layout_modules->addWidget(combo_modules); l->addLayout(layout_modules, 0, 0, 1, 3); for(auto m : modules) { if(m.type() == SERVER_MODULE_TYPE::SERVER_MODULE_DOWNLOADER) combo_modules->addItem(m.name().c_str()); } l->addLayout(layout_settings, 1, 0, 1, 3); spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding); l->addItem(spacer, 2, 0, 1, 3); QPushButton *btn_ok = new QPushButton(tr("Ok")), *btn_cancel = new QPushButton(tr("Cancel")); connect(btn_ok, SIGNAL(clicked(bool)), this, SLOT(btn_ok_clicked())); connect(btn_cancel, SIGNAL(clicked(bool)), this, SLOT(btn_cancel_clicked())); QHBoxLayout *layout_buttons = new QHBoxLayout; layout_buttons->addWidget(btn_ok); spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding); layout_buttons->addItem(spacer); layout_buttons->addWidget(btn_cancel); l->addLayout(layout_buttons, 3, 0, 1, 3); setLayout(l); } void download_add_widget::combo_modules_currentIndexChanged(QString module) { for (QLayoutItem *item = layout_settings->takeAt(0); item != 0; item = layout_settings->takeAt(0)) delete item; int row = 0; for(auto m : modules) { if(m.name().c_str() == module) { for(auto ui : m.download_creation_ui()) { if(ui.type() == MODULE_UI_ELEMENT_TYPE::UI_STR || ui.type() == MODULE_UI_ELEMENT_TYPE::UI_INTEGER) { QLabel *l = new QLabel(ui.name().c_str()); layout_settings->addWidget(l, row, 0); QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding); layout_settings->addItem(spacer, row, 1); switch(ui.type()) { case MODULE_UI_ELEMENT_TYPE::UI_STR: { marked_class *edit = new marked_class; edit->set_mark(ui.id()); layout_settings->addWidget(edit, row, 2); } break; case MODULE_UI_ELEMENT_TYPE::UI_INTEGER: { marked_class *edit = new marked_class; edit->set_mark(ui.id()); layout_settings->addWidget(edit, row, 2); } break; default: break; } ++row; } } } } } void download_add_widget::btn_ok_clicked() { } void download_add_widget::btn_cancel_clicked() { close(); deleteLater(); //? }