summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-04-24 15:11:39 (UTC)
committer mickeyl <mickeyl>2004-04-24 15:11:39 (UTC)
commit1a00a2edf5da1aa7d47c736bb718933f1c2e774b (patch) (unidiff)
treef14bdd2ac8aa2912238eb2ed254fa8cfe03e5b7f
parent2b700fa535661eb1ac897797f318a2694397a4d6 (diff)
downloadopie-1a00a2edf5da1aa7d47c736bb718933f1c2e774b.zip
opie-1a00a2edf5da1aa7d47c736bb718933f1c2e774b.tar.gz
opie-1a00a2edf5da1aa7d47c736bb718933f1c2e774b.tar.bz2
gcc34 fixlet
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tableviewer/db/common.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/apps/tableviewer/db/common.cpp b/noncore/apps/tableviewer/db/common.cpp
index 6e544ba..b58af85 100644
--- a/noncore/apps/tableviewer/db/common.cpp
+++ b/noncore/apps/tableviewer/db/common.cpp
@@ -573,906 +573,906 @@ bool TVVariant::closer(TVVariant n, TVVariant o)
573 switch(type()){ 573 switch(type()){
574 case String: { 574 case String: {
575 /* case for strings is close is a substring.. closer is 575 /* case for strings is close is a substring.. closer is
576 * earlier alphabetically */ 576 * earlier alphabetically */
577 QString qs1 = n.toString().lower(); 577 QString qs1 = n.toString().lower();
578 QString qs2 = o.toString().lower(); 578 QString qs2 = o.toString().lower();
579 QString qsv = toString().lower(); 579 QString qsv = toString().lower();
580 580
581 if (!qs1.startsWith(qsv)) 581 if (!qs1.startsWith(qsv))
582 return FALSE; 582 return FALSE;
583 583
584 /* contains sub-str, if later than is not closer */ 584 /* contains sub-str, if later than is not closer */
585 if(QString::compare(qs1, qs2) > 0) 585 if(QString::compare(qs1, qs2) > 0)
586 return FALSE; 586 return FALSE;
587 return TRUE; 587 return TRUE;
588 } 588 }
589 case Int: { 589 case Int: {
590 /* case for int is smallest absolute difference */ 590 /* case for int is smallest absolute difference */
591 int i1 = n.toInt(); 591 int i1 = n.toInt();
592 int i2 = o.toInt(); 592 int i2 = o.toInt();
593 int iv = toInt(); 593 int iv = toInt();
594 594
595 int diff1 = (i1 - iv); 595 int diff1 = (i1 - iv);
596 if (diff1 < 0) 596 if (diff1 < 0)
597 diff1 = -diff1; 597 diff1 = -diff1;
598 int diff2 = (i2 - iv); 598 int diff2 = (i2 - iv);
599 if (diff2 < 0) 599 if (diff2 < 0)
600 diff2 = -diff2; 600 diff2 = -diff2;
601 601
602 if (diff1 < diff2) 602 if (diff1 < diff2)
603 return TRUE; 603 return TRUE;
604 return FALSE; 604 return FALSE;
605 } 605 }
606 case Date: { 606 case Date: {
607 QDate i1 = n.toDate(); 607 QDate i1 = n.toDate();
608 QDate i2 = o.toDate(); 608 QDate i2 = o.toDate();
609 QDate iv = toDate(); 609 QDate iv = toDate();
610 610
611 /* definition of closer is the least difference in days */ 611 /* definition of closer is the least difference in days */
612 int diff1 = i1.daysTo(iv); 612 int diff1 = i1.daysTo(iv);
613 if (diff1 < 0) 613 if (diff1 < 0)
614 diff1 = -diff1; 614 diff1 = -diff1;
615 int diff2 = i2.daysTo(iv); 615 int diff2 = i2.daysTo(iv);
616 if (diff2 < 0) 616 if (diff2 < 0)
617 diff2 = -diff2; 617 diff2 = -diff2;
618 618
619 if (diff1 < diff2) 619 if (diff1 < diff2)
620 return TRUE; 620 return TRUE;
621 return FALSE; 621 return FALSE;
622 } 622 }
623 case Time: { 623 case Time: {
624 QTime i1 = n.toTime(); 624 QTime i1 = n.toTime();
625 QTime i2 = o.toTime(); 625 QTime i2 = o.toTime();
626 QTime iv = toTime(); 626 QTime iv = toTime();
627 627
628 /* definition of closer is the least difference in days */ 628 /* definition of closer is the least difference in days */
629 int diff1 = i1.msecsTo(iv); 629 int diff1 = i1.msecsTo(iv);
630 if (diff1 < 0) 630 if (diff1 < 0)
631 diff1 = -diff1; 631 diff1 = -diff1;
632 int diff2 = i2.msecsTo(iv); 632 int diff2 = i2.msecsTo(iv);
633 if (diff2 < 0) 633 if (diff2 < 0)
634 diff2 = -diff2; 634 diff2 = -diff2;
635 if (diff1 < diff2) 635 if (diff1 < diff2)
636 return TRUE; 636 return TRUE;
637 return FALSE; 637 return FALSE;
638 } 638 }
639 default: 639 default:
640 /* don't know how to do 'closer' on this type, hence never closer 640 /* don't know how to do 'closer' on this type, hence never closer
641 * or even close */ 641 * or even close */
642 break; 642 break;
643 } 643 }
644 return FALSE; 644 return FALSE;
645} 645}
646 646
647/*! True if n is close to this */ 647/*! True if n is close to this */
648bool TVVariant::close(TVVariant n) 648bool TVVariant::close(TVVariant n)
649{ 649{
650 /* Nothing is close to an invalid, so nothing can be closer */ 650 /* Nothing is close to an invalid, so nothing can be closer */
651 if(type() == Invalid) 651 if(type() == Invalid)
652 return FALSE; 652 return FALSE;
653 653
654 /* can't be close if of different type */ 654 /* can't be close if of different type */
655 if(n.type() != type()) 655 if(n.type() != type())
656 return FALSE; 656 return FALSE;
657 657
658 switch(type()){ 658 switch(type()){
659 case String: { 659 case String: {
660 /* case for strings is close is a substring.. closer is 660 /* case for strings is close is a substring.. closer is
661 * earlier alphabetically */ 661 * earlier alphabetically */
662 QString qs1 = n.toString().lower(); 662 QString qs1 = n.toString().lower();
663 QString qsv = toString().lower(); 663 QString qsv = toString().lower();
664 664
665 if (!qs1.startsWith(qsv)) 665 if (!qs1.startsWith(qsv))
666 return FALSE; 666 return FALSE;
667 return TRUE; 667 return TRUE;
668 } 668 }
669 case Int: 669 case Int:
670 case Date: 670 case Date:
671 case Time: 671 case Time:
672 return TRUE; 672 return TRUE;
673 default: 673 default:
674 /* don't know how to do 'closer' on this type, hence never closer 674 /* don't know how to do 'closer' on this type, hence never closer
675 * or even close */ 675 * or even close */
676 break; 676 break;
677 } 677 }
678 return FALSE; 678 return FALSE;
679} 679}
680 680
681/*! 681/*!
682 \class Key 682 \class Key
683 \brief document me! 683 \brief document me!
684 684
685 document me! 685 document me!
686*/ 686*/
687 687
688Key::Key() : kname(), kexample(), kflags(0) { } 688Key::Key() : kname(), kexample(), kflags(0) { }
689 689
690Key::Key(QString name, TVVariant example, int flags) : 690Key::Key(QString name, TVVariant example, int flags) :
691 kname(name), kexample(example), kflags(flags) { } 691 kname(name), kexample(example), kflags(flags) { }
692 692
693Key::Key(const Key &other) 693Key::Key(const Key &other)
694{ 694{
695 kname = other.kname; 695 kname = other.kname;
696 kexample = other.kexample; 696 kexample = other.kexample;
697 kflags = other.kflags; 697 kflags = other.kflags;
698} 698}
699 699
700Key& Key::operator=(const Key& key) 700Key& Key::operator=(const Key& key)
701{ 701{
702 kname = key.kname; 702 kname = key.kname;
703 kexample = key.kexample; 703 kexample = key.kexample;
704 kflags = key.kflags; 704 kflags = key.kflags;
705 return *this; 705 return *this;
706} 706}
707 707
708QString Key::name() const 708QString Key::name() const
709{ 709{
710 return QString(kname); 710 return QString(kname);
711} 711}
712 712
713TVVariant Key::example() const 713TVVariant Key::example() const
714{ 714{
715 return TVVariant(kexample); 715 return TVVariant(kexample);
716} 716}
717 717
718TVVariant::KeyType Key::type() const 718TVVariant::KeyType Key::type() const
719{ 719{
720 return kexample.type(); 720 return kexample.type();
721} 721}
722 722
723void Key::setName(const QString &name) 723void Key::setName(const QString &name)
724{ 724{
725 kname = QString(name); 725 kname = QString(name);
726} 726}
727 727
728void Key::setExample(const TVVariant &e) 728void Key::setExample(const TVVariant &e)
729{ 729{
730 kexample = TVVariant(e); 730 kexample = TVVariant(e);
731} 731}
732 732
733int Key::flags() const 733int Key::flags() const
734{ 734{
735 return kflags; 735 return kflags;
736} 736}
737 737
738void Key::setFlags(int fl) 738void Key::setFlags(int fl)
739{ 739{
740 kflags = fl; 740 kflags = fl;
741} 741}
742 742
743bool Key::delFlag() const 743bool Key::delFlag() const
744{ 744{
745 if(kflags & del_flag) 745 if(kflags & del_flag)
746 return TRUE; 746 return TRUE;
747 return FALSE; 747 return FALSE;
748} 748}
749 749
750bool Key::newFlag() const 750bool Key::newFlag() const
751{ 751{
752 if(kflags & new_flag) 752 if(kflags & new_flag)
753 return TRUE; 753 return TRUE;
754 return FALSE; 754 return FALSE;
755} 755}
756 756
757void Key::setDelFlag(bool v) 757void Key::setDelFlag(bool v)
758{ 758{
759 if(delFlag() != v) 759 if(delFlag() != v)
760 kflags = kflags ^ del_flag; 760 kflags = kflags ^ del_flag;
761} 761}
762 762
763void Key::setNewFlag(bool v) 763void Key::setNewFlag(bool v)
764{ 764{
765 if(newFlag() != v) 765 if(newFlag() != v)
766 kflags = kflags ^ new_flag; 766 kflags = kflags ^ new_flag;
767} 767}
768 768
769/*! 769/*!
770 \class KeyList 770 \class KeyList
771 \brief A represntation of keys used for a table. 771 \brief A represntation of keys used for a table.
772 772
773 The KeyList class is used to store the representation of keys used in table 773 The KeyList class is used to store the representation of keys used in table
774 headings by DBStore. It stores the names and types of the keys 774 headings by DBStore. It stores the names and types of the keys
775*/ 775*/
776 776
777/*! 777/*!
778 Constructs a KeyList 778 Constructs a KeyList
779*/ 779*/
780KeyList::KeyList() : QIntDict<Key>(20) 780KeyList::KeyList() : QIntDict<Key>(20)
781{ 781{
782 setAutoDelete(TRUE); 782 setAutoDelete(TRUE);
783} 783}
784 784
785/* Should be deep copy, but isn't */ 785/* Should be deep copy, but isn't */
786KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k) 786KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k)
787{ 787{
788 KeyListIterator it(k); 788 KeyListIterator it(k);
789 while(it.current()) { 789 while(it.current()) {
790 replace(it.currentKey(), new Key(*it.current())); 790 replace(it.currentKey(), new Key(*it.current()));
791 ++it; 791 ++it;
792 } 792 }
793 793
794 setAutoDelete(TRUE); 794 setAutoDelete(TRUE);
795} 795}
796 796
797/*! 797/*!
798 Destroys a KeyList 798 Destroys a KeyList
799*/ 799*/
800KeyList::~KeyList() { 800KeyList::~KeyList() {
801} 801}
802 802
803/* Do a comparision base on Keys */ 803/* Do a comparision base on Keys */
804bool KeyList::operator!=(const KeyList &other) 804bool KeyList::operator!=(const KeyList &other)
805{ 805{
806 KeyListIterator it(*this); 806 KeyListIterator it(*this);
807 807
808 if (other.getNumFields() != getNumFields()) 808 if (other.getNumFields() != getNumFields())
809 return TRUE; 809 return TRUE;
810 810
811 while(it.current()) { 811 while(it.current()) {
812 //it.currentKey(), it.current(); 812 //it.currentKey(), it.current();
813 if (other.getKeyName(it.currentKey()) != getKeyName(it.currentKey())) 813 if (other.getKeyName(it.currentKey()) != getKeyName(it.currentKey()))
814 return TRUE; 814 return TRUE;
815 if (other.getKeyType(it.currentKey()) != getKeyType(it.currentKey())) 815 if (other.getKeyType(it.currentKey()) != getKeyType(it.currentKey()))
816 return TRUE; 816 return TRUE;
817 ++it; 817 ++it;
818 } 818 }
819 return FALSE; 819 return FALSE;
820} 820}
821 821
822/*! 822/*!
823 Returns the number of keys stored in the KeyList 823 Returns the number of keys stored in the KeyList
824*/ 824*/
825int KeyList::getNumFields() const 825int KeyList::getNumFields() const
826{ 826{
827 return count(); 827 return count();
828} 828}
829 829
830/*! 830/*!
831 Adds a new key to the KeyList 831 Adds a new key to the KeyList
832 832
833 \param name the name of the new key 833 \param name the name of the new key
834 \param type the type of the new key 834 \param type the type of the new key
835*/ 835*/
836int KeyList::addKey(QString name, TVVariant example) 836int KeyList::addKey(QString name, TVVariant example)
837{ 837{
838 int i = count(); 838 int i = count();
839 while(find(i) && (i > -1)) 839 while(find(i) && (i > -1))
840 i--; 840 i--;
841 replace(i, new Key(name, example, 0)); 841 replace(i, new Key(name, example, 0));
842 return i; 842 return i;
843} 843}
844 844
845int KeyList::addKey(QString name, TVVariant::KeyType type) 845int KeyList::addKey(QString name, TVVariant::KeyType type)
846{ 846{
847 /* generate a valid type for the example? */ 847 /* generate a valid type for the example? */
848 TVVariant e = TVVariant("0"); 848 TVVariant e = TVVariant("0");
849 switch(type) { 849 switch(type) {
850 case TVVariant::String: 850 case TVVariant::String:
851 return addKey(name, TVVariant("<undefined>").asString()); 851 return addKey(name, TVVariant("<undefined>").asString());
852 break; 852 break;
853 case TVVariant::Date: 853 case TVVariant::Date:
854 return addKey(name, TVVariant(QDate::currentDate()).asDate()); 854 return addKey(name, TVVariant(QDate::currentDate()).asDate());
855 break; 855 break;
856 case TVVariant::Time: 856 case TVVariant::Time:
857 return addKey(name, TVVariant(QTime(0,0,0)).toTime()); 857 return addKey(name, TVVariant(QTime(0,0,0)).toTime());
858 break; 858 break;
859 case TVVariant::Int: 859 case TVVariant::Int:
860 return addKey(name, TVVariant(0).toInt()); 860 return addKey(name, TVVariant(0).toInt());
861 break; 861 break;
862 default: 862 default:
863 qWarning(QObject::tr("KeyList::addKey() Cannot make default " 863 qWarning(QObject::tr("KeyList::addKey() Cannot make default "
864 "value for type %1, Key not added.").arg(type)); 864 "value for type %1, Key not added.").arg(type));
865 break; 865 break;
866 } 866 }
867 return -1; 867 return -1;
868} 868}
869 869
870void KeyList::setKeyFlags(int i, int flag) 870void KeyList::setKeyFlags(int i, int flag)
871{ 871{
872 if(find(i)) 872 if(find(i))
873 find(i)->setFlags(flag); 873 find(i)->setFlags(flag);
874} 874}
875 875
876int KeyList::getKeyFlags(int i) const 876int KeyList::getKeyFlags(int i) const
877{ 877{
878 if(find(i)) 878 if(find(i))
879 return find(i)->flags(); 879 return find(i)->flags();
880 return 0; 880 return 0;
881} 881}
882 882
883bool KeyList::checkNewFlag(int i) const 883bool KeyList::checkNewFlag(int i) const
884{ 884{
885 if (find(i)) 885 if (find(i))
886 return find(i)->newFlag(); 886 return find(i)->newFlag();
887 return false; 887 return false;
888} 888}
889 889
890void KeyList::setNewFlag(int i, bool f) 890void KeyList::setNewFlag(int i, bool f)
891{ 891{
892 if(!find(i)) 892 if(!find(i))
893 return; 893 return;
894 find(i)->setNewFlag(f); 894 find(i)->setNewFlag(f);
895} 895}
896 896
897bool KeyList::checkDeleteFlag(int i) const 897bool KeyList::checkDeleteFlag(int i) const
898{ 898{
899 if (find(i)) 899 if (find(i))
900 return find(i)->delFlag(); 900 return find(i)->delFlag();
901 return false; 901 return false;
902} 902}
903 903
904void KeyList::setDeleteFlag(int i, bool f) 904void KeyList::setDeleteFlag(int i, bool f)
905{ 905{
906 if(!find(i)) 906 if(!find(i))
907 return; 907 return;
908 find(i)->setDelFlag(f); 908 find(i)->setDelFlag(f);
909} 909}
910 910
911/*! 911/*!
912 Returns the name of the key at index i 912 Returns the name of the key at index i
913*/ 913*/
914QString KeyList::getKeyName(int i) const 914QString KeyList::getKeyName(int i) const
915{ 915{
916 if (find (i)) 916 if (find (i))
917 return find(i)->name(); 917 return find(i)->name();
918 return QString(); 918 return QString();
919} 919}
920 920
921void KeyList::setKeyName(int i, const QString &n) 921void KeyList::setKeyName(int i, const QString &n)
922{ 922{
923 if(find(i)) 923 if(find(i))
924 find(i)->setName(n); 924 find(i)->setName(n);
925} 925}
926 926
927/*! 927/*!
928 Returns the type of the key at index i 928 Returns the type of the key at index i
929*/ 929*/
930TVVariant::KeyType KeyList::getKeyType(int i) const 930TVVariant::KeyType KeyList::getKeyType(int i) const
931{ 931{
932 if(find(i)) 932 if(find(i))
933 return find(i)->type(); 933 return find(i)->type();
934 return TVVariant::Invalid; 934 return TVVariant::Invalid;
935} 935}
936 936
937void KeyList::setKeyType(int i, TVVariant::KeyType t) 937void KeyList::setKeyType(int i, TVVariant::KeyType t)
938{ 938{
939 if(!find(i)) 939 if(!find(i))
940 return; 940 return;
941 switch(t) { 941 switch(t) {
942 case TVVariant::String: 942 case TVVariant::String:
943 find(i)->setExample(TVVariant(QString("default"))); 943 find(i)->setExample(TVVariant(QString("default")));
944 return; 944 return;
945 case TVVariant::Int: 945 case TVVariant::Int:
946 find(i)->setExample(TVVariant(int(0))); 946 find(i)->setExample(TVVariant(int(0)));
947 return; 947 return;
948 case TVVariant::Date: 948 case TVVariant::Date:
949 find(i)->setExample(TVVariant(QDate::currentDate())); 949 find(i)->setExample(TVVariant(QDate::currentDate()));
950 return; 950 return;
951 case TVVariant::Time: 951 case TVVariant::Time:
952 find(i)->setExample(TVVariant(QTime(0,0,0,0))); 952 find(i)->setExample(TVVariant(QTime(0,0,0,0)));
953 return; 953 return;
954 default: 954 default:
955 break; 955 break;
956 } 956 }
957 return; 957 return;
958} 958}
959 959
960TVVariant KeyList::getKeyExample(int i) const 960TVVariant KeyList::getKeyExample(int i) const
961{ 961{
962 if(find(i)) 962 if(find(i))
963 return find(i)->example(); 963 return find(i)->example();
964 return TVVariant(); 964 return TVVariant();
965} 965}
966 966
967void KeyList::setKeyExample(int i, TVVariant example) 967void KeyList::setKeyExample(int i, TVVariant example)
968{ 968{
969 if(find(i)) 969 if(find(i))
970 find(i)->setExample(example); 970 find(i)->setExample(example);
971} 971}
972 972
973/*! 973/*!
974 Returns the index of the key with name q 974 Returns the index of the key with name q
975*/ 975*/
976int KeyList::getKeyIndex(QString q) const 976int KeyList::getKeyIndex(QString q) const
977{ 977{
978 KeyListIterator it(*this); 978 KeyListIterator it(*this);
979 979
980 while(it.current()) { 980 while(it.current()) {
981 if(it.current()->name() == q) 981 if(it.current()->name() == q)
982 return it.currentKey(); 982 return it.currentKey();
983 ++it; 983 ++it;
984 } 984 }
985 return -1; 985 return -1;
986} 986}
987 987
988bool KeyList::validIndex(int i) const 988bool KeyList::validIndex(int i) const
989{ 989{
990 if(!find(i)) 990 if(!find(i))
991 return FALSE; 991 return FALSE;
992 if(find(i)->delFlag()) 992 if(find(i)->delFlag())
993 return FALSE; 993 return FALSE;
994 return TRUE; 994 return TRUE;
995} 995}
996 996
997QDataStream &operator<<( QDataStream &s, const KeyList &k) 997QDataStream &operator<<( QDataStream &s, const KeyList &k)
998{ 998{
999 s << k.getNumFields(); 999 s << k.getNumFields();
1000 1000
1001 KeyListIterator it(k); 1001 KeyListIterator it(k);
1002 1002
1003 while(it.current()) { 1003 while(it.current()) {
1004 s << (Q_UINT16)it.currentKey(); 1004 s << (Q_UINT16)it.currentKey();
1005 s << it.current()->name(); 1005 s << it.current()->name();
1006 s << it.current()->example(); 1006 s << it.current()->example();
1007 s << (Q_UINT16)it.current()->flags(); 1007 s << (Q_UINT16)it.current()->flags();
1008 ++it; 1008 ++it;
1009 } 1009 }
1010 return s; 1010 return s;
1011} 1011}
1012 1012
1013QDataStream &operator>>( QDataStream &s, KeyList &k) 1013QDataStream &operator>>( QDataStream &s, KeyList &k)
1014{ 1014{
1015 int i; 1015 int i;
1016 int size; 1016 int size;
1017 int index = 0; 1017 int index = 0;
1018 int flags = 0; 1018 int flags = 0;
1019 TVVariant type = TVVariant(); 1019 TVVariant type = TVVariant();
1020 QString name; 1020 QString name;
1021 1021
1022 s >> size; 1022 s >> size;
1023 1023
1024 for (i=0; i < size; i++) { 1024 for (i=0; i < size; i++) {
1025 s >> (Q_UINT16 &)index; 1025 s >> (Q_UINT16 &)index;
1026 s >> name; 1026 s >> name;
1027 s >> type; 1027 s >> type;
1028 s >> (Q_UINT16 &)flags; 1028 s >> (Q_UINT16 &)flags;
1029 k.replace(index, new Key(name, type, flags)); 1029 k.replace(index, new Key(name, type, flags));
1030 } 1030 }
1031 return s; 1031 return s;
1032} 1032}
1033 1033
1034/*! 1034/*!
1035 \class DataElem 1035 \class DataElem
1036 \brief A class representing a single row or element of a table in a DBStore 1036 \brief A class representing a single row or element of a table in a DBStore
1037 1037
1038 This class holds the data of a row in a table. 1038 This class holds the data of a row in a table.
1039*/ 1039*/
1040 1040
1041 1041
1042/*! 1042/*!
1043 Constructs a DataElem. This function needs a container because the 1043 Constructs a DataElem. This function needs a container because the
1044 size, types of keys and primary key are all defined by the containing 1044 size, types of keys and primary key are all defined by the containing
1045 database 1045 database
1046*/ 1046*/
1047DataElem::DataElem(DBStore *c) : values(20) 1047DataElem::DataElem(DBStore *c) : values(20)
1048{ 1048{
1049 int size; 1049 int size;
1050 contained = c; 1050 contained = c;
1051 size = c->getNumFields(); 1051 size = c->getNumFields();
1052 values.setAutoDelete(TRUE); 1052 values.setAutoDelete(TRUE);
1053} 1053}
1054 1054
1055/*! 1055/*!
1056 Destroys a DataElem and frees memory used by the DataElem 1056 Destroys a DataElem and frees memory used by the DataElem
1057*/ 1057*/
1058DataElem::~DataElem() { 1058DataElem::~DataElem() {
1059} 1059}
1060 1060
1061 1061
1062 1062
1063QDataStream &operator<<( QDataStream &s, const DataElem &d) 1063QDataStream &operator<<( QDataStream &s, const DataElem &d)
1064{ 1064{
1065 int size = d.getNumFields(); 1065 int size = d.getNumFields();
1066 1066
1067 s << size; /* redundent data but makes streaming easier */ 1067 s << size; /* redundent data but makes streaming easier */
1068 KeyList k = d.getKeys(); 1068 KeyList k = d.getKeys();
1069 1069
1070 KeyListIterator it(k); 1070 KeyListIterator it(k);
1071 1071
1072 while(it.current()) { 1072 while(it.current()) {
1073 s << (Q_UINT16)it.currentKey(); 1073 s << (Q_UINT16)it.currentKey();
1074 s << d.getField(it.currentKey()); 1074 s << d.getField(it.currentKey());
1075 ++it; 1075 ++it;
1076 } 1076 }
1077 return s; 1077 return s;
1078} 1078}
1079 1079
1080QDataStream &operator>>( QDataStream &s, DataElem &d) 1080QDataStream &operator>>( QDataStream &s, DataElem &d)
1081{ 1081{
1082 int i; 1082 int i;
1083 int size; 1083 int size;
1084 TVVariant t; 1084 TVVariant t;
1085 int index = 0; 1085 Q_UINT16 index = 0;
1086 1086
1087 s >> size; /* redundent data but makes streaming easier */ 1087 s >> size; /* redundent data but makes streaming easier */
1088 if (size != d.getNumFields()) { 1088 if (size != d.getNumFields()) {
1089 owarn << "DataSize mis-match" << oendl; 1089 owarn << "DataSize mis-match" << oendl;
1090 return s; /* sanity check failed.. don't load */ 1090 return s; /* sanity check failed.. don't load */
1091 } 1091 }
1092 1092
1093 for(i = 0; i < size; i++) { 1093 for(i = 0; i < size; i++) {
1094 s >> (Q_UINT16)index; 1094 s >> index;
1095 s >> t; 1095 s >> t;
1096 d.setField(index, t); 1096 d.setField(index, t);
1097 } 1097 }
1098 return s; 1098 return s;
1099} 1099}
1100 1100
1101/*! Returns the number of possible (not valid) fields in the data element */ 1101/*! Returns the number of possible (not valid) fields in the data element */
1102int DataElem::getNumFields() const 1102int DataElem::getNumFields() const
1103{ 1103{
1104 return contained->getNumFields(); 1104 return contained->getNumFields();
1105} 1105}
1106 1106
1107KeyList DataElem::getKeys() const 1107KeyList DataElem::getKeys() const
1108{ 1108{
1109 return *(contained->getKeys()); 1109 return *(contained->getKeys());
1110} 1110}
1111 1111
1112/*! 1112/*!
1113 This function determines whether field index i of the element has been 1113 This function determines whether field index i of the element has been
1114 set yet. 1114 set yet.
1115 1115
1116 \return A boolean value that is TRUE if the specfied field of this 1116 \return A boolean value that is TRUE if the specfied field of this
1117 element has been set and FALSE if the field has not yet been set 1117 element has been set and FALSE if the field has not yet been set
1118*/ 1118*/
1119bool DataElem::hasValidValue(int i) const 1119bool DataElem::hasValidValue(int i) const
1120{ 1120{
1121 if(!values.find(i)) 1121 if(!values.find(i))
1122 return FALSE; 1122 return FALSE;
1123 if(!contained->getKeys()->validIndex(i)) 1123 if(!contained->getKeys()->validIndex(i))
1124 return FALSE; 1124 return FALSE;
1125 return values.find(i)->isValid(); 1125 return values.find(i)->isValid();
1126} 1126}
1127 1127
1128/*! 1128/*!
1129 This function determines whether field name qs of the element has been 1129 This function determines whether field name qs of the element has been
1130 set yet. 1130 set yet.
1131 1131
1132 \return A boolean value that is TRUE if the specfied field of this 1132 \return A boolean value that is TRUE if the specfied field of this
1133 element has been set and FALSE if the field has not yet been set 1133 element has been set and FALSE if the field has not yet been set
1134*/ 1134*/
1135bool DataElem::hasValidValue(QString qs) const 1135bool DataElem::hasValidValue(QString qs) const
1136{ 1136{
1137 int i = contained->getKeyIndex(qs); 1137 int i = contained->getKeyIndex(qs);
1138 return hasValidValue(i); 1138 return hasValidValue(i);
1139} 1139}
1140 1140
1141/*! returns the type of the field specified by index i */ 1141/*! returns the type of the field specified by index i */
1142TVVariant::KeyType DataElem::getFieldType(int i) const 1142TVVariant::KeyType DataElem::getFieldType(int i) const
1143{ 1143{
1144 return contained->getKeyType(i); 1144 return contained->getKeyType(i);
1145} 1145}
1146 1146
1147/*! returns the type of the field specified by name qs */ 1147/*! returns the type of the field specified by name qs */
1148TVVariant::KeyType DataElem::getFieldType(QString qs) const 1148TVVariant::KeyType DataElem::getFieldType(QString qs) const
1149{ 1149{
1150 int i = contained->getKeyIndex(qs); 1150 int i = contained->getKeyIndex(qs);
1151 return contained->getKeyType(i); 1151 return contained->getKeyType(i);
1152} 1152}
1153 1153
1154/*! 1154/*!
1155 returns a pointer to the data stored in field index i for this 1155 returns a pointer to the data stored in field index i for this
1156 data element, (value may not be valid) 1156 data element, (value may not be valid)
1157*/ 1157*/
1158TVVariant DataElem::getField(int i) const 1158TVVariant DataElem::getField(int i) const
1159{ 1159{
1160 if(hasValidValue(i)) 1160 if(hasValidValue(i))
1161 return TVVariant(*values.find(i)); 1161 return TVVariant(*values.find(i));
1162 return TVVariant(); 1162 return TVVariant();
1163} 1163}
1164 1164
1165/*! 1165/*!
1166 returns a pointer to the data stored in field name qs for this 1166 returns a pointer to the data stored in field name qs for this
1167 data element, (value may not be valid) 1167 data element, (value may not be valid)
1168*/ 1168*/
1169TVVariant DataElem::getField(QString qs) const 1169TVVariant DataElem::getField(QString qs) const
1170{ 1170{
1171 int i = contained->getKeyIndex(qs); 1171 int i = contained->getKeyIndex(qs);
1172 return getField(i); 1172 return getField(i);
1173} 1173}
1174 1174
1175/*! 1175/*!
1176 Sets the value of the elements field index i to the value represented in 1176 Sets the value of the elements field index i to the value represented in
1177 the QString q. 1177 the QString q.
1178 1178
1179 \param i index of the field to set 1179 \param i index of the field to set
1180 \param q a string that can be parsed to get the value to be set 1180 \param q a string that can be parsed to get the value to be set
1181*/ 1181*/
1182void DataElem::setField(int i, QString q) 1182void DataElem::setField(int i, QString q)
1183{ 1183{
1184 /* from the type of the field, parse q and store */ 1184 /* from the type of the field, parse q and store */
1185 TVVariant::KeyType kt = contained->getKeyType(i); 1185 TVVariant::KeyType kt = contained->getKeyType(i);
1186 1186
1187 TVVariant t = TVVariant(q); 1187 TVVariant t = TVVariant(q);
1188 1188
1189 switch(kt) { 1189 switch(kt) {
1190 case TVVariant::Int: { 1190 case TVVariant::Int: {
1191 t.asInt(); 1191 t.asInt();
1192 setField(i, t); 1192 setField(i, t);
1193 return; 1193 return;
1194 } 1194 }
1195 case TVVariant::String: { 1195 case TVVariant::String: {
1196 t.asString(); 1196 t.asString();
1197 setField(i, t); 1197 setField(i, t);
1198 return; 1198 return;
1199 } 1199 }
1200 case TVVariant::Date: { 1200 case TVVariant::Date: {
1201 t.asDate(); 1201 t.asDate();
1202 setField(i, t); 1202 setField(i, t);
1203 return; 1203 return;
1204 } 1204 }
1205 case TVVariant::Time: { 1205 case TVVariant::Time: {
1206 t.asTime(); 1206 t.asTime();
1207 setField(i, t); 1207 setField(i, t);
1208 return; 1208 return;
1209 } 1209 }
1210 default: 1210 default:
1211 qWarning( 1211 qWarning(
1212 QObject::tr("DataElem::setField(%1, %2) No valid type found").arg(i).arg(q) 1212 QObject::tr("DataElem::setField(%1, %2) No valid type found").arg(i).arg(q)
1213 ); 1213 );
1214 } 1214 }
1215} 1215}
1216 1216
1217/*! 1217/*!
1218 Sets the value of the elements field index i to the value at the pointer 1218 Sets the value of the elements field index i to the value at the pointer
1219 value. 1219 value.
1220 1220
1221 \param i index of the field to set 1221 \param i index of the field to set
1222 \param value a pointer to the (already allocated) value to set 1222 \param value a pointer to the (already allocated) value to set
1223*/ 1223*/
1224void DataElem::setField(int i, TVVariant value) 1224void DataElem::setField(int i, TVVariant value)
1225{ 1225{
1226 if (value.isValid()) { 1226 if (value.isValid()) {
1227 values.remove(i); 1227 values.remove(i);
1228 values.replace(i, new TVVariant(value)); 1228 values.replace(i, new TVVariant(value));
1229 } 1229 }
1230} 1230}
1231 1231
1232/*! 1232/*!
1233 Sets the value of the elements field name qs to the value represented in 1233 Sets the value of the elements field name qs to the value represented in
1234 the QString q. 1234 the QString q.
1235 1235
1236 \param qs name of the field to set 1236 \param qs name of the field to set
1237 \param q a string that can be parsed to get the value to be set 1237 \param q a string that can be parsed to get the value to be set
1238*/ 1238*/
1239void DataElem::setField(QString qs, QString q) 1239void DataElem::setField(QString qs, QString q)
1240{ 1240{
1241 /* from the type of the field, parse q and store */ 1241 /* from the type of the field, parse q and store */
1242 int i = contained->getKeyIndex(qs); 1242 int i = contained->getKeyIndex(qs);
1243 setField(i, qs); 1243 setField(i, qs);
1244} 1244}
1245 1245
1246/*! 1246/*!
1247 Sets the value of the elements field name qs to the value at the pointer 1247 Sets the value of the elements field name qs to the value at the pointer
1248 value. 1248 value.
1249 1249
1250 \param qs name of the field to set 1250 \param qs name of the field to set
1251 \param value a pointer to the (already allocated) value to set 1251 \param value a pointer to the (already allocated) value to set
1252*/ 1252*/
1253void DataElem::setField(QString qs, TVVariant value) 1253void DataElem::setField(QString qs, TVVariant value)
1254{ 1254{
1255 int i = contained->getKeyIndex(qs); 1255 int i = contained->getKeyIndex(qs);
1256 setField(i, value); 1256 setField(i, value);
1257} 1257}
1258 1258
1259void DataElem::unsetField(int i) { 1259void DataElem::unsetField(int i) {
1260 values.remove(i); 1260 values.remove(i);
1261} 1261}
1262 1262
1263void DataElem::unsetField(QString qs) 1263void DataElem::unsetField(QString qs)
1264{ 1264{
1265 int i = contained->getKeyIndex(qs); 1265 int i = contained->getKeyIndex(qs);
1266 unsetField(i); 1266 unsetField(i);
1267} 1267}
1268 1268
1269/*! 1269/*!
1270 Converts the data element to a Rich Text QString 1270 Converts the data element to a Rich Text QString
1271*/ 1271*/
1272QString DataElem::toQString() const 1272QString DataElem::toQString() const
1273{ 1273{
1274 /* lets make an attempt at this function */ 1274 /* lets make an attempt at this function */
1275 int i; 1275 int i;
1276 QString scratch = ""; 1276 QString scratch = "";
1277 1277
1278 QIntDictIterator<TVVariant> it(values); 1278 QIntDictIterator<TVVariant> it(values);
1279 1279
1280 while (it.current()) { 1280 while (it.current()) {
1281 i = it.currentKey(); 1281 i = it.currentKey();
1282 if(hasValidValue(i)) { 1282 if(hasValidValue(i)) {
1283 scratch += "<B>" + contained->getKeyName(i) + ":</B> "; 1283 scratch += "<B>" + contained->getKeyName(i) + ":</B> ";
1284 scratch += getField(i).toString(); 1284 scratch += getField(i).toString();
1285 scratch += "<br>"; 1285 scratch += "<br>";
1286 } 1286 }
1287 ++it; 1287 ++it;
1288 } 1288 }
1289 return scratch; 1289 return scratch;
1290} 1290}
1291 1291
1292/*! formats individual fields to strings so can be displayed */ 1292/*! formats individual fields to strings so can be displayed */
1293QString DataElem::toQString(int i) const 1293QString DataElem::toQString(int i) const
1294{ 1294{
1295 if(hasValidValue(i)) { 1295 if(hasValidValue(i)) {
1296 return getField(i).toString(); 1296 return getField(i).toString();
1297 } 1297 }
1298 return ""; 1298 return "";
1299} 1299}
1300/*! formats individual fields to strings so can be sorted by QListView */ 1300/*! formats individual fields to strings so can be sorted by QListView */
1301QString DataElem::toSortableQString(int i) const 1301QString DataElem::toSortableQString(int i) const
1302{ 1302{
1303 QString scratch = ""; 1303 QString scratch = "";
1304 if(hasValidValue(i)) { 1304 if(hasValidValue(i)) {
1305 switch (contained->getKeyType(i)) { 1305 switch (contained->getKeyType(i)) {
1306 case TVVariant::String: { 1306 case TVVariant::String: {
1307 scratch += getField(i).toString(); 1307 scratch += getField(i).toString();
1308 break; 1308 break;
1309 } 1309 }
1310 case TVVariant::Int: { 1310 case TVVariant::Int: {
1311 scratch.sprintf("%08d", getField(i).toInt()); 1311 scratch.sprintf("%08d", getField(i).toInt());
1312 break; 1312 break;
1313 } 1313 }
1314 case TVVariant::Date: { 1314 case TVVariant::Date: {
1315 static QDate epochD(1800, 1, 1); 1315 static QDate epochD(1800, 1, 1);
1316 scratch.sprintf("%08d", 1316 scratch.sprintf("%08d",
1317 epochD.daysTo(getField(i).toDate())); 1317 epochD.daysTo(getField(i).toDate()));
1318 break; 1318 break;
1319 } 1319 }
1320 case TVVariant::Time: { 1320 case TVVariant::Time: {
1321 static QTime epochT(0, 0, 0); 1321 static QTime epochT(0, 0, 0);
1322 scratch.sprintf("%08d", 1322 scratch.sprintf("%08d",
1323 epochT.msecsTo(getField(i).toTime())); 1323 epochT.msecsTo(getField(i).toTime()));
1324 break; 1324 break;
1325 } 1325 }
1326 default: 1326 default:
1327 scratch += "Unknown type"; 1327 scratch += "Unknown type";
1328 break; 1328 break;
1329 } 1329 }
1330 } 1330 }
1331 return scratch; 1331 return scratch;
1332} 1332}
1333 1333
1334/* compare functions */ 1334/* compare functions */
1335 1335
1336bool DataElem::lessThan(int i, TVVariant v) const 1336bool DataElem::lessThan(int i, TVVariant v) const
1337{ 1337{
1338 if (!hasValidValue(i)) return FALSE; 1338 if (!hasValidValue(i)) return FALSE;
1339 1339
1340 if (getField(i).type() != v.type()) 1340 if (getField(i).type() != v.type())
1341 return FALSE; 1341 return FALSE;
1342 1342
1343 return (getField(i) < v); 1343 return (getField(i) < v);
1344} 1344}
1345 1345
1346bool DataElem::moreThan(int i, TVVariant v) const 1346bool DataElem::moreThan(int i, TVVariant v) const
1347{ 1347{
1348 if (!hasValidValue(i)) return FALSE; 1348 if (!hasValidValue(i)) return FALSE;
1349 1349
1350 if (getField(i).type() != v.type()) 1350 if (getField(i).type() != v.type())
1351 return FALSE; 1351 return FALSE;
1352 1352
1353 return (getField(i) > v); 1353 return (getField(i) > v);
1354} 1354}
1355 1355
1356bool DataElem::equalTo(int i, TVVariant v) const 1356bool DataElem::equalTo(int i, TVVariant v) const
1357{ 1357{
1358 if (!hasValidValue(i)) return FALSE; 1358 if (!hasValidValue(i)) return FALSE;
1359 1359
1360 if (getField(i).type() != v.type()) 1360 if (getField(i).type() != v.type())
1361 return FALSE; 1361 return FALSE;
1362 1362
1363 return (getField(i) == v); 1363 return (getField(i) == v);
1364} 1364}
1365 1365
1366bool DataElem::contains(int i, TVVariant v) const 1366bool DataElem::contains(int i, TVVariant v) const
1367{ 1367{
1368 if (!hasValidValue(i)) return FALSE; 1368 if (!hasValidValue(i)) return FALSE;
1369 1369
1370 if (getField(i).type() != v.type()) 1370 if (getField(i).type() != v.type())
1371 return FALSE; 1371 return FALSE;
1372 1372
1373 switch(getField(i).type()) { 1373 switch(getField(i).type()) {
1374 case TVVariant::String: { 1374 case TVVariant::String: {
1375 QString qs1 = getField(i).toString().lower(); 1375 QString qs1 = getField(i).toString().lower();
1376 QString qs2 = v.toString().lower(); 1376 QString qs2 = v.toString().lower();
1377 if (qs1.contains(qs2) > 0) return TRUE; 1377 if (qs1.contains(qs2) > 0) return TRUE;
1378 break; 1378 break;
1379 } 1379 }
1380 /* meaningless for ints */ 1380 /* meaningless for ints */
1381 /* meaningless for time */ 1381 /* meaningless for time */
1382 /* meaningless for dates */ 1382 /* meaningless for dates */
1383 case TVVariant::Int: 1383 case TVVariant::Int:
1384 case TVVariant::Time: 1384 case TVVariant::Time:
1385 case TVVariant::Date: 1385 case TVVariant::Date:
1386 break; 1386 break;
1387 default: 1387 default:
1388 owarn << "Tried to compare unknown data type" << oendl; 1388 owarn << "Tried to compare unknown data type" << oendl;
1389 } 1389 }
1390 return FALSE; 1390 return FALSE;
1391} 1391}
1392 1392
1393bool DataElem::startsWith(int i, TVVariant v) const 1393bool DataElem::startsWith(int i, TVVariant v) const
1394{ 1394{
1395 if (!hasValidValue(i)) return FALSE; 1395 if (!hasValidValue(i)) return FALSE;
1396 1396
1397 if (getField(i).type() != v.type()) 1397 if (getField(i).type() != v.type())
1398 return FALSE; 1398 return FALSE;
1399 1399
1400 switch(getField(i).type()) { 1400 switch(getField(i).type()) {
1401 case TVVariant::String: { 1401 case TVVariant::String: {
1402 QString qs1 = getField(i).toString().lower(); 1402 QString qs1 = getField(i).toString().lower();
1403 QString qs2 = v.toString().lower(); 1403 QString qs2 = v.toString().lower();
1404 return qs1.startsWith(qs2); 1404 return qs1.startsWith(qs2);
1405 } 1405 }
1406 /* meaningless for ints */ 1406 /* meaningless for ints */
1407 /* meaningless for time */ 1407 /* meaningless for time */
1408 /* meaningless for dates */ 1408 /* meaningless for dates */
1409 case TVVariant::Int: 1409 case TVVariant::Int:
1410 case TVVariant::Time: 1410 case TVVariant::Time:
1411 case TVVariant::Date: 1411 case TVVariant::Date:
1412 return FALSE; 1412 return FALSE;
1413 default: 1413 default:
1414 owarn << "Tried to compare unknown data type" << oendl; 1414 owarn << "Tried to compare unknown data type" << oendl;
1415 } 1415 }
1416 return FALSE; 1416 return FALSE;
1417} 1417}
1418 1418
1419bool DataElem::endsWith(int i, TVVariant v) const 1419bool DataElem::endsWith(int i, TVVariant v) const
1420{ 1420{
1421 if (!hasValidValue(i)) return FALSE; 1421 if (!hasValidValue(i)) return FALSE;
1422 1422
1423 if (getField(i).type() != v.type()) 1423 if (getField(i).type() != v.type())
1424 return FALSE; 1424 return FALSE;
1425 1425
1426 switch(getField(i).type()) { 1426 switch(getField(i).type()) {
1427 case TVVariant::String: { 1427 case TVVariant::String: {
1428 QString qs1 = getField(i).toString().lower(); 1428 QString qs1 = getField(i).toString().lower();
1429 QString qs2 = v.toString().lower(); 1429 QString qs2 = v.toString().lower();
1430 return qs1.startsWith(qs2); 1430 return qs1.startsWith(qs2);
1431 } 1431 }
1432 /* meaningless for ints */ 1432 /* meaningless for ints */
1433 /* meaningless for time */ 1433 /* meaningless for time */
1434 /* meaningless for dates */ 1434 /* meaningless for dates */
1435 case TVVariant::Int: 1435 case TVVariant::Int:
1436 case TVVariant::Time: 1436 case TVVariant::Time:
1437 case TVVariant::Date: 1437 case TVVariant::Date:
1438 return FALSE; 1438 return FALSE;
1439 default: 1439 default:
1440 owarn << "Tried to compare unknown data type" << oendl; 1440 owarn << "Tried to compare unknown data type" << oendl;
1441 } 1441 }
1442 return FALSE; 1442 return FALSE;
1443} 1443}
1444 1444
1445/*! 1445/*!
1446 Determins which of the first to parameters are closer to the third, target 1446 Determins which of the first to parameters are closer to the third, target
1447 parameter. 1447 parameter.
1448 1448
1449 \return 1449 \return
1450 <UL> 1450 <UL>
1451 <LI>TRUE if the first element is a closer match to the target than the 1451 <LI>TRUE if the first element is a closer match to the target than the
1452 second element</LI> 1452 second element</LI>
1453 <LI>FALSE if the first element is not a closer match to the target than 1453 <LI>FALSE if the first element is not a closer match to the target than
1454 the second element</LI> 1454 the second element</LI>
1455 </UL> 1455 </UL>
1456*/ 1456*/
1457bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column) 1457bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column)
1458{ 1458{
1459 int type; 1459 int type;
1460 1460
1461 if(!d1) return FALSE; 1461 if(!d1) return FALSE;
1462 1462
1463 if (!d1->hasValidValue(column)) return FALSE; 1463 if (!d1->hasValidValue(column)) return FALSE;
1464 1464
1465 if(!target.isValid()) return FALSE; 1465 if(!target.isValid()) return FALSE;
1466 1466
1467 type = d1->getField(column).type(); 1467 type = d1->getField(column).type();
1468 1468
1469 if(d2) { 1469 if(d2) {
1470 if (type != d2->getField(column).type()) { 1470 if (type != d2->getField(column).type()) {
1471 /* can't do compare */ 1471 /* can't do compare */
1472 owarn << "Tried to compare two incompatable types" << oendl; 1472 owarn << "Tried to compare two incompatable types" << oendl;
1473 return FALSE; 1473 return FALSE;
1474 } 1474 }
1475 return target.closer(d1->getField(column), d2->getField(column)); 1475 return target.closer(d1->getField(column), d2->getField(column));
1476 } 1476 }
1477 return target.close(d1->getField(column)); 1477 return target.close(d1->getField(column));
1478} 1478}