- // Iterate through all the domains.
- for (int i = 0; i < numberOfDomains; ++i)
- {
- // Get the current domain strings.
- QString currentDomain = standardItemModelPointer->invisibleRootItem()->child(i, 0)->index().data().toString();
- QString currentDomainTopLevelDomain = currentDomain.section('.', -1);
- QString currentDomainSecondLevelDomain = currentDomain.section('.', -2);
- QString currentDomainThirdLevelDomain = currentDomain.section('.', -3);
+ // Create the new domain strings.
+ QString newDomainTopLevelDomain;
+ QString newDomainSecondLevelDomain;
+ QString newDomainThirdLevelDomain;
+
+ // Get the number of dots in the new domain string.
+ int newDomainDots = newDomain.count(QLatin1Char('.'));
+
+ // Get the new top level domain.
+ newDomainTopLevelDomain = newDomain.section('.', -1);
+
+ // Get the new second level domain if it contains at least one dot.
+ if (newDomainDots >= 1)
+ newDomainSecondLevelDomain = newDomain.section('.', -2);
+
+ // Get the new third level domain if it contains at least two dots.
+ if (newDomainDots >= 2)
+ newDomainThirdLevelDomain = newDomain.section('.', -3);
+
+ // Create while loop trackers.
+ bool locationFound = false;
+ int currentRow = 0;
+
+ // Check to see if the new domain should be inserted after an existing domain.
+ while (!locationFound && (currentRow < numberOfDomains)) {
+ // Get the current domain string.
+ QString currentDomain = treeModelPointer->invisibleRootItem()->child(currentRow, 0)->index().data().toString();
+
+ // Create the current domain strings.
+ QString currentDomainTopLevelDomain;
+ QString currentDomainSecondLevelDomain;
+ QString currentDomainThirdLevelDomain;
+
+ // Get the number of dots in the current domain string.
+ int currentDomainDots = currentDomain.count(QLatin1Char('.'));
+
+ // Get the current top level domain.
+ currentDomainTopLevelDomain = currentDomain.section('.', -1);
+
+ // Get the current second level domain if it contains at least one dot.
+ if (currentDomainDots >= 1)
+ currentDomainSecondLevelDomain = currentDomain.section('.', -2);
+
+ // Get the current third level domain if it contains at least two dots.
+ if (currentDomainDots >= 2)
+ currentDomainThirdLevelDomain = currentDomain.section('.', -3);