Rev 226 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 226 | Rev 227 | ||
---|---|---|---|
Line 644... | Line 644... | ||
644 | QString FilterValueDelegate::getFieldType(QString class_id, QString fieldName)//îïðåäåëÿåì òèï äàííûõ ïîëÿ |
644 | QString FilterValueDelegate::getFieldType(QString class_id, QString fieldName)//îïðåäåëÿåì òèï äàííûõ ïîëÿ |
645 | {
|
645 | {
|
646 | 646 | ||
647 | }
|
647 | }
|
648 | 648 | ||
- | 649 | QMap<QString, QString> FilterValueDelegate::getItems(QString inctance){ // âîçâðàùàåì ñïèñîê âñåõ çíà÷åíèé èç òàáëèöû-õðàíèëèùà |
|
- | 650 | QSqlQuery q;
|
|
- | 651 | QString sql_str;
|
|
- | 652 | QStringList keys_list;
|
|
- | 653 | QStringList values_list;
|
|
- | 654 | QMap<QString, QString> result_map; |
|
- | 655 | ||
- | 656 | ||
- | 657 | ||
- | 658 | ||
- | 659 | bool ok; |
|
- | 660 | sql_str = tr("select * from `"); |
|
- | 661 | sql_str.append(inctance); |
|
- | 662 | sql_str.append(tr("`")); |
|
- | 663 | ok = q.prepare(sql_str); |
|
- | 664 | ok = q.exec(); |
|
- | 665 | if(!ok) return result_map; |
|
- | 666 | while (q.next()){ |
|
- | 667 | QString key_tmp;
|
|
- | 668 | QString value_tmp;
|
|
- | 669 | ||
- | 670 | key_tmp = q.record().value(0).asString(); //îïðåäåëÿåì id îáúåêòà |
|
- | 671 | //keys_list.append(tmp_str); // äîáàâèì â ñïèñîê êëþ÷åé
|
|
- | 672 | ||
- | 673 | value_tmp = q.record().value(1).asString(); //îïðåäåëÿåì èìÿ îáúåêòà |
|
- | 674 | ||
- | 675 | result_map.insert(key_tmp, value_tmp); |
|
- | 676 | // values_list.append(tmp_str);
|
|
649 | 677 | ||
650 | 678 | ||
- | 679 | }
|
|
- | 680 | ||
- | 681 | ||
- | 682 | ||
- | 683 | ||
- | 684 | ||
- | 685 | return result_map; |
|
- | 686 | ||
- | 687 | }
|
|
651 | 688 | ||
652 | 689 | ||
653 | 690 | ||
654 | 691 | ||
655 | //! [1]
|
692 | //! [1]
|
Line 771... | Line 808... | ||
771 | TField Field;
|
808 | TField Field;
|
772 | 809 | ||
773 | Field = getField(index); |
810 | Field = getField(index); |
774 | 811 | ||
775 | 812 | ||
- | 813 | if (Field.FieldType == tr("pointer")){ // åñëè äàííîå ïîëå õðàíèò óêàçàòåëè íà êëàññ-êîíòåéíåð |
|
- | 814 | QString parent_inctance;
|
|
- | 815 | QMap<QString, QString> items_map; |
|
- | 816 | QStringList items_list;
|
|
- | 817 | ||
- | 818 | parent_inctance = getClassInctanc(Field.DefaultValue);// îïðåäåëÿåì õðàíèëèùå îáúåêòîâ êëàññà-êîíòåéíåðà |
|
- | 819 | items_map = getItems(parent_inctance); |
|
- | 820 | items_list = items_map.values(); |
|
- | 821 | ||
- | 822 | comboBox->addItems(items_list); |
|
- | 823 | if (items_list.indexOf(value)!=-1) comboBox->setCurrentIndex(items_list.indexOf(value)); |
|
- | 824 | return; |
|
776 | 825 | ||
777 | 826 | ||
778 | 827 | ||
- | 828 | }
|
|
- | 829 | ||
- | 830 | ||
779 | 831 | ||
780 | fieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString(); |
832 | fieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString(); |
781 | 833 | ||
782 | 834 | ||
783 | inctance = FilterValueDelegate::getClassInctanc(class_id); |
835 | inctance = FilterValueDelegate::getClassInctanc(class_id); |
Line 845... | Line 897... | ||
845 | // spinBox->interpretText();
|
897 | // spinBox->interpretText();
|
846 | // int value = spinBox->value();
|
898 | // int value = spinBox->value();
|
847 | 899 | ||
848 | // model->setData(index, value, Qt::EditRole);
|
900 | // model->setData(index, value, Qt::EditRole);
|
849 | 901 | ||
850 | QStringList ID_list;
|
- | |
851 | QStringList Name_list;
|
- | |
852 | - | ||
853 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
902 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
854 | int currIndex; |
903 | int currIndex; |
855 | currIndex = comboBox->currentIndex(); |
904 | currIndex = comboBox->currentIndex(); |
- | 905 | ||
856 | if (currIndex==-1) return; |
906 | if (currIndex==-1) return; |
- | 907 | ||
- | 908 | QString new_value = comboBox->itemText(currIndex); |
|
- | 909 | ||
- | 910 | QString curr_value = model->data(index, Qt::EditRole).toString();//òåêóùåå çíà÷åíèå â ìîäåëè |
|
- | 911 | ||
- | 912 | ||
- | 913 | ||
- | 914 | QString class_id = model->data(model->index(index.row(),2), Qt::EditRole).toString();//îïðåäåëèì êëàññ, ê êîòîðîìó ïðåíàäëåæèò ïîëå |
|
- | 915 | ||
- | 916 | ||
- | 917 | QStringList ID_list;
|
|
- | 918 | QStringList Name_list;
|
|
- | 919 | ||
- | 920 | ||
- | 921 | TField Field;
|
|
- | 922 | ||
- | 923 | Field = getField(index); |
|
- | 924 | ||
- | 925 | if(Field.FieldType==tr("pointer")){ |
|
- | 926 | QString parent_inctance;
|
|
- | 927 | QMap<QString, QString> items_map; |
|
- | 928 | QStringList keys_list; // ñïèñîê ID îáúåêòîâ ðîäèòåëüñêîãî êëàññà |
|
- | 929 | QStringList values_list; //ñïèñîê èìåí îáúåêòîâ ðîäèòåëüñêîãî êëàññà |
|
- | 930 | ||
- | 931 | ||
- | 932 | ||
- | 933 | parent_inctance = getClassInctanc(Field.DefaultValue);// îïðåäåëÿåì õðàíèëèùå îáúåêòîâ êëàññà-êîíòåéíåðà |
|
- | 934 | items_map = getItems(parent_inctance); // |
|
- | 935 | keys_list = items_map.keys(); |
|
- | 936 | values_list = items_map.values(); |
|
- | 937 | ||
- | 938 | if( values_list.indexOf(new_value)!=-1){ // |
|
- | 939 | ||
- | 940 | QString new_key = keys_list.at(values_list.indexOf(new_value)); // îïðåäåëÿåì íîâîå ØÂ |
|
- | 941 | if (new_key != curr_value) model->setData(index, new_key, Qt::EditRole); |
|
- | 942 | return; |
|
- | 943 | }
|
|
- | 944 | ||
- | 945 | ||
- | 946 | ||
- | 947 | ||
- | 948 | }
|
|
- | 949 | ||
- | 950 | ||
- | 951 | ||
- | 952 | ||
- | 953 | ||
- | 954 | ||
- | 955 | ||
857 | // QString value = comboBox->itemText(currIndex);
|
956 | // QString new_value = comboBox->itemText(currIndex);
|
- | 957 | ||
- | 958 | ||
- | 959 | ||
858 | 960 | ||
859 | // ID_list = items.keys();
|
961 | // ID_list = items.keys();
|
860 | // Name_list = items.values();
|
962 | // Name_list = items.values();
|
861 | 963 | ||
862 | // QString value = ID_list.at(currIndex);
|
964 | // QString value = ID_list.at(currIndex);
|
863 | QString value = items.at(currIndex); |
965 | // QString value = items.at(currIndex);
|
864 | model->setData(index, value, Qt::EditRole); |
966 | model->setData(index, new_value, Qt::EditRole); |
865 | 967 | ||
866 | 968 | ||
867 | }
|
969 | }
|
868 | 970 | ||
869 | 971 |