Exemple #1
0
void tst_QStandardItem::getSetChild()
{
    QFETCH(int, rows);
    QFETCH(int, columns);
    QFETCH(int, row);
    QFETCH(int, column);

    QStandardItem item(rows, columns);
    bool shouldHaveChildren = (rows > 0) && (columns > 0);
    QCOMPARE(item.hasChildren(), shouldHaveChildren);
    QCOMPARE(item.child(row, column), static_cast<QStandardItem*>(0));

    QStandardItem *child = new QStandardItem;
    item.setChild(row, column, child);
    if ((row >= 0) && (column >= 0)) {
        QCOMPARE(item.rowCount(), qMax(rows, row + 1));
        QCOMPARE(item.columnCount(), qMax(columns, column + 1));

        QCOMPARE(item.child(row, column), child);
        QCOMPARE(child->row(), row);
        QCOMPARE(child->column(), column);

        QStandardItem *anotherChild = new QStandardItem;
        item.setChild(row, column, anotherChild);
        QCOMPARE(item.child(row, column), anotherChild);
        QCOMPARE(anotherChild->row(), row);
        QCOMPARE(anotherChild->column(), column);
        item.setChild(row, column, 0);
    } else {
        delete child;
    }
    QCOMPARE(item.child(row, column), static_cast<QStandardItem*>(0));
}
Exemple #2
0
 template<class T> static QStandardItem * appendRow( QStandardItem * parent, const char * label, const T& value ) {
     QStandardItem * item = new QStandardItem( label );
     item->setEditable( false );
     if ( parent ) {
         parent->appendRow( item );
         QStandardItemModel& model = *item->model();
         if ( parent->columnCount() <= ( item->column() + 1 ) ) 
             model.insertColumn( item->column() + 1, parent->index() );
         model.setData( model.index( item->row(), item->column() + 1, parent->index() ), value );
     }
     return item;
 }
 virtual bool operator<(const QStandardItem &other) const
 {
     const QVariant l = data(Qt::DisplayRole), r = other.data(Qt::DisplayRole);
     if (column() == other.column())
     {
         return l.toDouble() < r.toDouble();
     }
     return QStandardItem::operator<(other);
 }
Exemple #4
0
bool LedgerItem::operator<(const QStandardItem &other) const
{
    if( model() && other.model() && model()==other.model() &&
        column() == Ledger::COL_DESCRIP && other.column() == Ledger::COL_DESCRIP )
    {
        QString a, b;
        a = data(model()->sortRole()).toString();
        b = other.data(other.model()->sortRole()).toString();
        return a.localeAwareCompare(b)<0;
    }
    return QStandardItem::operator <(other);
}
QStandardItem *
StandardItemHelper::appendRow( QStandardItem * parent, const char * label, const QVariant& qv )
{
    QStandardItem * item = new QStandardItem( label );
    item->setEditable( false );
    if ( parent ) {
        parent->appendRow( item );
        QStandardItemModel& model = *item->model();
        int row = item->row();
        int col = item->column();
        model.setData( model.index( row, col + 1, parent->index() ), qv );
    }
    return item;
}
/*
 * Called every time user positions mouse over package's treeview items
 */
