Exemplo n.º 1
0
void WSuggestionPopup::modelDataChanged(const WModelIndex& topLeft,
					const WModelIndex& bottomRight)
{
  if (topLeft.parent().isValid())
    return;

  if (modelColumn_ < topLeft.column() || modelColumn_ > bottomRight.column())
    return;

  for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
    WContainerWidget *w = dynamic_cast<WContainerWidget *>(impl_->widget(i));
    WAnchor *anchor = dynamic_cast<WAnchor *>(w->widget(0));
    WText *value = dynamic_cast<WText *>(anchor->widget(0));

    WModelIndex index = model_->index(i, modelColumn_);

    boost::any d = index.data();
    value->setText(asString(d));

    TextFormat format = index.flags() & ItemIsXHTMLText ? XHTMLText : PlainText;
    value->setTextFormat(format);

    boost::any d2 = model_->data(i, modelColumn_, UserRole);
    if (d2.empty())
      d2 = d;

    value->setAttributeValue("sug", asString(d2));
  }
}
Exemplo n.º 2
0
void WAbstractItemModel::dropEvent(const WDropEvent& e, DropAction action,
				   int row, int column,
				   const WModelIndex& parent)
{
  // TODO: For now, we assumes selectionBehavior() == RowSelection !

  WItemSelectionModel *selectionModel
    = dynamic_cast<WItemSelectionModel *>(e.source());
  if (selectionModel) {
    WAbstractItemModel *sourceModel = selectionModel->model();

    /*
     * (1) Insert new rows (or later: cells ?)
     */
    if (action == MoveAction || row == -1) {
      if (row == -1)
	row = rowCount(parent);

      insertRows(row, selectionModel->selectedIndexes().size(), parent);
    }

    /*
     * (2) Copy data
     */
    WModelIndexSet selection = selectionModel->selectedIndexes();

    int r = row;
    for (WModelIndexSet::const_iterator i = selection.begin();
	 i != selection.end(); ++i) {
      WModelIndex sourceIndex = *i;
      if (selectionModel->selectionBehavior() == SelectRows) {
	WModelIndex sourceParent = sourceIndex.parent();

	for (int col = 0; col < sourceModel->columnCount(sourceParent); ++col) {
	  WModelIndex s = sourceModel->index(sourceIndex.row(), col,
					     sourceParent);
	  WModelIndex d = index(r, col, parent);
	  copyData(sourceModel, s, this, d);
	}

	++r;
      } else {
	  
      }
    }

    /*
     * (3) Remove original data
     */
    if (action == MoveAction) {
      while (!selectionModel->selectedIndexes().empty()) {
	WModelIndex i = Utils::last(selectionModel->selectedIndexes());

	sourceModel->removeRow(i.row(), i.parent());
      }
    }
  }
}
void WSortFilterProxyModel::sourceDataChanged(const WModelIndex& topLeft,
					      const WModelIndex& bottomRight)
{
  bool refilter
    = dynamic_ && (filterKeyColumn_ >= topLeft.column() 
		   && filterKeyColumn_ <= bottomRight.column());

  bool resort
    = dynamic_ && (sortKeyColumn_ >= topLeft.column() 
		   && sortKeyColumn_ <= bottomRight.column());

  WModelIndex parent = mapFromSource(topLeft.parent());
  Item *item = itemFromIndex(parent);

  for (int row = topLeft.row(); row <= bottomRight.row(); ++row) {
    int oldMappedRow = item->sourceRowMap_[row];
    bool propagateDataChange = oldMappedRow != -1;

    if (refilter || resort) {
      // Determine new insertion point: erase it temporarily for this
      if (oldMappedRow != -1)
	item->proxyRowMap_.erase(item->proxyRowMap_.begin() + oldMappedRow);
      int newMappedRow = mappedInsertionPoint(row, item);
      if (oldMappedRow != -1)
	item->proxyRowMap_.insert(item->proxyRowMap_.begin() + oldMappedRow, row);

      if (newMappedRow != oldMappedRow) {
	if (oldMappedRow != -1) {
	  beginRemoveRows(parent, oldMappedRow, oldMappedRow);
	  item->proxyRowMap_.erase
	    (item->proxyRowMap_.begin() + oldMappedRow);
	  rebuildSourceRowMap(item);
	  endRemoveRows();
	}

	if (newMappedRow != -1) {
	  beginInsertRows(parent, newMappedRow, newMappedRow);
	  item->proxyRowMap_.insert
	    (item->proxyRowMap_.begin() + newMappedRow, row);
	  rebuildSourceRowMap(item);
	  endInsertRows();
	}

	propagateDataChange = false;
      }
    }

    if (propagateDataChange) {
      WModelIndex l = sourceModel()->index(row, topLeft.column(),
					   topLeft.parent());
      WModelIndex r = sourceModel()->index(row, bottomRight.column(),
					   topLeft.parent());

      dataChanged().emit(mapFromSource(l), mapFromSource(r));
    }
  }
}
Exemplo n.º 4
0
void gdContainerBar::doDelete()
{
  WModelIndexSet pSet = m_pView->selectedIndexes();
  if ( pSet.empty() ) return;
  // TODO : Dialog confirm
  for (WModelIndexSet::iterator it = pSet.begin(); it != pSet.end(); ++it) {
    WModelIndex    pIdx = *it;
    rowDeleted_.emit(pIdx.row());
    m_pView->model()->removeRows(pIdx.row(), 1);
  }
}
Exemplo n.º 5
0
// Updates the model index of the gdSqlComboBoxCustomItem
void gdSqlComboBoxDelegate::updateModelIndex(WWidget* widget, const WModelIndex& index)
{
  if ( isFirstRowReserved() )
    if ( index.row() == 0 ) {
      if ( m_bDebug )
        wApp->log("notice") << " gdSqlComboBoxDelegate::updateModelIndex firstRow reserved and row = 0 ";
      WItemDelegate* pItem = dynamic_cast<WItemDelegate*>(widget);
      return pItem->updateModelIndex(widget, index);
    }
  if ( m_bDebug )
    wApp->log("notice") << " gdSqlComboBoxDelegate::updateModelIndex row =  " << index.row();
  gdSqlComboBoxCustomItem*    item = dynamic_cast<gdSqlComboBoxCustomItem*>(widget);
  item->setIndex(index);
  WItemDelegate::updateModelIndex(widget, index);
}
Exemplo n.º 6
0
int GitModel::rowCount(const WModelIndex& index) const
{
  // we are looking for the git SHA1 id of a tree object (since only folders
  // may contain children).
  Git::ObjectId objectId;
  int treeId;

  if (index.isValid()) {
    // only column 0 items may contain children
    if (index.column() != 0)
      return 0;

    Git::Object o = getObject(index);
    if (o.type == Git::Tree) {
      objectId = o.id;
      treeId = getTreeId(index.internalId(), index.row());
    } else
      // not a folder: no children
      return 0;
  } else {
    treeId = 0;
    // the index corresponds to the root object
    if (treeData_.empty())
      // model not yet loaded !
      return 0;
    else
      objectId = treeData_[0].treeObject();
  }

  return treeData_[treeId].rowCount();
}
Exemplo n.º 7
0
WModelIndexList WAbstractItemModel::match(const WModelIndex& start,
					  int role,
					  const boost::any& value,
					  int hits,
					  WFlags<MatchFlag> flags)
  const
{
  WModelIndexList result;

  const int rc = rowCount(start.parent());

  for (int i = 0; i < rc; ++i) {
    int row = start.row() + i;

    if (row >= rc) {
      if (!(flags & MatchWrap))
	break;
      else
	row -= rc;
    }

    WModelIndex idx = index(row, start.column(), start.parent());
    boost::any v = data(idx, role);

    if (Impl::matchValue(v, value, flags))
      result.push_back(idx);
  }

  return result;
}
Exemplo n.º 8
0
WModelIndex WIdentityProxyModel::mapFromSource(const WModelIndex &sourceIndex) const
{
  if (!sourceIndex.isValid())
    return WModelIndex();

  return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
}
Exemplo n.º 9
0
bool ChannelsModel::setData(const WModelIndex &index, const boost::any &value, int role)
{
  if (index.column() == 3)
  {
    QSharedPointer<common::User> du;
    QSharedPointer<Channel> ch;
    ch = m_availableChannels->at(index.row());
    du = common::DbSession::getInstance().getTokensMap().find(std::string(m_token))->second;
    bool subscribed=false;
    for (int i = 0; i < m_subscribedChannels->size(); i++)
    {
      if (m_subscribedChannels->at(i) == ch)
      {
        subscribed = true;
        break;
      }
    }
    if (subscribed)
    {
      //unsubscribe
      common::DbSession::getInstance().unsubscribe(du,ch);
    }
    else
    {
      //subscribe
      common::DbSession::getInstance().subscribe(du,ch);
    }
    //		index.data(Wt::CheckStateRole)=;
    dataChanged().emit(index, index);
    this->channelsUpdated.emit();
    return true;
  }
  return false;
}
Exemplo n.º 10
0
  void handleFinish(DialogCode result)
  {
    if (result == WDialog::Accepted) {
      /*
       * Update the model with data from the edit widgets.
       *
       * You will want to do some validation here...
       *
       * Note that we directly update the source model to avoid
       * problems caused by the dynamic sorting of the proxy model,
       * which reorders row numbers, and would cause us to switch to editing
       * the wrong data.
       */
      WAbstractItemModel *m = model_;
      int modelRow = item_.row();

      WAbstractProxyModel *proxyModel = dynamic_cast<WAbstractProxyModel *>(m);
      if (proxyModel) {
	m = proxyModel->sourceModel();
	modelRow = proxyModel->mapToSource(item_).row();
      }

      m->setData(modelRow, 1, boost::any(nameEdit_->text()));
      m->setData(modelRow, 2, boost::any(typeEdit_->currentText()));
      m->setData(modelRow, 3, boost::any(boost::lexical_cast<int>
					 (sizeEdit_->text().toUTF8())));
      m->setData(modelRow, 4, boost::any(createdPicker_->date()));
      m->setData(modelRow, 5, boost::any(modifiedPicker_->date()));
    }

    delete this;
  }
