Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. #include "globals.h"
  2. #include "window.h"
  3. #include "tabs.h"
  4. #include "ITab.h"
  5. #include <QLabel>
  6. #include <QHBoxLayout>
  7. #include <QHBoxLayout>
  8. #include <QStatusBar>
  9. #include <QGroupBox>
  10. #include <QMenuBar>
  11. #include <QApplication>
  12. #include <QtWidgets>
  13. #include <QGridLayout>
  14. #include <QString>
  15. #include <QWindow>
  16. #include <QCoreApplication>
  17. #include <vector>
  18. #include "gitpp.h"
  19.  
  20. namespace
  21. {
  22. class ListConfig : public QWidget, public ITab
  23. {
  24. public:
  25. //Use of Vectors for the layouts used in listing configuations
  26. std::vector<QPushButton *> editButtons;
  27. std::vector<QLineEdit *> configInputs;
  28. std::vector<QGroupBox *> groupBoxes;
  29. std::vector<QHBoxLayout *> inputLayouts;
  30. std::vector<QLabel *> listConfigs;
  31. GITPP::REPO repo;
  32. QWidget *choiceWindow = new QWidget();
  33.  
  34. public:
  35. ListConfig() : QWidget()
  36. {
  37. std::string path = ".";
  38. GITPP::REPO r(path.c_str());
  39. gTabs.push_back(this);
  40. repo = gRepository;
  41. refresh();
  42.  
  43. }
  44.  
  45. void refresh() override
  46. {
  47. QGroupBox *nameBox = new QGroupBox();
  48. QFormLayout *boxLayout = new QFormLayout();
  49. QLabel *listConfigTitle = new QLabel("LIST OF CONFIGURATIONS");
  50. listConfigTitle->setFont(headingsFont);
  51. //GITPP::REPO r;
  52. std::string nameValue;
  53. size_t count = 0;
  54. //LISTING THE CONFIGURATIONS
  55. for (auto i : repo.config())
  56. {
  57. nameValue = i.name() + ":" + i.value() + "\n";
  58. listConfigs.push_back(new QLabel((QString::fromStdString(nameValue))));
  59. listConfigs[count]->setFont(textFont);
  60. editButtons.push_back(new QPushButton("Edit"));
  61. configInputs.push_back(new QLineEdit());
  62. configInputs[count]->clear();
  63. groupBoxes.push_back(new QGroupBox());
  64. inputLayouts.push_back(new QHBoxLayout());
  65. configInputs[count]->setMinimumWidth(30);
  66. configInputs[count]->setPlaceholderText("Enter new Value");
  67. editButtons[count]->minimumSizeHint();
  68. inputLayouts[count]->addWidget(configInputs[count]);
  69. inputLayouts[count]->addWidget(editButtons[count]);
  70. boxLayout->addRow(listConfigs[count], inputLayouts[count]);
  71. connect(editButtons[count++], &QPushButton::clicked, [=](){ this->choicePage(i.name(),i.value(),configInputs[count]->text(),count); });
  72. }
  73.  
  74. //SETTING THE LAYOUT FOR THE WINDOW
  75. nameBox->setLayout(boxLayout);
  76. QVBoxLayout *finalLayout = new QVBoxLayout();
  77. finalLayout->addWidget(listConfigTitle, 0, 0);
  78. finalLayout->addWidget(nameBox, 2, 0);
  79. finalLayout->spacing();
  80. finalLayout->addStretch();
  81. setLayout(finalLayout);
  82.  
  83. }
  84. void choicePage(std::string name,std::string value, QString newConfig, int count)
  85. //Error Message is user enters no value
  86. {
  87.  
  88. if (newConfig.toStdString() == "")
  89. {
  90. QWidget *errorWindow = new QWidget();
  91. QHBoxLayout *errorLayout = new QHBoxLayout();
  92. QLabel *errorMessage = new QLabel("Please enter a valid value");
  93. errorMessage->setFont(textFont);
  94. errorLayout->addWidget(errorMessage);
  95. errorWindow->setLayout(errorLayout);
  96. errorWindow->show();
  97. hWindow->statusBar()->showMessage("Please enter a valid value for "
  98. +QString::fromStdString(name));
  99. }
  100. else
  101. //Opens a new window to confirm edit
  102. {
  103. QFormLayout *choiceButtons=new QFormLayout;
  104. QGroupBox *choiceBox=new QGroupBox();
  105. QVBoxLayout *choiceLayout=new QVBoxLayout();
  106. QLabel *choiceLabel=new QLabel("Configuation:"+QString::fromStdString(name) +"\n"
  107. "Old Value: " + QString::fromStdString(value) +" \n"+ "New Value: " + newConfig
  108. + "\nCONFIRM CHANGES?");
  109.  
  110. // YES AND NO BUTTONS
  111. QPushButton *yesChoice=new QPushButton("Yes");
  112. QPushButton *noChoice=new QPushButton("No");
  113. choiceButtons->addRow(yesChoice,noChoice);
  114. choiceBox->setLayout(choiceButtons);
  115. choiceLayout->addWidget(choiceLabel,0,0);
  116. choiceLayout->addWidget(choiceBox,1,0);
  117. choiceLayout->addStretch();
  118. choiceWindow->setLayout(choiceLayout);
  119. choiceWindow->show();
  120. connect(noChoice, &QPushButton::clicked,[=](){ choiceWindow->hide(); });
  121. connect(yesChoice,&QPushButton::clicked,[=](){ this->editConfig(name,newConfig,count); });
  122. }
  123. }
  124.  
  125. //
  126.  
  127. void editConfig(std::string name, QString newConfig, int count)
  128. { //Changing the config value in the git repository
  129. GITPP::REPO r;
  130. auto c = repo.config();
  131. c[name] = newConfig.toStdString();
  132. configInputs[count]->clear();
  133. std::string NameValue = name + ":" + newConfig.toStdString() + "\n";
  134. listConfigs[count]->setText(QString::fromStdString(NameValue));
  135. choiceWindow->hide();
  136. hWindow->statusBar()->showMessage("Edited "+ QString::fromStdString(name) + " to " + newConfig );
  137. }
  138. };
  139.  
  140.  
  141. INSTALL_TAB(ListConfig, "Show/Edit Configurations");
  142. } // namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement