Remove SQLTableDialogDataItem as it is no longer used.
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -1481,227 +1481,6 @@ class BranchWindow(QMdiSubWindow): · 1480 unmodified lines | ||
| 1481 | 1481 | else: |
| 1482 | 1482 | self.find_bar.NotFound() |
| 1483 | 1483 | |
| 1484 | −# Dialog data item converted and validated using a SQL table | |
| 1485 | − | |
| 1486 | −class SQLTableDialogDataItem(): | |
| 1487 | − | |
| 1488 | − def __init__(self, glb, label, placeholder_text, table_name, match_column, column_name1, column_name2, parent): | |
| 1489 | − self.glb = glb | |
| 1490 | − self.label = label | |
| 1491 | − self.placeholder_text = placeholder_text | |
| 1492 | − self.table_name = table_name | |
| 1493 | − self.match_column = match_column | |
| 1494 | − self.column_name1 = column_name1 | |
| 1495 | − self.column_name2 = column_name2 | |
| 1496 | − self.parent = parent | |
| 1497 | − | |
| 1498 | − self.value = "" | |
| 1499 | − | |
| 1500 | − self.widget = QLineEdit() | |
| 1501 | − self.widget.editingFinished.connect(self.Validate) | |
| 1502 | − self.widget.textChanged.connect(self.Invalidate) | |
| 1503 | − self.red = False | |
| 1504 | − self.error = "" | |
| 1505 | − self.validated = True | |
| 1506 | − | |
| 1507 | − self.last_id = 0 | |
| 1508 | − self.first_time = 0 | |
| 1509 | − self.last_time = 2 ** 64 | |
| 1510 | − if self.table_name == "<timeranges>": | |
| 1511 | − query = QSqlQuery(self.glb.db) | |
| 1512 | − QueryExec(query, "SELECT id, time FROM samples ORDER BY id DESC LIMIT 1") | |
| 1513 | − if query.next(): | |
| 1514 | − self.last_id = int(query.value(0)) | |
| 1515 | − self.last_time = int(query.value(1)) | |
| 1516 | − QueryExec(query, "SELECT time FROM samples WHERE time != 0 ORDER BY id LIMIT 1") | |
| 1517 | − if query.next(): | |
| 1518 | − self.first_time = int(query.value(0)) | |
| 1519 | − if placeholder_text: | |
| 1520 | − placeholder_text += ", between " + str(self.first_time) + " and " + str(self.last_time) | |
| 1521 | − | |
| 1522 | − if placeholder_text: | |
| 1523 | − self.widget.setPlaceholderText(placeholder_text) | |
| 1524 | − | |
| 1525 | − def ValueToIds(self, value): | |
| 1526 | − ids = [] | |
| 1527 | − query = QSqlQuery(self.glb.db) | |
| 1528 | − stmt = "SELECT id FROM " + self.table_name + " WHERE " + self.match_column + " = '" + value + "'" | |
| 1529 | − ret = query.exec_(stmt) | |
| 1530 | − if ret: | |
| 1531 | − while query.next(): | |
| 1532 | − ids.append(str(query.value(0))) | |
| 1533 | − return ids | |
| 1534 | − | |
| 1535 | − def IdBetween(self, query, lower_id, higher_id, order): | |
| 1536 | − QueryExec(query, "SELECT id FROM samples WHERE id > " + str(lower_id) + " AND id < " + str(higher_id) + " ORDER BY id " + order + " LIMIT 1") | |
| 1537 | − if query.next(): | |
| 1538 | − return True, int(query.value(0)) | |
| 1539 | − else: | |
| 1540 | − return False, 0 | |
| 1541 | − | |
| 1542 | − def BinarySearchTime(self, lower_id, higher_id, target_time, get_floor): | |
| 1543 | − query = QSqlQuery(self.glb.db) | |
| 1544 | − while True: | |
| 1545 | − next_id = int((lower_id + higher_id) / 2) | |
| 1546 | − QueryExec(query, "SELECT time FROM samples WHERE id = " + str(next_id)) | |
| 1547 | − if not query.next(): | |
| 1548 | − ok, dbid = self.IdBetween(query, lower_id, next_id, "DESC") | |
| 1549 | − if not ok: | |
| 1550 | − ok, dbid = self.IdBetween(query, next_id, higher_id, "") | |
| 1551 | − if not ok: | |
| 1552 | − return str(higher_id) | |
| 1553 | − next_id = dbid | |
| 1554 | − QueryExec(query, "SELECT time FROM samples WHERE id = " + str(next_id)) | |
| 1555 | − next_time = int(query.value(0)) | |
| 1556 | − if get_floor: | |
| 1557 | − if target_time > next_time: | |
| 1558 | − lower_id = next_id | |
| 1559 | − else: | |
| 1560 | − higher_id = next_id | |
| 1561 | − if higher_id <= lower_id + 1: | |
| 1562 | − return str(higher_id) | |
| 1563 | − else: | |
| 1564 | − if target_time >= next_time: | |
| 1565 | − lower_id = next_id | |
| 1566 | − else: | |
| 1567 | − higher_id = next_id | |
| 1568 | − if higher_id <= lower_id + 1: | |
| 1569 | − return str(lower_id) | |
| 1570 | − | |
| 1571 | − def ConvertRelativeTime(self, val): | |
| 1572 | − mult = 1 | |
| 1573 | − suffix = val[-2:] | |
| 1574 | − if suffix == "ms": | |
| 1575 | − mult = 1000000 | |
| 1576 | − elif suffix == "us": | |
| 1577 | − mult = 1000 | |
| 1578 | − elif suffix == "ns": | |
| 1579 | − mult = 1 | |
| 1580 | − else: | |
| 1581 | − return val | |
| 1582 | − val = val[:-2].strip() | |
| 1583 | − if not self.IsNumber(val): | |
| 1584 | − return val | |
| 1585 | − val = int(val) * mult | |
| 1586 | − if val >= 0: | |
| 1587 | − val += self.first_time | |
| 1588 | − else: | |
| 1589 | − val += self.last_time | |
| 1590 | − return str(val) | |
| 1591 | − | |
| 1592 | − def ConvertTimeRange(self, vrange): | |
| 1593 | − if vrange[0] == "": | |
| 1594 | − vrange[0] = str(self.first_time) | |
| 1595 | − if vrange[1] == "": | |
| 1596 | − vrange[1] = str(self.last_time) | |
| 1597 | − vrange[0] = self.ConvertRelativeTime(vrange[0]) | |
| 1598 | − vrange[1] = self.ConvertRelativeTime(vrange[1]) | |
| 1599 | − if not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]): | |
| 1600 | − return False | |
| 1601 | − beg_range = max(int(vrange[0]), self.first_time) | |
| 1602 | − end_range = min(int(vrange[1]), self.last_time) | |
| 1603 | − if beg_range > self.last_time or end_range < self.first_time: | |
| 1604 | − return False | |
| 1605 | − vrange[0] = self.BinarySearchTime(0, self.last_id, beg_range, True) | |
| 1606 | − vrange[1] = self.BinarySearchTime(1, self.last_id + 1, end_range, False) | |
| 1607 | − return True | |
| 1608 | − | |
| 1609 | − def AddTimeRange(self, value, ranges): | |
| 1610 | − n = value.count("-") | |
| 1611 | − if n == 1: | |
| 1612 | − pass | |
| 1613 | − elif n == 2: | |
| 1614 | − if value.split("-")[1].strip() == "": | |
| 1615 | − n = 1 | |
| 1616 | − elif n == 3: | |
| 1617 | − n = 2 | |
| 1618 | − else: | |
| 1619 | − return False | |
| 1620 | − pos = findnth(value, "-", n) | |
| 1621 | − vrange = [value[:pos].strip() ,value[pos+1:].strip()] | |
| 1622 | − if self.ConvertTimeRange(vrange): | |
| 1623 | − ranges.append(vrange) | |
| 1624 | − return True | |
| 1625 | − return False | |
| 1626 | − | |
| 1627 | − def InvalidValue(self, value): | |
| 1628 | − self.value = "" | |
| 1629 | − palette = QPalette() | |
| 1630 | − palette.setColor(QPalette.Text,Qt.red) | |
| 1631 | − self.widget.setPalette(palette) | |
| 1632 | − self.red = True | |
| 1633 | − self.error = self.label + " invalid value '" + value + "'" | |
| 1634 | − self.parent.ShowMessage(self.error) | |
| 1635 | − | |
| 1636 | − def IsNumber(self, value): | |
| 1637 | − try: | |
| 1638 | − x = int(value) | |
| 1639 | − except: | |
| 1640 | − x = 0 | |
| 1641 | − return str(x) == value | |
| 1642 | − | |
| 1643 | − def Invalidate(self): | |
| 1644 | − self.validated = False | |
| 1645 | − | |
| 1646 | − def Validate(self): | |
| 1647 | − input_string = self.widget.text() | |
| 1648 | − self.validated = True | |
| 1649 | − if self.red: | |
| 1650 | − palette = QPalette() | |
| 1651 | − self.widget.setPalette(palette) | |
| 1652 | − self.red = False | |
| 1653 | − if not len(input_string.strip()): | |
| 1654 | − self.error = "" | |
| 1655 | − self.value = "" | |
| 1656 | − return | |
| 1657 | − if self.table_name == "<timeranges>": | |
| 1658 | − ranges = [] | |
| 1659 | − for value in [x.strip() for x in input_string.split(",")]: | |
| 1660 | − if not self.AddTimeRange(value, ranges): | |
| 1661 | − return self.InvalidValue(value) | |
| 1662 | − ranges = [("(" + self.column_name1 + " >= " + r[0] + " AND " + self.column_name1 + " <= " + r[1] + ")") for r in ranges] | |
| 1663 | − self.value = " OR ".join(ranges) | |
| 1664 | − elif self.table_name == "<ranges>": | |
| 1665 | − singles = [] | |
| 1666 | − ranges = [] | |
| 1667 | − for value in [x.strip() for x in input_string.split(",")]: | |
| 1668 | − if "-" in value: | |
| 1669 | − vrange = value.split("-") | |
| 1670 | − if len(vrange) != 2 or not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]): | |
| 1671 | − return self.InvalidValue(value) | |
| 1672 | − ranges.append(vrange) | |
| 1673 | − else: | |
| 1674 | − if not self.IsNumber(value): | |
| 1675 | − return self.InvalidValue(value) | |
| 1676 | − singles.append(value) | |
| 1677 | − ranges = [("(" + self.column_name1 + " >= " + r[0] + " AND " + self.column_name1 + " <= " + r[1] + ")") for r in ranges] | |
| 1678 | − if len(singles): | |
| 1679 | − ranges.append(self.column_name1 + " IN (" + ",".join(singles) + ")") | |
| 1680 | − self.value = " OR ".join(ranges) | |
| 1681 | − elif self.table_name: | |
| 1682 | − all_ids = [] | |
| 1683 | − for value in [x.strip() for x in input_string.split(",")]: | |
| 1684 | − ids = self.ValueToIds(value) | |
| 1685 | − if len(ids): | |
| 1686 | − all_ids.extend(ids) | |
| 1687 | − else: | |
| 1688 | − return self.InvalidValue(value) | |
| 1689 | − self.value = self.column_name1 + " IN (" + ",".join(all_ids) + ")" | |
| 1690 | − if self.column_name2: | |
| 1691 | − self.value = "( " + self.value + " OR " + self.column_name2 + " IN (" + ",".join(all_ids) + ") )" | |
| 1692 | − else: | |
| 1693 | − self.value = input_string.strip() | |
| 1694 | − self.error = "" | |
| 1695 | − self.parent.ClearMessage() | |
| 1696 | − | |
| 1697 | − def IsValid(self): | |
| 1698 | − if not self.validated: | |
| 1699 | − self.Validate() | |
| 1700 | − if len(self.error): | |
| 1701 | − self.parent.ShowMessage(self.error) | |
| 1702 | − return False | |
| 1703 | − return True | |
| 1704 | − | |
| 1705 | 1484 | # Line edit data item |
| 1706 | 1485 | |
| 1707 | 1486 | class LineEditDataItem(object): |