Exemplo n.º 11
0
boost::any ChannelsModel::data(const WModelIndex & index,
int role) const
{
  if (role == Wt::DisplayRole || role == Wt::EditRole
    || role == ToolTipRole || CheckStateRole)
  {
    switch (index.column())
    {
      case 0:
        return m_availableChannels->at(index.row())->getName();
      case 1:
        return m_availableChannels->at(index.row())->getDescription();
      case 2:
        return m_availableChannels->at(index.row())->getRadius();
      case 3:
      {

        //	  WCheckBox *Check;
        //  	  Check = new WCheckBox(/*dynamic_cast<WContainerWidget*>(WObject::parent())*/);
        for (int i=0;i<m_subscribedChannels->size();i++)
        {
          if (m_subscribedChannels->at(i)==m_availableChannels->at(index.row()))
          {
            //			Check->setChecked(true);
            //	return boost::any(Check);
            if (role == Wt::CheckStateRole) return true;
            return "";
          }
        }
        //	  return *Check;
        if (role == Wt::CheckStateRole) return false;
        return "";
      }
      default:
        return "undefined";
    }
    return "indefined";
  }
  else
  {
    return boost::any();
  }
}
Exemplo n.º 12
0
WModelIndex WSortFilterProxyModel::mapToSource(const WModelIndex& proxyIndex)
  const
{
  if (proxyIndex.isValid()) {
    Item *parentItem = parentItemFromIndex(proxyIndex);
    return sourceModel()->index(parentItem->proxyRowMap_[proxyIndex.row()],
				proxyIndex.column(),
				parentItem->sourceIndex_);
  } else
    return WModelIndex();
}
Exemplo n.º 13
0
void gDoubledSpinBoxDelegate::updateModelIndex(WWidget* widget, const WModelIndex& index)
{
  if ( isFirstRowReserved() )
    if ( index.row() == 0 ) {
      WItemDelegate* pItem = dynamic_cast<WItemDelegate*>(widget);
      return pItem->updateModelIndex(widget, index);
    }
  gdDoubleSpinBoxCustomItem*    item = dynamic_cast<gdDoubleSpinBoxCustomItem*>(widget);
  item->setIndex(index);
  WItemDelegate::updateModelIndex(widget, index);
}
Exemplo n.º 14
0
    virtual WModelIndex index(int row, int column,
                                  const WModelIndex& parent = WModelIndex()) const {
	int parentId;

	if (!parent.isValid())
	    parentId = 0;
	else {
	    int grandParentId = parent.internalId();
	    parentId = getTreeId(grandParentId, parent.row());
	}

	return createIndex(row, column, parentId);
    }
Exemplo n.º 15
0
void WSuggestionPopup::modelDataChanged(const WModelIndex& topLeft,
					const WModelIndex& bottomRight)
{
  if (topLeft.parent().isValid())
    return;

  if (modelColumn_ < topLeft.column() || modelColumn_ > bottomRight.column())
    return;

  for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
    WContainerWidget *w = dynamic_cast<WContainerWidget *>(content_->widget(i));
    WText *value = dynamic_cast<WText *>(w->widget(0));

    boost::any d = model_->data(i, modelColumn_);
    value->setText(asString(d));

    boost::any d2 = model_->data(i, modelColumn_, UserRole);
    if (d2.empty())
      d2 = d;

    value->setAttributeValue("sug", asString(d2));
  }
}
Exemplo n.º 16
0
bool WModelIndex::UnorderedLess::operator() (const WModelIndex& i1,
					     const WModelIndex& i2) const
{
  if (!i1.isValid())
    return i2.isValid();
  else if (!i2.isValid())
    return false;
  else if (i1 == i2)
    return false;
  else if (i1.model() != i2.model()) {
    LOG_ERROR("comparing indexes from different models are you?");
    return false;
  } else if (i1.row() < i2.row())
    return true;
  else if (i1.row() > i2.row())
    return false;
  else if (i1.column() < i2.column())
    return true;
  else if (i1.column() > i2.column())
    return false;
  else
    return i1.internalId_ < i2.internalId_;
}
Exemplo n.º 17
0
///
/// Handle emitting result clicked or selected (they do the same thing except
/// for the signal so combined into one function)
///
void ResultsTable::emitJobClickedOrSelected(const WModelIndex& item, bool clicked)
{

    int modelRow = item.row();

    boost::any d = mSortFilterProxyModel->data(modelRow, 0, UserRole);
    boost::any d1 = mSortFilterProxyModel->data(modelRow, 0, UserRole + 1);
    boost::any d2 = mSortFilterProxyModel->data(modelRow, 0, UserRole + 2);
    boost::any d3 = mSortFilterProxyModel->data(modelRow, 0, UserRole + 3);
    boost::any d4 = mSortFilterProxyModel->data(modelRow, 1, DisplayRole);
    boost::any d5 = mSortFilterProxyModel->data(modelRow, 0, UserRole + 4);

    if (!d.empty() && !d1.empty() && !d2.empty())
    {
        WString clusterCommand = boost::any_cast<WString>(d);
        WString metaScript = boost::any_cast<WString>(d1);
        WString arguments = boost::any_cast<WString>(d2);

        WString jobID;
        if (!d3.empty())
        {
            jobID = boost::any_cast<WString>(d3);
        }

        WString user;
        if (!d4.empty())
        {
            user = boost::any_cast<WString>(d4);
        }

        WString project;
        if (!d5.empty())
        {
            project = boost::any_cast<WString>(d5);
        }

        if (clicked)
        {
            mResultClicked.emit(clusterCommand.toUTF8(), metaScript.toUTF8(), arguments.toUTF8(),
                                jobID.toUTF8(), user.toUTF8(), project.toUTF8());
        }
        else
        {
            mResultSelected.emit(clusterCommand.toUTF8(), metaScript.toUTF8(), arguments.toUTF8(),
                                jobID.toUTF8(), user.toUTF8(), project.toUTF8());
        }
    }

}
Exemplo n.º 18
0
void DataStore::modelDataChanged(const WModelIndex& topLeft,
				 const WModelIndex& bottomRight)
{
  if (dataLocation_ == ClientSide) {
    for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
      if (recordIds_[i] == -1)
	continue;

      for (unsigned j = 0; j < columns_.size(); ++j) {
	const Column& c = columns_[j];

	if (c.modelColumn >= topLeft.column()
	    && c.modelColumn <= bottomRight.column()) {

	  jsChanges_ += "store.getById("
	    + boost::lexical_cast<std::string>(recordIds_[i]) + ").set('"
	    + c.fieldName + "',"
	    + dataAsJSLiteral(i, c.modelColumn) + ");";
	}
      }
    }
  } else
    needRefresh_ = true;
}
Exemplo n.º 19
0
    virtual int rowCount(const WModelIndex& parent = WModelIndex()) const {
	int treeId;

	if (parent.isValid()) {
	    if (parent.column() != 0)
		return 0;
	    Git::Object o = getObject(parent);
	    if (o.type == Git::Tree) { // is a folder
		treeId = getTreeId(parent.internalId(), parent.row());
	    } else                     // is a file
		return 0;
	} else {
	    treeId = 0;
	}

	return treeData_[treeId].rowCount();
    }
