Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 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 <QLayoutItem>
  7. #include <QHBoxLayout>
  8. #include <QHBoxLayout>
  9. #include <QStatusBar>
  10. #include <QGroupBox>
  11. #include <QMenuBar>
  12. #include <QApplication>
  13. #include <QtWidgets>
  14. #include <QGridLayout>
  15. #include <QString>
  16. #include <QWindow>
  17. #include <QCoreApplication>
  18. #include <vector>
  19. #include "gitpp.h"
  20. #include<QLayoutItem>
  21. #include <QLayout>
  22. namespace
  23. {
  24. class ListConfig : public QWidget, public ITab
  25. {
  26. private:
  27. //Use of Vectors for the layouts used in listing configuations
  28. std::vector<QPushButton *> editButtons;
  29. std::vector<QLineEdit *> configInputs;
  30. std::vector<QGroupBox *> groupBoxes;
  31. std::vector<QHBoxLayout *> inputLayouts;
  32. std::vector<QLabel *> listConfigs;
  33. QWidget *choiceWindow = new QWidget();
  34. QGroupBox *nameBox = new QGroupBox();
  35. QFormLayout *boxLayout = new QFormLayout();
  36. QLabel *listConfigTitle = new QLabel("LIST OF CONFIGURATIONS");
  37. QVBoxLayout *finalLayout = new QVBoxLayout();
  38. size_t count = 0;
  39.  
  40.  
  41. public:
  42. ListConfig() : QWidget()
  43. {
  44. //count=0;
  45. gTabs.push_back(this);
  46. // configList();
  47. listConfigTitle->setFont(headingsFont);
  48. // GITPP::REPO r;
  49. // configList();
  50. listConfigTitle->setFont(headingsFont);
  51. // GITPP::REPO r;
  52. std::string nameValue;
  53. //LISTING THE CONFIGURATIONS
  54. for (auto i : gRepository->config())
  55. {
  56. nameValue = i.name() + ":" + i.value() + "\n";
  57. listConfigs.push_back(new QLabel((QString::fromStdString(nameValue))));
  58. listConfigs[count]->setFont(textFont);
  59. editButtons.push_back(new QPushButton("Edit"));
  60. configInputs.push_back(new QLineEdit());
  61. configInputs[count]->clear();
  62. groupBoxes.push_back(new QGroupBox());
  63. inputLayouts.push_back(new QHBoxLayout());
  64. configInputs[count]->setMinimumWidth(30);
  65. configInputs[count]->setPlaceholderText("Enter new Value");
  66. editButtons[count]->minimumSizeHint();
  67. inputLayouts[count]->addWidget(configInputs[count]);
  68. inputLayouts[count]->addWidget(editButtons[count]);
  69. boxLayout->addRow(listConfigs[count], inputLayouts[count]);
  70. connect(editButtons[count++], &QPushButton::clicked, [=](){ this->choicePage(i.name(),i.value(),configInputs[count]->text(),count); });
  71. }
  72. nameBox->setLayout(boxLayout);
  73. finalLayout->addWidget(listConfigTitle, 0, 0);
  74. finalLayout->addWidget(nameBox, 2, 0);
  75. finalLayout->spacing();
  76. finalLayout->addStretch();
  77. setLayout(finalLayout);
  78. //LISTING THE CONFIGURATIONS
  79. }
  80.  
  81. public:
  82.  
  83. void refresh() override
  84. {
  85. deleteLayouts();
  86.  
  87. }
  88. public:
  89. void deleteLayouts()
  90. {
  91. // count=0;
  92. // editButtons.clear();
  93. // configInputs.clear();
  94. delete finalLayout;
  95. delete boxLayout;
  96. delete nameBox;
  97. finalLayout = new QVBoxLayout();
  98.  
  99. // Create the layout for the group
  100. boxLayout = new QFormLayout();
  101.  
  102. // Creating the group box
  103. nameBox = new QGroupBox();
  104.  
  105. // configList();
  106. std::string nameValue;
  107. //LISTING THE CONFIGURATIONS
  108. for (auto i : gRepository->config())
  109. {
  110.  
  111. //configInputs[count]->clear();
  112. nameValue = i.name() + ":" + i.value() + "\n";
  113. listConfigs.push_back(new QLabel((QString::fromStdString(nameValue))));
  114. listConfigs[count]->setFont(textFont);
  115. editButtons.push_back(new QPushButton("Edit"));
  116. configInputs.push_back(new QLineEdit());
  117. configInputs[count]->clear();
  118. groupBoxes.push_back(new QGroupBox());
  119. inputLayouts.push_back(new QHBoxLayout());
  120. configInputs[count]->setMinimumWidth(30);
  121. configInputs[count]->setPlaceholderText("Enter new Value");
  122. editButtons[count]->minimumSizeHint();
  123. inputLayouts[count]->addWidget(configInputs[count]);
  124. inputLayouts[count]->addWidget(editButtons[count]);
  125. boxLayout->addRow(listConfigs[count], inputLayouts[count]);
  126. connect(editButtons[count++], &QPushButton::clicked, [=](){ this->choicePage(i.name(),i.value(),configInputs[count]->text(),count); });
  127. }
  128. nameBox->setLayout(boxLayout);
  129. finalLayout->addWidget(listConfigTitle, 0, 0);
  130. finalLayout->addWidget(nameBox, 2, 0);
  131. finalLayout->spacing();
  132. finalLayout->addStretch();
  133. setLayout(finalLayout);
  134.  
  135. }
  136.  
  137.  
  138.  
  139. void choicePage(std::string name,std::string value, QString newConfig, int count)
  140. //Error Message is user enters no value
  141. {
  142.  
  143. if (newConfig.toStdString() == "")
  144. {
  145. QWidget *errorWindow = new QWidget();
  146. QHBoxLayout *errorLayout = new QHBoxLayout();
  147. QLabel *errorMessage = new QLabel("Please enter a valid value");
  148. errorMessage->setFont(textFont);
  149. errorLayout->addWidget(errorMessage);
  150. errorWindow->setLayout(errorLayout);
  151. errorWindow->show();
  152. hWindow->statusBar()->showMessage("Please enter a valid value for "
  153. +QString::fromStdString(name));
  154. }
  155. else
  156. //Opens a new window to confirm edit
  157. {
  158. QFormLayout *choiceButtons=new QFormLayout;
  159. QGroupBox *choiceBox=new QGroupBox();
  160. QVBoxLayout *choiceLayout=new QVBoxLayout();
  161. QLabel *choiceLabel=new QLabel("Configuation:"+QString::fromStdString(name) +"\n"
  162. "Old Value: " + QString::fromStdString(value) +" \n"+ "New Value: " + newConfig
  163. + "\nCONFIRM CHANGES?");
  164.  
  165. // YES AND NO BUTTONS
  166. QPushButton *yesChoice=new QPushButton("Yes");
  167. QPushButton *noChoice=new QPushButton("No");
  168. choiceButtons->addRow(yesChoice,noChoice);
  169. choiceBox->setLayout(choiceButtons);
  170. choiceLayout->addWidget(choiceLabel,0,0);
  171. choiceLayout->addWidget(choiceBox,1,0);
  172. choiceLayout->addStretch();
  173. choiceWindow->setLayout(choiceLayout);
  174. choiceWindow->show();
  175. connect(noChoice, &QPushButton::clicked,[=](){ choiceWindow->hide(); });
  176. connect(yesChoice,&QPushButton::clicked,[=](){ this->editConfig(name,newConfig,count); });
  177. }
  178. }
  179.  
  180. //
  181.  
  182. void editConfig(std::string name, QString newConfig, int count)
  183. { //Changing the config value in the git repository
  184. auto c= gRepository->config();
  185. c[name] = newConfig.toStdString();
  186. configInputs[count]->clear();
  187. std::string NameValue = name + ":" + newConfig.toStdString() + "\n";
  188. listConfigs[count]->setText(QString::fromStdString(NameValue));
  189. choiceWindow->hide();
  190. hWindow->statusBar()->showMessage("Edited "+ QString::fromStdString(name) + " to " + newConfig );
  191. }
  192. };
  193.  
  194.  
  195. INSTALL_TAB(ListConfig, "Show/Edit Configurations");
  196. } // namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement