Mantid
Loading...
Searching...
No Matches
PeriodicTableWidget.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <QVector>
9
14PeriodicTableWidget::PeriodicTableWidget(QWidget *parent) : QWidget(parent) {
15 ui.setupUi(this);
20 ui.Groups->setVisible(false);
21}
22
23// slot for showing group legend dependant on state of radioButton
25 if (checked) {
26 ui.Groups->setVisible(true);
27 } else {
28 ui.Groups->setVisible(false);
29 }
30}
31
44}
45void PeriodicTableWidget::ColourActinides(const QVector<QPushButton *> &actinides) {
46 QString buttonColourStr = "background-color: rgb(255, 85, 127, 255)";
47 for (auto actinide : actinides) {
48 ColourButton(actinide, buttonColourStr);
49 update();
50 }
51}
52void PeriodicTableWidget::ColourAlkaliMetals(const QVector<QPushButton *> &alkaliMetals) {
53 QString buttonColourStr = "background-color: rgb(255, 255, 0, 255)";
54 for (auto alkaliMetal : alkaliMetals) {
55 ColourButton(alkaliMetal, buttonColourStr);
56 update();
57 }
58}
59void PeriodicTableWidget::ColourAlkalineEarthMetals(const QVector<QPushButton *> &alkalineEarthMetals) {
60 QString buttonColourStr = "background-color: rgb(170, 170, 127, 255)";
61 for (auto alkalineEarthMetal : alkalineEarthMetals) {
62 ColourButton(alkalineEarthMetal, buttonColourStr);
63 update();
64 }
65}
66void PeriodicTableWidget::ColourHalogens(const QVector<QPushButton *> &halogens) {
67 QString buttonColourStr = "background-color: rgb(0, 255, 255, 255)";
68 for (auto halogen : halogens) {
69 ColourButton(halogen, buttonColourStr);
70 update();
71 }
72}
73void PeriodicTableWidget::ColourLanthanides(const QVector<QPushButton *> &lanthanides) {
74 QString buttonColourStr = "background-color: rgb(170, 85, 255, 255)";
75 for (auto lanthanide : lanthanides) {
76 ColourButton(lanthanide, buttonColourStr);
77 update();
78 }
79}
80void PeriodicTableWidget::ColourMetalloids(const QVector<QPushButton *> &metalloids) {
81 QString buttonColourStr = "background-color: rgb(255, 170, 255, 255)";
82 for (auto metalloid : metalloids) {
83 ColourButton(metalloid, buttonColourStr);
84 update();
85 }
86}
87void PeriodicTableWidget::ColourNobleGases(const QVector<QPushButton *> &nobleGases) {
88 QString buttonColourStr = "background-color: rgb(255, 170, 0, 255)";
89 for (auto nobleGas : nobleGases) {
90 ColourButton(nobleGas, buttonColourStr);
91 update();
92 }
93}
94void PeriodicTableWidget::ColourNonMetals(const QVector<QPushButton *> &nonMetals) {
95 QString buttonColourStr = "background-color: rgb(0, 170, 255, 255)";
96 for (auto nonMetal : nonMetals) {
97 ColourButton(nonMetal, buttonColourStr);
98 update();
99 }
100}
101void PeriodicTableWidget::ColourPostTransitionMetals(const QVector<QPushButton *> &postTransMetals) {
102 QString buttonColourStr = "background-color: rgb(116, 116, 116, 255)";
103 for (auto postTransMetal : postTransMetals) {
104 ColourButton(postTransMetal, buttonColourStr);
105 update();
106 }
107}
108void PeriodicTableWidget::ColourTransitionMetals(const QVector<QPushButton *> &transMetals) {
109 QString buttonColourStr = "background-color: rgb(0, 255, 127, 255)";
110 for (auto transMetal : transMetals) {
111 ColourButton(transMetal, buttonColourStr);
112 update();
113 }
114}
115void PeriodicTableWidget::ColourUnknownProperties(const QVector<QPushButton *> &UnknownProperties) {
116 QString buttonColourStr = "background-color: rgb(255, 0, 0, 255)";
117 for (auto unknownProperty : UnknownProperties) {
118 ColourButton(unknownProperty, buttonColourStr);
119 update();
120 }
121}
122
123void PeriodicTableWidget::enableButtonByName(const QString &elementStr) {
124 for (auto &AllElementButton : AllElementButtons) {
125 for (auto btn_i = AllElementButton.begin(); btn_i != AllElementButton.end(); btn_i++) {
126 if (compareButtonNameToStr((*btn_i), elementStr)) {
127 (*btn_i)->setDisabled(false);
128 }
129 }
130 }
131}
132
133bool PeriodicTableWidget::compareButtonNameToStr(QPushButton *buttonToCompare, const QString &stringToCompare) {
134 return (strcmp(buttonToCompare->text().toStdString().c_str(), stringToCompare.toStdString().c_str()) == 0);
135}
136
149}
150void PeriodicTableWidget::ColourButton(QPushButton *element, const QString &colourStr) {
151 element->setStyleSheet("QPushButton{border:1px solid rgb(0, 0, 0); " + colourStr + ";}" +
152 "QPushButton:checked{ background-color:rgb(175,255,255)}" +
153 "QPushButton:!enabled{background-color: rgb(204,204,204);" + "}");
154}
155
156QString PeriodicTableWidget::elementsSelectedToString(const QVector<QPushButton *> &elements) {
157 QString selectedElements = "";
158 /* Loop through QPushButtons and if they are checked
159 * then retrieve the text on the button i.e the
160 * element and add it to the string (space delimiter).
161 */
162 for (auto &element : elements) {
163 if (element->isChecked()) {
164 selectedElements += element->text() + ",";
165 }
166 }
167 return selectedElements;
168}
169
171 /*checking all groups of buttons to see if they
172 * have been selected in the Widget.
173 * if they have been selected, the button text is added to
174 * the comma-separated list of elements checked.
175 */
176 QString allCheckedElementsStr = "";
177 allCheckedElementsStr += elementsSelectedToString(Actinides);
178 allCheckedElementsStr += elementsSelectedToString(AlkaliMetals);
179 allCheckedElementsStr += elementsSelectedToString(AlkalineEarthMetals);
180 allCheckedElementsStr += elementsSelectedToString(Halogens);
181 allCheckedElementsStr += elementsSelectedToString(Lanthanides);
182 allCheckedElementsStr += elementsSelectedToString(NobleGases);
183 allCheckedElementsStr += elementsSelectedToString(Metalloids);
184 allCheckedElementsStr += elementsSelectedToString(OtherNonMetals);
185 allCheckedElementsStr += elementsSelectedToString(PostTransitionMetals);
186 allCheckedElementsStr += elementsSelectedToString(TransitionMetals);
187 allCheckedElementsStr += elementsSelectedToString(UnknownProperties);
188
189 // return a string with all the elements that have been selected
190 return allCheckedElementsStr;
191}
192
194
195void PeriodicTableWidget::disableButtons(QVector<QPushButton *> buttonsToDisable) {
196 for (auto &button : buttonsToDisable) {
197 button->setDisabled(true);
198 }
199}
200
202 /*Populate Group Vectors with corresponding Element Buttons*/
203
204 // Populate Other Non-Metals
205 OtherNonMetals.push_back(ui.C); // Carbon
206 OtherNonMetals.push_back(ui.N); // Nitrogen
207 OtherNonMetals.push_back(ui.H); // Hydrogen
208 OtherNonMetals.push_back(ui.O); // Oxygen
209 OtherNonMetals.push_back(ui.Se); // Selenium
210 OtherNonMetals.push_back(ui.S); // Sulfur
211 OtherNonMetals.push_back(ui.P); // Phospherus
212 // Populate Alkali Metals
213 AlkaliMetals.push_back(ui.Cs); // Cesium
214 AlkaliMetals.push_back(ui.Fr); // Francium
215 AlkaliMetals.push_back(ui.Li); // Lithium
216 AlkaliMetals.push_back(ui.K); // Potassium
217 AlkaliMetals.push_back(ui.Rb); // Rubidium
218 AlkaliMetals.push_back(ui.Na); // Sodium
219 // Populate Alkaline Earth Metals
220 AlkalineEarthMetals.push_back(ui.Ba); // Barium
221 AlkalineEarthMetals.push_back(ui.Be); // Beryllium
222 AlkalineEarthMetals.push_back(ui.Ca); // Calcium
223 AlkalineEarthMetals.push_back(ui.Mg); // Magnesium
224 AlkalineEarthMetals.push_back(ui.Ra); // Radium
225 AlkalineEarthMetals.push_back(ui.Sr); // Strontium
226 // Populate Transition Metals
227 TransitionMetals.push_back(ui.Ag); // Silver
228 TransitionMetals.push_back(ui.Au); // Gold
229 TransitionMetals.push_back(ui.Bh); // Bohrium
230 TransitionMetals.push_back(ui.Cd); // Cadmium
231 TransitionMetals.push_back(ui.Cn); // Copernicium
232 TransitionMetals.push_back(ui.Co); // Cobalt
233 TransitionMetals.push_back(ui.Cr); // Chromium
234 TransitionMetals.push_back(ui.Cu); // Copper
235 TransitionMetals.push_back(ui.Db); // Dubnium
236 TransitionMetals.push_back(ui.Fe); // Iron
237 TransitionMetals.push_back(ui.Hf); // Hafnium
238 TransitionMetals.push_back(ui.Hg); // Mercury
239 TransitionMetals.push_back(ui.Hs); // Hassium
240 TransitionMetals.push_back(ui.Ir); // Iridium
241 TransitionMetals.push_back(ui.Mn); // Manganese
242 TransitionMetals.push_back(ui.Mo); // Molybdenum
243 TransitionMetals.push_back(ui.Nb); // Niobium
244 TransitionMetals.push_back(ui.Ni); // Nickel
245 TransitionMetals.push_back(ui.Os); // Osmium
246 TransitionMetals.push_back(ui.Pd); // Palladium
247 TransitionMetals.push_back(ui.Pt); // Platinum
248 TransitionMetals.push_back(ui.Re); // Rhenium
249 TransitionMetals.push_back(ui.Rf); // Rutherfordium
250 TransitionMetals.push_back(ui.Rh); // Rhodium
251 TransitionMetals.push_back(ui.Ru); // Ruthenium
252 TransitionMetals.push_back(ui.Sc); // Scandium
253 TransitionMetals.push_back(ui.Sg); // Seaborgium
254 TransitionMetals.push_back(ui.Ta); // Tantalum
255 TransitionMetals.push_back(ui.Tc); // Technetium
256 TransitionMetals.push_back(ui.Ti); // Titanium
257 TransitionMetals.push_back(ui.V); // Vanadium
258 TransitionMetals.push_back(ui.W); // Tungsten
259 TransitionMetals.push_back(ui.Y); // Yttrium
260 TransitionMetals.push_back(ui.Zn); // Zinc
261 TransitionMetals.push_back(ui.Zr); // Zirconium
262 // Populate Actinides
263 Actinides.push_back(ui.Ac); // Actinium
264 Actinides.push_back(ui.Am); // Americium
265 Actinides.push_back(ui.Bk); // Berkelium
266 Actinides.push_back(ui.Cf); // Californium
267 Actinides.push_back(ui.Cm); // Curium
268 Actinides.push_back(ui.Es); // Einsteinium
269 Actinides.push_back(ui.Fm); // Fermium
270 Actinides.push_back(ui.Lr); // Lawrencium
271 Actinides.push_back(ui.Md); // Mendelevium
272 Actinides.push_back(ui.No); // Nobelium
273 Actinides.push_back(ui.Np); // Neptunium
274 Actinides.push_back(ui.Pa); // Protractinium
275 Actinides.push_back(ui.Pu); // Plutonium
276 Actinides.push_back(ui.Th); // Thorium
277 Actinides.push_back(ui.U); // Uranium
278 // Populate Lanthanides
279 Lanthanides.push_back(ui.Ce); // Cerium
280 Lanthanides.push_back(ui.Dy); // Dysprosium
281 Lanthanides.push_back(ui.Er); // Erbium
282 Lanthanides.push_back(ui.Eu); // Europium
283 Lanthanides.push_back(ui.Gd); // Gadolinium
284 Lanthanides.push_back(ui.Ho); // Holmium
285 Lanthanides.push_back(ui.La); // Lanthanum
286 Lanthanides.push_back(ui.Lu); // Lutetium
287 Lanthanides.push_back(ui.Nd); // Neodymium
288 Lanthanides.push_back(ui.Pm); // Promethium
289 Lanthanides.push_back(ui.Pr); // Praseodymium
290 Lanthanides.push_back(ui.Sm); // Samarium
291 Lanthanides.push_back(ui.Tb); // Terbium
292 Lanthanides.push_back(ui.Tm); // Thulium
293 Lanthanides.push_back(ui.Yb); // Yttrbium
294 // Populate Unknown Properties
295 UnknownProperties.push_back(ui.Ds); // Damstadium
296 UnknownProperties.push_back(ui.Fl); // Flerovium
297 UnknownProperties.push_back(ui.Lv); // Livermorium
298 UnknownProperties.push_back(ui.Mt); // Meitnerium
299 UnknownProperties.push_back(ui.Rg); // Roentgenium
300 UnknownProperties.push_back(ui.Uuo); // Ununoctium
301 UnknownProperties.push_back(ui.Uup); // Ununpentium
302 UnknownProperties.push_back(ui.Uus); // Ununseptium
303 UnknownProperties.push_back(ui.Uut); // Ununtrium
304 // Populate Post-Transition Metals
305 PostTransitionMetals.push_back(ui.Al); // Aluminium
306 PostTransitionMetals.push_back(ui.Bi); // Bismuth
307 PostTransitionMetals.push_back(ui.Ga); // Gallium
308 PostTransitionMetals.push_back(ui.In); // Indium
309 PostTransitionMetals.push_back(ui.Pb); // Lead
310 PostTransitionMetals.push_back(ui.Po); // Polonium
311 PostTransitionMetals.push_back(ui.Sn); // Tin
312 PostTransitionMetals.push_back(ui.Tl); // Thalium
313 // Populate Metalloids
314 Metalloids.push_back(ui.As); // Arsenic
315 Metalloids.push_back(ui.B); // Boron
316 Metalloids.push_back(ui.Ge); // Germanium
317 Metalloids.push_back(ui.Sb); // Antimony
318 Metalloids.push_back(ui.Si); // Silicon
319 Metalloids.push_back(ui.Te); // Tellurium
320 // Populate Halogens
321 Halogens.push_back(ui.At); // Astatine
322 Halogens.push_back(ui.Cl); // Chlorine
323 Halogens.push_back(ui.Br); // Bromine
324 Halogens.push_back(ui.F); // Flourine
325 Halogens.push_back(ui.I); // Iodine
326 // Populate Noble Gases
327 NobleGases.push_back(ui.Ar); // Argon
328 NobleGases.push_back(ui.He); // Helium
329 NobleGases.push_back(ui.Kr); // Krypton
330 NobleGases.push_back(ui.Ne); // Neon
331 NobleGases.push_back(ui.Rn); // Radon
332 NobleGases.push_back(ui.Xe); // Xenon
333}
334
336 AllElementButtons.push_back(Actinides);
344 AllElementButtons.push_back(Metalloids);
345 AllElementButtons.push_back(Halogens);
346 AllElementButtons.push_back(NobleGases);
347}
PeriodicTableWidget(QWidget *parent=nullptr)
Constructor.
void ColourElements()
Colour all of the elements by calls to individual group colouring methods.
void ColourPostTransitionMetals(const QVector< QPushButton * > &postTransMetals)
bool compareButtonNameToStr(QPushButton *buttonToCompare, const QString &stringToCompare)
void populateAllButtonsVector()
Method to populate Vector with all Group vectors.
QVector< QPushButton * > NobleGases
QVector< QPushButton * > Lanthanides
void ColourHalogens(const QVector< QPushButton * > &halogens)
QVector< QPushButton * > PostTransitionMetals
void showGroupLegend(bool checked)
Displays or hides the Legend for the colour coding of periodic groups.
void enableButtonByName(const QString &elementStr)
Enables a button for an element by the element name i.e 'Au' for Gold.
void ColourNonMetals(const QVector< QPushButton * > &nonMetals)
Methods to colour element buttons by periodic group.
void ColourAlkaliMetals(const QVector< QPushButton * > &alkaliMetals)
void ColourLanthanides(const QVector< QPushButton * > &lanthanides)
QVector< QPushButton * > Actinides
QVector< QPushButton * > UnknownProperties
void ColourNobleGases(const QVector< QPushButton * > &nobleGases)
void ColourAlkalineEarthMetals(const QVector< QPushButton * > &alkalineEarthMetals)
Ui::PeriodicTable ui
The Form containing the PeriodicTableWidget.
QString elementsSelectedToString(const QVector< QPushButton * > &elementsSelected)
void ColourButton(QPushButton *elementButton, const QString &colour)
Methods to colour single element button by setting styleSheet.
QVector< QPushButton * > TransitionMetals
void disableButtons(QVector< QPushButton * > buttons)
Disables all buttons associated with a group.
void populateGroupVectors()
Method to populate Group Vectors with element QPushButtons.
void ColourMetalloids(const QVector< QPushButton * > &metalloids)
void disableAllElementButtons()
Disables All buttons in periodicTableWidget.
void ColourTransitionMetals(const QVector< QPushButton * > &transMetals)
void ColourActinides(const QVector< QPushButton * > &actinides)
QVector< QPushButton * > Halogens
QVector< QVector< QPushButton * > > AllElementButtons
Vector to hold all group vectors for access to All Buttons at once.
QVector< QPushButton * > Metalloids
void ColourUnknownProperties(const QVector< QPushButton * > &unknownProperties)
QVector< QPushButton * > OtherNonMetals
Vectors to Hold the QPushButtons of Elements in corresponding Groups.
QVector< QPushButton * > AlkalineEarthMetals
QVector< QPushButton * > AlkaliMetals