bool TreeViewPackagesItemDelegate::helpEvent ( QHelpEvent *event, QAbstractItemView*,
    const QStyleOptionViewItem&, const QModelIndex &index )
{
  if (this->parent()->objectName() == "tvPackages")
  {
    QTreeView* tvPackages = qobject_cast<QTreeView*>(this->parent());
    QSortFilterProxyModel *sfp = qobject_cast<QSortFilterProxyModel*>(tvPackages->model());
    QStandardItemModel *sim = qobject_cast<QStandardItemModel*>(sfp->sourceModel());

    if (sim->rowCount() == 0) return false;

    QModelIndex ind = sfp->mapToSource(index);
    QStandardItem *si = sim->itemFromIndex(ind);

    if (si)
    {
      //If the user's mouse is not positioned above the name column, let's give him a little help...
      if (si->column() != ctn_PACKAGE_NAME_COLUMN)
      {
        QModelIndex miName = sim->index(si->row(), ctn_PACKAGE_NAME_COLUMN);
        si = sim->itemFromIndex(miName);
      }

      QPoint p;
      gPoint = tvPackages->mapToGlobal(event->pos());
      QFuture<QString> f;
      disconnect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
      f = QtConcurrent::run(showPackageInfo, si->text());
      g_fwToolTip.setFuture(f);
      connect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
    }
    else return false;
  }
  else if (this->parent()->objectName() == "tvTransaction")
  {
    QTreeView* tvTransaction = qobject_cast<QTreeView*>(this->parent());
    QStandardItemModel *sim = qobject_cast<QStandardItemModel*>(tvTransaction->model());

    if (sim->rowCount() == 0) return false;

    QStandardItem *si = sim->itemFromIndex(index);

    if (si)
    {
      //If it's really a package in the Transaction treeview...
      QString pkgName=si->text();

      //We have to separate Repository from Package Name, first
      int slash = pkgName.indexOf("/");
      if (slash != -1)
      {
        pkgName = pkgName.mid(slash+1);
      }

      if (si->icon().pixmap(22, 22).toImage() ==
          IconHelper::getIconInstallItem().pixmap(22, 22).toImage() ||
          si->icon().pixmap(22, 22).toImage() ==
          IconHelper::getIconRemoveItem().pixmap(22, 22).toImage())
      {
        QStandardItemModel *modelPackages = MainWindow::returnMainWindow()->getModelPackages();
        QList<QStandardItem*> foundItems =
            modelPackages->findItems(pkgName, Qt::MatchExactly, ctn_PACKAGE_NAME_COLUMN);

        if (foundItems.count() > 0)
        {
          QStandardItem *siFound = foundItems.at(0);

          QPoint p;
          gPoint = tvTransaction->mapToGlobal(event->pos());
          QFuture<QString> f;
          disconnect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
          f = QtConcurrent::run(showPackageInfo, siFound->text());
          g_fwToolTip.setFuture(f);
          connect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
        }
      }
      else
      {
        QToolTip::hideText();
      }
    }
  }

  return true;
}
Exemple #7
0
void MainWindow::tableview_generations_clicked(QModelIndex index)
{
    QStandardItem *item = _modelGenerations->itemFromIndex(index);
    item->column();
    qDebug() << "clicked signal";
    qDebug() << item->text();

    QDomDocument doc;
    QString filename = _strLogDir + "/" + item->text();
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly))
    {   qDebug() << "Fail to open file...";
        return;
    }
    if (!doc.setContent(&file)) {
        qDebug() << "Fail to populize domdocument...";
        file.close();
        return;
    }
    file.close();

    // clear old model
    _modelIndividuals->clear();
    _genos.clear();

    // initialize view header
    QStringList strList;
    strList.append("Fitness");
    strList.append("Size");
    strList.append("Depth");
    //strList.append("Genotype");
    _modelIndividuals->setHorizontalHeaderLabels(strList);

    // get individuals
    QDomNodeList individuals = doc.elementsByTagName("Individual");

    // for each individual get fitness value and genotype
    for(int i = 0; i < individuals.size(); i++)
    {
        QDomElement individual = individuals.at(i).toElement();
        int indi_size = individual.attribute("size").toInt();

        QDomElement elem = individual.firstChildElement();
        QString fitness = elem.text();

        for (int j = 0; j < indi_size; j++)
        {
            elem = elem.nextSiblingElement();
            // add individual index
            QList<QStandardItem *> items;
            items.append(new QStandardItem( fitness ));
            items.append(new QStandardItem( elem.attribute("size") ));
            items.append(new QStandardItem( elem.attribute("depth") ));
            QString str;
            QTextStream stream(&str);
            stream << elem.firstChildElement();
            stream.flush();

            //items.append(new QStandardItem( str.trimmed() ));
            _genos.append(str);
            _modelIndividuals->appendRow(items);
        }

    }
    ui->tableView_Individuals->resizeColumnsToContents();
    ui->tableView_Individuals->sortByColumn(0);
}