Seite 1 von 1

QTreeWidgetItem up & verschieben oder swappen ... Proble

Verfasst: 18. Oktober 2006 08:34
von patrik08
Ich habe ein xml tree Kategorien File zum handle

Jedoch bringe ist es nich fertig die QTreeWidgetItem zu verschieben nach oben ... auf dem gleichen level ich habe es mit Drag&Drop versucht .. jedoch appendet das ding
eine neue Categorie und laest die original Kopie stehen.... es ist schlecht zu steuern wo hin verschieben und wohin nicht...

Gibt es andere moeglichkeiten?


Ich habe es so gemacht ... und jedesmal die Dom attribute mit verschieben die in eine QList nach ID int index "itecats" abgespeichert sind... aber im class Cache von QList kann man die Index position nich gut aendern....




Code: Alles auswählen


/////niagara->setDragEnabled (true);
///////niagara->setAcceptDrops(true);

/* move on item to other position  */
/* swap 2 QTreeWidgetItem niagara  = QTreeWidget  tree */
void  Tree_Category::MoveCurrentToDest() 
{
    /* allnametmp = qstringlist from class all QTreeWidgetItem */
    if (Maus_Select_Active) {
       bool ok;
       QString spazio = "\t\t\t\t";
       QString YourActualPosTextIs = Niagara_Actual->text(Maus_Select_Active_On_Cool);
       QString dest_text = QInputDialog::getItem(this, tr("Verschieben nach Liste von alle Categorien"), tr("Item:%1").arg(spazio),allnametmp, 0, false, &ok);
       if (ok && !dest_text.isEmpty()) {
       QList<QTreeWidgetItem*> items = niagara->findItems(dest_text, Qt::MatchRecursive | Qt::MatchExactly , 0);
                     if (items.count() == 1) {
                         QString foundgoogle = items[0]->text(0);
                         
                            int dest_nr = BraketNummer(foundgoogle);  /* [88] text categoryname */
                            int dest_list = FindSavedList(dest_nr);  /* QList<CateSetting *> itecats;   xml tree attribute */
                            
                            int sourc_nr = BraketNummer(YourActualPosTextIs);   /* [88] text categoryname */
                            int sourc_list = FindSavedList(sourc_nr);  /* QList<CateSetting *> itecats;   xml tree attribute */
                
                             if (itecats[sourc_list]->CateValid() and itecats[dest_list]->CateValid()) {
                              /* swap nummer */
                                       itecats[dest_list]->SetPosition(sourc_nr);
                                       itecats[sourc_list]->SetPosition(dest_nr);
                                 
                                       items[0]->setText(0,YourActualPosTextIs);
                                       items[0]->setToolTip(0,QString(YourActualPosTextIs+" ins. %1").arg(dest_list));
                                        Niagara_Actual->setText(0,foundgoogle);
                                        Niagara_Actual->setToolTip(0,QString(foundgoogle+" ins. %1").arg(sourc_list));
                             } else {
                                QMessageBox::warning( this, tr( "Error" ), tr( "Unmoeglich  %1 nach %2!\nHaben Sie eine Kategorie geloescht?").arg(foundgoogle).arg(YourActualPosTextIs)); 
                             }                                 
                         
                         
                         
                         
                         
                         
                         
                     }
       }
    } else {
       QMessageBox::warning( this, tr( "Error" ), tr( "Keine Kategorie Gewaehlt")); 
    } 
}

/*  setting vom dom attribute */

class CateSetting : public QObject
{
    Q_OBJECT
    
public:
        CateSetting( int canva , QString ti ) { 
            if (canva > 0) {
                filler = true;
               position =  canva;
               titles = ti;
            } else {
               filler = false;
               position =  0;
               titles = ti;
            }
        }
        inline void SetPosition( int swap ) { position = swap; }
        inline QString GetTit() const { return titles; }
        inline QDomElement GetDom()  { return ele; }
        inline QDomElement GetBigDom()  { return original; }
        inline void RemoveFromList() { delete this;  }
        int Indexnum() const { return position; }
        bool CateValid() const { return filler; }
        void SetTit ( QString t ) 
        {
           titles = t; 
        }
         void SetDom ( QDomElement d ) 
        {
           ele = d; 
        }
         void SetBigDom ( QDomElement d ) 
        {
           original = d; 
        }
private:
    bool filler;
    QDomElement ele;
    QDomElement original;
    QString titles;
     int position;  
};