void TableEditor::configureCell(int row, int col, Node * node) { TableItem* item = (TableItem*) m_dataTable->item(row, col); if (!item) return; // Header (TH) or standard cell? item->setHeader(node->tag->name.lower() == "th"); // Horizontal alignment Qt::AlignmentFlags flags; QString align = node->tag->attributeValue("align", true); if (align == "right") flags = Qt::AlignRight; else if (align == "center") flags = Qt::AlignHCenter; else if (align == "justify") flags = Qt::AlignJustify; else if (align.isEmpty() && item->header()) flags = Qt::AlignHCenter; // TH is centered by default else flags = Qt::AlignLeft; item->setAlignment(flags); // Vertical alignment QString valign = node->tag->attributeValue("valign", true); if (valign == "top") flags = Qt::AlignTop; else if (valign == "bottom") flags = Qt::AlignBottom; else flags = Qt::AlignVCenter; item->setVAlignment(flags); }
bool TableModel::setData(const QModelIndex &index, const QVariant &value, int role) { if ( !index.isValid() ) { return false; } TableItem *itm = item(index); if (itm) { itm->setData(role, value); return true; } // don't create dummy table items for empty values if ( !value.isValid() ) { return false; } TableView *view = qobject_cast<TableView*>( QObject::parent() ); if (!view) { return false; } itm = createItem(); itm->setData(role, value); view->setItem(index.row(), index.column(), itm); return true; }
ConstraintTable::ConstraintTable(QWidget * parent, ConstraintCanvas * c) : Q3Table(c->elements.count(), 4, parent) { setSorting(true); setSelectionMode(NoSelection); setRowMovingEnabled(FALSE); horizontalHeader()->setLabel(0, TR("visible")); horizontalHeader()->setLabel(1, " "); horizontalHeader()->setLabel(2, TR("element")); horizontalHeader()->setLabel(3, TR("constraint")); setColumnStretchable(0, FALSE); setColumnStretchable(1, FALSE); int row; bool v = c->indicate_visible; Q3ValueList<BrowserNode *> & hv = c->hidden_visible; BrowserNodeList & elts = c->elements; BrowserNode * bn; QString yes = TR(" yes"); QString empty; elts.sort(); for (bn = elts.first(), row = 0; bn != 0; bn = elts.next(), row += 1) { if ((v) ? hv.findIndex(bn) != -1 : hv.findIndex(bn) == -1) setText(row, 0, yes); setPixmap(row, 1, *(bn->pixmap(0))); TableItem * ti; ti = new TableItem(this, Q3TableItem::Never, bn->full_name(TRUE)); ti->setReplaceable(FALSE); setItem(row, 2, ti); QString s = toUnicode(bn->constraint()); int n = s.count('\n'); ti = new TableItem(this, Q3TableItem::Never, s); ti->setReplaceable(FALSE); setItem(row, 3, ti); if (n != 0) { // note : adjustRow(row) does nothing setRowHeight(row, rowHeight(row) * (n + 1)); } } adjustColumn(0); adjustColumn(1); setColumnStretchable(2, TRUE); setColumnStretchable(3, TRUE); connect(this, SIGNAL(pressed(int, int, int, const QPoint &)), this, SLOT(button_pressed(int, int, int, const QPoint &))); }
TableItem* TableItem::create(CCSize size) { TableItem *instance = new TableItem(); if (instance && instance->initWithSize(size)) { instance->autorelease(); return instance; } CC_SAFE_DELETE(instance); return instance; }
QVariant TableModel::data(const QModelIndex &index, int role) const { TableItem *itm = item(index); if (itm) { return itm->data(role); } return QVariant(); }
void TableView::setHorizontalHeaderLabels(const QStringList &labels) { TableItem *item = 0; for (int i = 0; i < _imp->model->columnCount() && i < labels.count(); ++i) { item = _imp->model->horizontalHeaderItem(i); if (!item) { item = _imp->model->createItem(); setHorizontalHeaderItem(i, item); } item->setText( labels.at(i) ); } }
static gboolean plugin_init (GstPlugin *plugin) { GQuark library_name_quark; GQuark component_name_quark; GQuark component_role_quark; GST_DEBUG_CATEGORY_INIT (gstomx_debug, "omx", 0, "gst-openmax"); GST_DEBUG_CATEGORY_INIT (gstomx_util_debug, "omx_util", 0, "gst-openmax utility"); GST_DEBUG_CATEGORY_INIT (gstomx_ppm, "omx_ppm", 0, "gst-openmax performance"); library_name_quark = g_quark_from_static_string ("library-name"); component_name_quark = g_quark_from_static_string ("component-name"); component_role_quark = g_quark_from_static_string ("component-role"); g_omx_init (); { guint i; for (i = 0; element_table[i].name; i++) { TableItem *element; GType type; element = &element_table[i]; type = element->get_type (); g_type_set_qdata (type, library_name_quark, (gpointer) element->library_name); g_type_set_qdata (type, component_name_quark, (gpointer) element->component_name); g_type_set_qdata (type, component_role_quark, (gpointer) element->component_role); if (!gst_element_register (plugin, element->name, element->rank, type)) { g_warning ("failed registering '%s'", element->name); return FALSE; } } } return TRUE; }
bool TableModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) { if ( !index.isValid() ) { return false; } TableView *view = qobject_cast<TableView*>( QObject::parent() ); TableItem *itm = item(index); if (itm) { itm->view = 0; // prohibits item from calling itemChanged() bool changed = false; for (QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it) { if ( itm->data( it.key() ) != it.value() ) { itm->setData( it.key(), it.value() ); changed = true; } } itm->view = view; if (changed) { itemChanged(itm); } return true; } if (!view) { return false; } itm = createItem(); for (QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it) { itm->setData( it.key(), it.value() ); } view->setItem(index.row(), index.column(), itm); return true; }
bool TableModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) { if ( (section < 0) || ( (orientation == Qt::Horizontal) && ( (int)_imp->horizontalHeaderItems.size() <= section ) ) ) { return false; } TableItem *itm = 0; if (orientation == Qt::Horizontal) { itm = _imp->horizontalHeaderItems.at(section); } if (itm) { itm->setData(role, value); return true; } return false; }
QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const { if (section < 0) { return QVariant(); } TableItem *itm = 0; if ( (orientation == Qt::Horizontal) && ( section < (int)_imp->horizontalHeaderItems.size() ) ) { itm = _imp->horizontalHeaderItems.at(section); } else { return QVariant(); // section is out of bounds } if (itm) { return itm->data(role); } if (role == Qt::DisplayRole) { return section + 1; } return QVariant(); }
int main(int argc, char **argv) { if (4 != argc) { fprintf(stderr, "./test_tablemgr [store_root] [raid_regex] [store_regex]\n"); exit(-1); } ob_init_memory_pool(); char *root = argv[1]; char *raid = argv[2]; char *store = argv[3]; TableMgr tm; SSTableMgr &sstm = UPS.get_sstable_mgr(); CommonSchemaManagerWrapper schema_mgr; tbsys::CConfig config; schema_mgr.parse_from_file("test_schema.ini", config); UPS.get_table_mgr().set_schemas(schema_mgr); common::ObRoleMgr role_mgr; common::ObSlaveMgr slave_mgr; role_mgr.set_role(ObRoleMgr::MASTER); int ret = slave_mgr.init(0, &UPS.get_ups_rpc_stub(), 1000000, 6000000, 4000000, 3); assert(OB_SUCCESS == ret); ret = UPS.get_log_mgr().init("./commitlog", 64 * 1024 * 1024, &slave_mgr, &role_mgr, 0); assert(OB_SUCCESS == ret); ret = UPS.get_log_mgr().replay_log(UPS.get_table_mgr()); assert(OB_SUCCESS == ret); ret = tm.init(); assert(OB_SUCCESS == ret); sstable::ObBlockCacheConf bc_conf; bc_conf.block_cache_memsize_mb = 100; sstable::ObBlockIndexCacheConf bic_conf; bic_conf.cache_mem_size = 100 * 1024 * 1024; ret = UPS.get_sstable_query().init(bc_conf, bic_conf); assert(OB_SUCCESS == ret); ret = sstm.init(root, raid, store); assert(OB_SUCCESS == ret); ret = sstm.reg_observer(&tm); assert(OB_SUCCESS == ret); sstm.load_new(); tm.sstable_scan_finished(3); TableItem *ti = tm.get_active_memtable(); assert(NULL != ti); fill_memtable(ti->get_memtable()); tm.revert_active_memtable(ti); ret = tm.replay_freeze_memtable(SSTableID::get_id(11, 2, 2), SSTableID::get_id(11, 1, 1), 7); assert(OB_SUCCESS == ret); tm.log_table_info(); ObVersionRange vg; vg.start_version_ = 10; vg.end_version_ = 10; vg.border_flag_.set_inclusive_start(); vg.border_flag_.set_inclusive_end(); uint64_t max_version = 0; ObList<ITableEntity*> tlist; ret = tm.acquire_table(vg, max_version, tlist); assert(OB_SUCCESS == ret); assert(10 == max_version); assert(3 == tlist.size()); tm.revert_table(tlist); tm.try_dump_memtable(); ti = tm.get_active_memtable(); fill_memtable(ti->get_memtable()); tm.revert_active_memtable(ti); uint64_t new_version = 0; uint64_t frozen_version = 0; uint64_t clog_id = 9; int64_t time_stamp = 0; bool major_version_changed = false; ret = tm.try_freeze_memtable(0, 0, 0, new_version, frozen_version, clog_id, time_stamp, major_version_changed); assert(OB_SUCCESS == ret); assert(new_version == SSTableID::get_id(12, 1, 1)); assert(frozen_version == SSTableID::get_id(11, 2, 2)); assert(major_version_changed); tm.try_dump_memtable(); vg.start_version_ = 10; vg.end_version_ = 100; vg.border_flag_.set_inclusive_start(); vg.border_flag_.set_inclusive_end(); max_version = 0; ret = tm.acquire_table(vg, max_version, tlist); assert(OB_SUCCESS == ret); assert(12 == max_version); assert(6 == tlist.size()); get_table(tlist); tm.log_table_info(); sstm.log_sstable_info(); tm.try_drop_memtable(true); //tm.try_erase_sstable(true); tm.try_dump_memtable(); system("mv /tmp/*.sst /tmp/trash"); system("mv ~/*.sst ~/trash"); system("cp *.sst /tmp/"); system("cp *.sst ~/"); sstm.umount_store("~"); sstm.check_broken(); system("ln -s ~ data/raid1/store1"); tm.revert_table(tlist); tm.log_table_info(); sstm.log_sstable_info(); ObString dump_dir(2, 2, "./"); tm.dump_memtable2text(dump_dir); tm.destroy(); fprintf(stderr, "MemTableUtils=%ld SSTableUtils=%ld GetParam=%ld SSTableGetter=%ld SSTableScanner=%ld\n", sizeof(MemTableUtils), sizeof(SSTableUtils), sizeof(ObGetParam), sizeof(sstable::ObSSTableGetter), sizeof(sstable::ObSeqSSTableScanner)); }
void TableView::dropEvent(QDropEvent* e) { // QTreeView::dropEvent(e); DropIndicatorPosition position = dropIndicatorPosition(); switch (position) { case QAbstractItemView::OnItem: case QAbstractItemView::OnViewport: default: return; case QAbstractItemView::AboveItem: case QAbstractItemView::BelowItem: break; } TableItem* into = itemAt( e->pos() ); if ( !into || _imp->draggedItems.empty() ) { return; } Q_EMIT aboutToDrop(); int targetRow = into->row(); //We only support full rows assert(selectionBehavior() == QAbstractItemView::SelectRows); ///Remove the items std::map<int, std::map<int, TableItem*> > rowMoved; for (std::list<TableItem*>::iterator it = _imp->draggedItems.begin(); it != _imp->draggedItems.end(); ++it) { rowMoved[(*it)->row()][(*it)->column()] = *it; TableItem* taken = _imp->model->takeItem( (*it)->row(), (*it)->column() ); assert(taken == *it); Q_UNUSED(taken); } /// remove the rows in reverse order so that indexes are still valid for (std::map<int, std::map<int, TableItem*> >::reverse_iterator it = rowMoved.rbegin(); it != rowMoved.rend(); ++it) { _imp->model->removeRows(it->first); if (it->first <= targetRow) { --targetRow; } } _imp->draggedItems.clear(); ///insert back at the correct position int nRows = _imp->model->rowCount(); switch (position) { case QAbstractItemView::AboveItem: { _imp->model->insertRows( targetRow, rowMoved.size() ); break; } case QAbstractItemView::BelowItem: { ++targetRow; if (targetRow > nRows) { targetRow = nRows; } _imp->model->insertRows( targetRow, rowMoved.size() ); break; } default: assert(false); return; } ; int rowIndex = targetRow; for (std::map<int, std::map<int, TableItem*> >::iterator it = rowMoved.begin(); it != rowMoved.end(); ++it, ++rowIndex) { for (std::map<int, TableItem*>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) { _imp->model->setItem(rowIndex, it2->first, it2->second); } } Q_EMIT itemDropped(); } // TableView::dropEvent
KeyValuesTable::KeyValuesTable(HaveKeyValueData * hv, QWidget * parent, bool isReadOnly) : StringTable(((hv == 0) ? 0 : hv->get_n_keys()) + ((isReadOnly) ? 0 : 1), (isReadOnly) ? 2 : 3, parent, isReadOnly) { horizontalHeader()->setLabel(0, TR("Key")); horizontalHeader()->setLabel(1, TR("Value")); if (!isReadOnly) horizontalHeader()->setLabel(2, TR("do")); int index; int sup = 0; if(hv) sup = hv->get_n_keys(); if (isReadOnly) { for (index = 0; index < sup; index += 1) { TableItem * ti; ti = new TableItem(this, Q3TableItem::Never, toUnicode(hv->get_key(index))); ti->setReplaceable(FALSE); setItem(index, 0, ti); QString s = toUnicode(hv->get_value(index)); int n = s.count('\n'); ti = new TableItem(this, Q3TableItem::Never, s); ti->setReplaceable(FALSE); setItem(index, 1, ti); if (n != 0) { // note : adjustRow(index) does nothing setRowHeight(index, rowHeight(index) * (n + 1)); } } } else { props.setAutoDelete(TRUE); QStringList items; for (index = 0; index < sup; index += 1) { QString k = toUnicode(hv->get_key(index)); QString v = toUnicode(hv->get_value(index)); QStringList * psl = props[k]; setText(index, 0, k); if (psl != 0) setItem(index, 1, new ComboItem(this, v, *psl, FALSE)); if ((k.contains(':') == 2) && ProfiledStereotypes::enumerated(k, items)) { psl = new QStringList(items); props.insert(k, psl); setItem(index, 1, new ComboItem(this, v, *psl, FALSE)); } else setItem(index, 1, new MLinesItem(this, v)); setText(index, 2, QString()); setRowStretchable(index, TRUE); } setText(index, 0, QString()); setItem(index, 1, new MLinesItem(this, QString())); setText(index, 2, QString()); setRowStretchable(index, TRUE); } horizontalHeader()->setResizeEnabled(TRUE, 0); //setColumnStretchable (0, TRUE); setColumnStretchable(1, TRUE); if (! isReadOnly) { adjustColumn(2); setColumnStretchable(2, FALSE); } }
void KeyValuesTable::updateThisFromNode(HaveKeyValueData *hv, bool isReadOnly) { if (!isReadOnly) { if(numCols() == 2) insertColumns(2); horizontalHeader()->setLabel(2, TR("do")); } else { if(numCols() == 3) removeColumn(2); } int index; int sup = 0; if(hv) sup = hv->get_n_keys(); int rowCount = numRows(); for (index = rowCount - 1; index > sup; index -= 1) removeRow(index); if (isReadOnly) { for (index = 0; index < sup; index += 1) { TableItem * tiKey = nullptr; TableItem * tiValue = nullptr; QString s = toUnicode(hv->get_value(index)); int n = s.count('\n'); if(index == numRows() || numRows() == 0) { tiKey = new TableItem(this, Q3TableItem::Never, toUnicode(hv->get_key(index))); tiValue = new TableItem(this, Q3TableItem::Never, s); setItem(index, 0, tiKey); setItem(index, 1, tiValue); } else { tiKey = dynamic_cast<TableItem*>(item(index, 0)); tiKey->setText(hv->get_key(index)); tiValue = dynamic_cast<TableItem*>(item(index, 1)); tiValue->setText(s); } tiKey->setReplaceable(FALSE); tiValue->setReplaceable(FALSE); if (n != 0) { // note : adjustRow(index) does nothing setRowHeight(index, rowHeight(index) * (n + 1)); } } } else { props.setAutoDelete(TRUE); QStringList items; for (index = 0; index < sup; index += 1) { QString k = toUnicode(hv->get_key(index)); QString v = toUnicode(hv->get_value(index)); QStringList * psl = props[k]; setText(index, 0, k); if (psl != 0) setItem(index, 1, new ComboItem(this, v, *psl, FALSE)); if ((k.contains(':') == 2) && ProfiledStereotypes::enumerated(k, items)) { psl = new QStringList(items); props.insert(k, psl); setItem(index, 1, new ComboItem(this, v, *psl, FALSE)); } else setItem(index, 1, new MLinesItem(this, v)); setText(index, 2, QString()); setRowStretchable(index, TRUE); } if(index == numRows()) insertRows(numRows()); setText(index, 0, QString()); setItem(index, 1, new MLinesItem(this, QString())); setText(index, 2, QString()); setRowStretchable(index, TRUE); } horizontalHeader()->setResizeEnabled(TRUE, 0); //setColumnStretchable (0, TRUE); setColumnStretchable(1, TRUE); if (! isReadOnly) { adjustColumn(2); setColumnStretchable(2, FALSE); } }