Exemplo n.º 20
0
WModelIndex WSortFilterProxyModel::mapFromSource(const WModelIndex& sourceIndex)
  const
{
  if (sourceIndex.isValid()) {
    WModelIndex sourceParent = sourceIndex.parent();

    Item *item = itemFromSourceIndex(sourceParent);

    int row = item->sourceRowMap_[sourceIndex.row()];
    if (row != -1)
      return createIndex(row, sourceIndex.column(),
			 static_cast<void *>(item));
    else
      return WModelIndex();
  } else
    return WModelIndex();
}
Exemplo n.º 21
0
WModelIndex GitModel::index(int row, int column,
			    const WModelIndex& parent) const
{
  int parentId;

  // the top-level parent has id=0.
  if (!parent.isValid())
    parentId = 0;
  else {
    // the internal id of the parent identifies the grand parent
    int grandParentId = parent.internalId();

    // lookup the parent id for the parent himself, based on grand parent
    // and child-index (=row) within the grand parent
    parentId = getTreeId(grandParentId, parent.row());
  }

  return createIndex(row, column, parentId);
}
Exemplo n.º 22
0
 inline virtual boost::any data(const WModelIndex& index, int role = Wt::DisplayRole) const { return wtr(items[index.row()] + ".combo"); }
Exemplo n.º 23
0
    /*
     * Gets the Git::Object that corresponds to an index.
     */
    Git::Object getObject(const WModelIndex& index) const {
	int parentId = index.internalId();
	const Tree& parentItem = treeData_[parentId];
	return git_.treeGetObject(parentItem.treeObject(), index.row());
    }
Exemplo n.º 24
0
WModelIndex WIdentityProxyModel::mapToSource(const WModelIndex &proxyIndex) const
{
  if (!sourceModel() || !proxyIndex.isValid())
    return WModelIndex();
  return createSourceIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer());
}
Exemplo n.º 25
0
void WAbstractProxyModel::shiftModelIndexes(const WModelIndex& sourceParent,
					    int start, int count,
					    ItemMap& items)
{
  /*
   * We must shift all indexes within sourceParent >= start with count
   * and delete items when count < 0.
   */
  std::vector<BaseItem *> shifted;
  std::vector<BaseItem *> erased;

  for (ItemMap::iterator it
	 = items.lower_bound(sourceModel()->index(start, 0, sourceParent));
       it != items.end();) {
#ifndef WT_TARGET_JAVA
    ItemMap::iterator n = it;
    ++n;
#endif
    WModelIndex i = it->first;

    if (i.isValid()) {
      WModelIndex p = i.parent();
      if (p != sourceParent && !WModelIndex::isAncestor(p, sourceParent))
	break;

      if (p == sourceParent) {
	shifted.push_back(it->second);
      } else if (count < 0) {
	// delete indexes that are about to be deleted, if they are within
	// the range of deleted indexes
	do {
	  if (p.parent() == sourceParent
	      && p.row() >= start
	      && p.row() < start - count) {
	    erased.push_back(it->second);
	    break;
	  } else
	    p = p.parent();
	} while (p != sourceParent);
      }
    }

#ifndef WT_TARGET_JAVA
    it = n;
#endif
  }

  for (unsigned i = 0; i < erased.size(); ++i) {
    items.erase(erased[i]->sourceIndex_);
    delete erased[i];
  }

  for (unsigned i = 0; i < shifted.size(); ++i) {
    BaseItem *item = shifted[i];
    items.erase(item->sourceIndex_);
    if (item->sourceIndex_.row() + count >= start) {
      item->sourceIndex_ = sourceModel()->index
	(item->sourceIndex_.row() + count,
	 item->sourceIndex_.column(),
	 sourceParent);
    } else {
      delete item;
      shifted[i] = 0;
    }
  }

  for (unsigned i = 0; i < shifted.size(); ++i) {
    if (shifted[i])
      items[shifted[i]->sourceIndex_] = shifted[i];
  }
}