Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "globals.h"
- #include "window.h"
- #include "tabs.h"
- #include "ITab.h"
- #include <QLabel>
- #include <QHBoxLayout>
- #include <QHBoxLayout>
- #include <QStatusBar>
- #include <QGroupBox>
- #include <QMenuBar>
- #include <QApplication>
- #include <QtWidgets>
- #include <QGridLayout>
- #include <QString>
- #include <QWindow>
- #include <QCoreApplication>
- #include <vector>
- #include "gitpp.h"
- namespace
- {
- class ListConfig : public QWidget, public ITab
- {
- public:
- //Use of Vectors for the layouts used in listing configuations
- std::vector<QPushButton *> editButtons;
- std::vector<QLineEdit *> configInputs;
- std::vector<QGroupBox *> groupBoxes;
- std::vector<QHBoxLayout *> inputLayouts;
- std::vector<QLabel *> listConfigs;
- GITPP::REPO repo;
- QWidget *choiceWindow = new QWidget();
- public:
- ListConfig() : QWidget()
- {
- std::string path = ".";
- GITPP::REPO r(path.c_str());
- gTabs.push_back(this);
- repo = gRepository;
- refresh();
- }
- void refresh() override
- {
- QGroupBox *nameBox = new QGroupBox();
- QFormLayout *boxLayout = new QFormLayout();
- QLabel *listConfigTitle = new QLabel("LIST OF CONFIGURATIONS");
- listConfigTitle->setFont(headingsFont);
- //GITPP::REPO r;
- std::string nameValue;
- size_t count = 0;
- //LISTING THE CONFIGURATIONS
- for (auto i : repo.config())
- {
- nameValue = i.name() + ":" + i.value() + "\n";
- listConfigs.push_back(new QLabel((QString::fromStdString(nameValue))));
- listConfigs[count]->setFont(textFont);
- editButtons.push_back(new QPushButton("Edit"));
- configInputs.push_back(new QLineEdit());
- configInputs[count]->clear();
- groupBoxes.push_back(new QGroupBox());
- inputLayouts.push_back(new QHBoxLayout());
- configInputs[count]->setMinimumWidth(30);
- configInputs[count]->setPlaceholderText("Enter new Value");
- editButtons[count]->minimumSizeHint();
- inputLayouts[count]->addWidget(configInputs[count]);
- inputLayouts[count]->addWidget(editButtons[count]);
- boxLayout->addRow(listConfigs[count], inputLayouts[count]);
- connect(editButtons[count++], &QPushButton::clicked, [=](){ this->choicePage(i.name(),i.value(),configInputs[count]->text(),count); });
- }
- //SETTING THE LAYOUT FOR THE WINDOW
- nameBox->setLayout(boxLayout);
- QVBoxLayout *finalLayout = new QVBoxLayout();
- finalLayout->addWidget(listConfigTitle, 0, 0);
- finalLayout->addWidget(nameBox, 2, 0);
- finalLayout->spacing();
- finalLayout->addStretch();
- setLayout(finalLayout);
- }
- void choicePage(std::string name,std::string value, QString newConfig, int count)
- //Error Message is user enters no value
- {
- if (newConfig.toStdString() == "")
- {
- QWidget *errorWindow = new QWidget();
- QHBoxLayout *errorLayout = new QHBoxLayout();
- QLabel *errorMessage = new QLabel("Please enter a valid value");
- errorMessage->setFont(textFont);
- errorLayout->addWidget(errorMessage);
- errorWindow->setLayout(errorLayout);
- errorWindow->show();
- hWindow->statusBar()->showMessage("Please enter a valid value for "
- +QString::fromStdString(name));
- }
- else
- //Opens a new window to confirm edit
- {
- QFormLayout *choiceButtons=new QFormLayout;
- QGroupBox *choiceBox=new QGroupBox();
- QVBoxLayout *choiceLayout=new QVBoxLayout();
- QLabel *choiceLabel=new QLabel("Configuation:"+QString::fromStdString(name) +"\n"
- "Old Value: " + QString::fromStdString(value) +" \n"+ "New Value: " + newConfig
- + "\nCONFIRM CHANGES?");
- // YES AND NO BUTTONS
- QPushButton *yesChoice=new QPushButton("Yes");
- QPushButton *noChoice=new QPushButton("No");
- choiceButtons->addRow(yesChoice,noChoice);
- choiceBox->setLayout(choiceButtons);
- choiceLayout->addWidget(choiceLabel,0,0);
- choiceLayout->addWidget(choiceBox,1,0);
- choiceLayout->addStretch();
- choiceWindow->setLayout(choiceLayout);
- choiceWindow->show();
- connect(noChoice, &QPushButton::clicked,[=](){ choiceWindow->hide(); });
- connect(yesChoice,&QPushButton::clicked,[=](){ this->editConfig(name,newConfig,count); });
- }
- }
- //
- void editConfig(std::string name, QString newConfig, int count)
- { //Changing the config value in the git repository
- GITPP::REPO r;
- auto c = repo.config();
- c[name] = newConfig.toStdString();
- configInputs[count]->clear();
- std::string NameValue = name + ":" + newConfig.toStdString() + "\n";
- listConfigs[count]->setText(QString::fromStdString(NameValue));
- choiceWindow->hide();
- hWindow->statusBar()->showMessage("Edited "+ QString::fromStdString(name) + " to " + newConfig );
- }
- };
- INSTALL_TAB(ListConfig, "Show/Edit Configurations");
- } // namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement