Exemplo n.º 1
0
void AnalysisController::slotDatasetSelected(const QString& datasetS)
{
    AnalysisView *analysisView = qobject_cast<AnalysisView*>(view);
    analysisView->removeResultMessageWidget();
    QSortFilterProxyModel *proxyModel = qobject_cast<QSortFilterProxyModel*>(analysisView->getSubjectsTable()->model());
    AnalysisSubjectsTableModel *model = qobject_cast<AnalysisSubjectsTableModel*>(proxyModel->sourceModel());

    //QSortFilterProxyModel *proxyModelP = qobject_cast<QSortFilterProxyModel*>(analysisView->getProtocolsTable()->model());
    AnalysisProtocolsTableModel *protocolModel = qobject_cast<AnalysisProtocolsTableModel*>(analysisView->getProtocolsTable()->model());

    if(datasetS != Utils::ROMEO_SELECT_DATASET) {
        clearData();

        dataset = datasetS;

        model->loadModelData(dataset);

        DatasetDAO pDao;
        protocolOfDataset = pDao.getProtocolsOfDataset(dataset);
        protocolModel->loadModelData(protocolOfDataset);
    }
    else {
        clearData();
        model->resetModelData();
        protocolModel->resetModelData();
    }
}
Exemplo n.º 2
0
void ContactsTable::onDeleteContact()
  {
  //remove selected contacts from inbox model (and database)
  QSortFilterProxyModel* model = dynamic_cast<QSortFilterProxyModel*>(ui->contact_table->model());
  //model->setUpdatesEnabled(false);
  QItemSelectionModel*   selection_model = ui->contact_table->selectionModel();
  QModelIndexList        sortFilterIndexes = selection_model->selectedRows();
  if (sortFilterIndexes.count() == 0)
    return;
  if (QMessageBox::question(this, "Delete Contact", "Are you sure you want to delete this contact?") == QMessageBox::Button::No)
    return;
  QModelIndexList        indexes;
  foreach(QModelIndex sortFilterIndex, sortFilterIndexes)
    indexes.append(model->mapToSource(sortFilterIndex));
  qSort(indexes);
  auto sourceModel = model->sourceModel();
  for (int i = indexes.count() - 1; i > -1; --i)
    {
    auto contact_id = ((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).wallet_index;
    sourceModel->removeRows(indexes.at(i).row(), 1);    
    Q_EMIT contactDeleted(contact_id); //emit signal so that ContactGui is also deleted
    }
  //model->setUpdatesEnabled(true);

  //TODO Remove fullname/bitname for deleted contacts from QCompleter
  }
Exemplo n.º 3
0
void EditSolutionDialog::accept()
{
    QVariant bw = ui->bw->property("wine");
    QModelIndexList l = mWineModel->match(mWineModel->index(0, 0), Qt::DisplayRole, bw, -1, Qt::MatchFixedString);
    bw = l.first().data(PackageModel::IdRole);
    QVariant aw = ui->aw->property("wine");
    l = mWineModel->match(mWineModel->index(0, 0), Qt::DisplayRole, aw, -1, Qt::MatchFixedString);
    aw = l.first().data(PackageModel::IdRole);
    SolutionModel::IntList bp;
    QAbstractItemModel *bpm = ui->bp->model();
    for (int i = 0, count = bpm->rowCount(); i < count; ++i)
        bp.append(bpm->index(i, 0).data(PackageModel::IdRole).toInt());
    SolutionModel::IntList ap;
    QAbstractItemModel *apm = ui->ap->model();
    for (int i = 0, count = apm->rowCount(); i < count; ++i)
        ap.append(apm->index(i, 0).data(PackageModel::IdRole).toInt());
    QModelIndex index = mModel->index(mRow, 0);
    QMap<int, QVariant> data;
    data.insert(SolutionModel::BWRole, bw);
    data.insert(SolutionModel::AWRole, aw);
    data.insert(SolutionModel::BPRole, QVariant::fromValue(bp));
    data.insert(SolutionModel::APRole, QVariant::fromValue(ap));
    QSortFilterProxyModel *sm = static_cast<QSortFilterProxyModel *>(mModel);
    sm->sourceModel()->setItemData(sm->mapToSource(index), data);
    QDialog::accept();
}
void mySqlRelationalDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
    if (!index.isValid())
        return;

    QSqlRelationalTableModel *sqlModel = qobject_cast<QSqlRelationalTableModel *>(model);
    QSortFilterProxyModel* proxyModel = NULL;
    if (!sqlModel )
    {
        proxyModel = qobject_cast<QSortFilterProxyModel *>(model);
        if (proxyModel)
             sqlModel = qobject_cast<QSqlRelationalTableModel *>(proxyModel->sourceModel());
    }

    QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
    QComboBox *combo = qobject_cast<QComboBox *>(editor);
    if (!sqlModel || !childModel || !combo) {
        QItemDelegate::setModelData(editor, model, index);
        return;
    }

    int currentItem = combo->currentIndex();
    int childColIndex = childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn());
    int childEditIndex = childModel->fieldIndex(sqlModel->relation(index.column()).indexColumn());


    if (proxyModel) {
        proxyModel->setData(index, childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole), Qt::DisplayRole);
        proxyModel->setData(index, childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole), Qt::EditRole);
    } else {
        sqlModel->setData(index, childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole), Qt::DisplayRole);
        sqlModel->setData(index, childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole), Qt::EditRole);
    }
}
Exemplo n.º 5
0
QAbstractItemModel* MainWindow::rootModel(QAbstractItemModel *model)
{
    QSortFilterProxyModel *proxyModel = 0;

    while ((proxyModel = qobject_cast<QSortFilterProxyModel*>(model)))
        model = proxyModel->sourceModel();
    return model;
}
Exemplo n.º 6
0
ModelEditDialog::ModelEditDialog(QAbstractItemModel * model, IModelEditPanel * panel,
		Logbook::Ptr logbook, const QModelIndex & index, QWidget * parent)
	: QDialog(parent), m_model(model), m_panel(panel), m_logbook(logbook)
{
	m_mapper = new QDataWidgetMapper(this);
	m_mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
	m_mapper->setModel(m_model);

	QAbstractItemDelegate * d = m_panel->createDelegate(this);
	if (d != NULL)
		m_mapper->setItemDelegate(d);
	else
		m_mapper->setItemDelegate(new CustomDelegate(this));

	m_btnPrev = new QPushButton(tr("Previous"));
	m_btnNext = new QPushButton(tr("Next"));

	//FIXME: HAX so that the search box in MapLocationEditor gets a
	//  returnPressed() event instead of submitting the dialog.
	m_btnPrev->setDefault(false);
	m_btnPrev->setAutoDefault(false);
	m_btnNext->setDefault(false);
	m_btnNext->setAutoDefault(false);

	QHBoxLayout * hbox = new QHBoxLayout();
	hbox->addStretch();
	hbox->addWidget(m_btnPrev);
	hbox->addWidget(m_btnNext);

	QWidget * pnl_widget = dynamic_cast<QWidget *>(m_panel);
	assert(pnl_widget != NULL);

	QVBoxLayout * vbox = new QVBoxLayout();
	vbox->addWidget(pnl_widget);
	vbox->addLayout(hbox);

	setLayout(vbox);

	QAbstractItemModel * m = model;
	QSortFilterProxyModel * p = dynamic_cast<QSortFilterProxyModel *>(m);
	while (p != NULL)
	{
		m = p->sourceModel();
		p = dynamic_cast<QSortFilterProxyModel *>(m);
	}

	CustomTableModel * tm = dynamic_cast<CustomTableModel *>(m);
	if (tm)
		tm->bind(m_logbook->session());

	m_panel->bind(m_logbook->session(), m_mapper);
	connect(m_btnNext, SIGNAL(clicked()), m_mapper, SLOT(toNext()));
	connect(m_btnPrev, SIGNAL(clicked()), m_mapper, SLOT(toPrevious()));
	connect(m_mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(mapperIndexChanged(int)));

	if (index.isValid())
		m_mapper->setCurrentIndex(index.row());
}
Exemplo n.º 7
0
void FilterOptions::setDefaultEngine(int index)
{
  QSortFilterProxyModel* proxy = qobject_cast<QSortFilterProxyModel*>(m_dlg.cmbDefaultEngine->model());
  if (index == -1)
    index = proxy->rowCount()-1;//"None" is the last

  const QModelIndex modelIndex = proxy->mapFromSource(proxy->sourceModel()->index(index,0));
  m_dlg.cmbDefaultEngine->setCurrentIndex(modelIndex.row());
  m_dlg.cmbDefaultEngine->view()->setCurrentIndex(modelIndex);  //TODO: remove this when Qt bug is fixed
}
Exemplo n.º 8
0
void RepoTreeView::syncRepoImmediately()
{
    LocalRepo repo = qvariant_cast<LocalRepo>(sync_now_action_->data());

    seafApplet->rpcClient()->syncRepoImmediately(repo.id);

    QSortFilterProxyModel *proxy = (QSortFilterProxyModel *)model();
    RepoTreeModel *tree_model = (RepoTreeModel *)(proxy->sourceModel());
    tree_model->updateRepoItemAfterSyncNow(repo.id);
}
Exemplo n.º 9
0
void Mailbox::onMarkAsUnreadMail()
{
  QItemSelectionModel* selection_model = ui->inbox_table->selectionModel();
  QModelIndexList      indexes = selection_model->selectedRows();
  QSortFilterProxyModel* model = dynamic_cast<QSortFilterProxyModel*>(ui->inbox_table->model());
  MailboxModel* sourceModel = dynamic_cast<MailboxModel*>(model->sourceModel());
  foreach(QModelIndex index, indexes)
  {
    QModelIndex mapped_index = model->mapToSource(index);
    sourceModel->markMessageAsUnread(mapped_index);
  }
Exemplo n.º 10
0
void PropertiesTab::propertyContextMenu(const QPoint &pos)
{
  const QModelIndex index = m_ui->propertyView->indexAt(pos);
  if (!index.isValid()) {
    return;
  }

  const int actions = index.data(PropertyModel::ActionRole).toInt();
  if (actions == PropertyModel::NoAction) {
    return;
  }

  QMenu contextMenu;
  if (actions & PropertyModel::Delete) {
    QAction *action = contextMenu.addAction(tr("Remove"));
    action->setData(PropertyModel::Delete);
  }
  if (actions & PropertyModel::Reset) {
    QAction *action = contextMenu.addAction(tr("Reset"));
    action->setData(PropertyModel::Reset);
  }
  if (actions & PropertyModel::NavigateTo) {
    QAction *action =
      contextMenu.addAction(tr("Show in %1").
        arg(index.data(PropertyModel::AppropriateToolRole).toString()));
    action->setData(PropertyModel::NavigateTo);
  }

  if (QAction *action = contextMenu.exec(m_ui->propertyView->viewport()->mapToGlobal(pos))) {
    const QString propertyName = index.sibling(index.row(), 0).data(Qt::DisplayRole).toString();
    switch (action->data().toInt()) {
      case PropertyModel::Delete:
        m_interface->setProperty(propertyName, QVariant());
        break;
      case PropertyModel::Reset:
        m_interface->resetProperty(propertyName);
        break;
      case PropertyModel::NavigateTo:
        QSortFilterProxyModel *proxy =
          qobject_cast<QSortFilterProxyModel*>(m_ui->propertyView->model());
        QModelIndex sourceIndex = index;
        while (proxy) {
          sourceIndex = proxy->mapToSource(sourceIndex);
          proxy = qobject_cast<QSortFilterProxyModel*>(proxy->sourceModel());
        }
        m_interface->navigateToValue(sourceIndex.row());
        break;
    }
  }
}
Exemplo n.º 11
0
void Mailbox::onDoubleClickedItem(QModelIndex index)
  {
  QSortFilterProxyModel* model = dynamic_cast<QSortFilterProxyModel*>(ui->inbox_table->model());
  auto                   sourceModelIndex = model->mapToSource(index);
  auto                   sourceModel = dynamic_cast<MailboxModel*>(model->sourceModel());

  IMailProcessor::TPhysicalMailMessage decodedMsg;
  IMailProcessor::TStoredMailMessage encodedMsg;
  sourceModel->getMessageData(sourceModelIndex, &encodedMsg, &decodedMsg);
  MailEditorMainWindow* mailEditor = new MailEditorMainWindow(_mainWindow,
    sourceModel->getAddressBookModel(), *_mailProcessor, _type == Drafts);
  mailEditor->LoadMessage(this, encodedMsg, decodedMsg, MailEditorMainWindow::TLoadForm::Draft);
  mailEditor->show();
  }
Exemplo n.º 12
0
void LibraryWidget::connectModelSignals(QLibraryTreeWidgetItem *root, Library *p, BibGlobals::ResourceSelection resourceType)
{
    QSortFilterProxyModel *viewModel = p->viewModel(resourceType);
    if(!viewModel)
        return;

    NepomukModel *nm = qobject_cast<NepomukModel *>(viewModel->sourceModel());
    if(!nm)
        return;

    connect(nm, SIGNAL(queryStarted()), root, SLOT(startQueryFetch()));
    connect(nm, SIGNAL(queryFinished()), root, SLOT(stopQueryFetch()));
    connect(nm, SIGNAL(dataSizeChaged(int)), root, SLOT(updateItemCount(int)));
}
Exemplo n.º 13
0
QStandardItem* RepoTreeView::getRepoItem(const QModelIndex &index) const
{
    if (!index.isValid()) {
        return NULL;
    }
    QSortFilterProxyModel *proxy = (QSortFilterProxyModel *)model();
    RepoTreeModel *tree_model = (RepoTreeModel *)(proxy->sourceModel());
    QStandardItem *item = tree_model->itemFromIndex(proxy->mapToSource(index));

    if (item->type() != REPO_ITEM_TYPE &&
        item->type() != REPO_CATEGORY_TYPE) {
        return NULL;
    }
    return item;
}
Exemplo n.º 14
0
void ContactsTable::onDeleteContact()
{
   //remove selected contacts from inbox model (and database)
   QSortFilterProxyModel* model = dynamic_cast<QSortFilterProxyModel*>(ui->contact_table->model());
   //model->setUpdatesEnabled(false);
   QItemSelectionModel* selection_model = ui->contact_table->selectionModel();
   QModelIndexList sortFilterIndexes = selection_model->selectedRows();
   QModelIndexList indexes;
   foreach(QModelIndex sortFilterIndex,sortFilterIndexes)
     indexes.append(model->mapToSource(sortFilterIndex));
   qSort(indexes);
   auto sourceModel = model->sourceModel();
   for(int i = indexes.count() - 1; i > -1; --i)
       sourceModel->removeRows(indexes.at(i).row(),1);
   //model->setUpdatesEnabled(true);   

   //TODO Remove fullname/bitname for deleted contacts from QCompleter
}
Exemplo n.º 15
0
void CompetitorList::setClubId(int id)
{
    m_clubId = id;
    CompetitorTableModel *model = dynamic_cast<CompetitorTableModel *>(ui->competitorTable->model());

    if(!model)
    {
        QSortFilterProxyModel* proxyModel = dynamic_cast<QSortFilterProxyModel *>(ui->competitorTable->model());
        if(proxyModel)
        {
            model = dynamic_cast<CompetitorTableModel*>(proxyModel->sourceModel());
        }
    }
    if(model)
    {
        model->setParentId(id);
    }
    ui->competitorTable->reset();
}
Exemplo n.º 16
0
void ContactsTable::onDeleteContact()
  {
  //remove selected contacts from inbox model (and database)
  QSortFilterProxyModel* model = dynamic_cast<QSortFilterProxyModel*>(ui->contact_table->model());
  //model->setUpdatesEnabled(false);
  QItemSelectionModel*   selection_model = ui->contact_table->selectionModel();
  QModelIndexList        sortFilterIndexes = selection_model->selectedRows();
  if (sortFilterIndexes.count() == 0)
    return;
  if (QMessageBox::question(this, tr("Delete Contact"), tr("Are you sure you want to delete selected contact(s)?")) == QMessageBox::Button::No)
    return;
  QModelIndexList        indexes;
  for(const QModelIndex& sortFilterIndex : sortFilterIndexes)
    indexes.append(model->mapToSource(sortFilterIndex));
  qSort(indexes);
  auto sourceModel = model->sourceModel();
  auto app = bts::application::instance();
  auto profile = app->get_profile();

  for (int i = indexes.count() - 1; i > -1; --i)
  {
    auto contact_id = ((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).wallet_index;
    if(profile->isIdentityPresent(((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).dac_id_string))
    {
      auto priv_key = profile->get_keychain().get_identity_key(((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).dac_id_string);
      app->remove_receive_key(priv_key);
      profile->removeIdentity(((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).dac_id_string);

      /// notify identity observers
      IdentityObservable::getInstance().notify();
    }
    sourceModel->removeRows(indexes.at(i).row(), 1);
    Q_EMIT contactDeleted(contact_id); //emit signal so that ContactGui is also deleted
  }
  //model->setUpdatesEnabled(true);
  //TODO Remove fullname/bitname for deleted contacts from QCompleter

  qSort(sortFilterIndexes);
  selectNextRow(sortFilterIndexes.takeLast().row(), indexes.count());
  }
Exemplo n.º 17
0
void NewDatasetController::slotGroupSelected(const QModelIndex &index)
{
    NewDatasetView *newDatasetView = qobject_cast<NewDatasetView*>(view);

    if(group.isEmpty() || group!=newDatasetView->getGroupsTable()->model()->index(index.row(), 0 ,index).data().toString()) {
        newDatasetView->resetInfo();

        group = newDatasetView->getGroupsTable()->model()->index(index.row(), 0 ,index).data().toString();
        QString type = newDatasetView->getGroupsTable()->model()->index(index.row(), 1 ,index).data().toString();

        GroupDAO *db = new GroupDAO();
        GroupOfSubject* groupItem = db->getGroupByName(group);
        QVector<ASubject*> subjects = groupItem->getAllSubjects();
        QString txt = "Subjects in the Group "+group+" ("+QString::number(subjects.size())+"):\n";
        for(int i=0; i<subjects.size(); ++i) {
            txt.append(subjects.at(i)->getName()+"\n");
        }
        newDatasetView->setGroupInfo(txt);

        QSortFilterProxyModel *proxyModel = qobject_cast<QSortFilterProxyModel*>(newDatasetView->getProtocolsTable()->model());
        DatasetProtocolTableModel *model = qobject_cast<DatasetProtocolTableModel*>(proxyModel->sourceModel());
        model->loadModelData(type);
    }
}
Exemplo n.º 18
0
void RepoTreeView::updateRepoActions()
{
    RepoItem *item = NULL;
    QItemSelection selected = selectionModel()->selection();
    QModelIndexList indexes = selected.indexes();
    if (indexes.size() != 0) {
        const QModelIndex& index = indexes.at(0);
        QSortFilterProxyModel *proxy = (QSortFilterProxyModel *)model();
        RepoTreeModel *tree_model = (RepoTreeModel *)(proxy->sourceModel());
        QStandardItem *it = tree_model->itemFromIndex(proxy->mapToSource(index));
        if (it && it->type() == REPO_ITEM_TYPE) {
            item = (RepoItem *)it;
        }
    }

    if (!item) {
        // No repo item is selected
        download_action_->setEnabled(false);
        download_toolbar_action_->setEnabled(false);
        sync_now_action_->setEnabled(false);
        open_local_folder_action_->setEnabled(false);
        open_local_folder_toolbar_action_->setEnabled(false);
        unsync_action_->setEnabled(false);
        resync_action_->setEnabled(false);
        toggle_auto_sync_action_->setEnabled(false);
        view_on_web_action_->setEnabled(false);
        show_detail_action_->setEnabled(false);
        return;
    }

    LocalRepo r;
    seafApplet->rpcClient()->getLocalRepo(item->repo().id, &r);
    item->setLocalRepo(r);

    if (item->localRepo().isValid()) {
        const LocalRepo& local_repo = item->localRepo();
        download_action_->setEnabled(false);
        download_toolbar_action_->setEnabled(false);

        sync_now_action_->setEnabled(true);
        sync_now_action_->setData(QVariant::fromValue(local_repo));

        open_local_folder_action_->setData(QVariant::fromValue(local_repo));
        open_local_folder_action_->setEnabled(true);
        open_local_folder_toolbar_action_->setData(QVariant::fromValue(local_repo));
        open_local_folder_toolbar_action_->setEnabled(true);

        unsync_action_->setData(QVariant::fromValue(local_repo));
        unsync_action_->setEnabled(true);

        resync_action_->setData(QVariant::fromValue(local_repo));
        resync_action_->setEnabled(true);

        toggle_auto_sync_action_->setData(QVariant::fromValue(local_repo));
        toggle_auto_sync_action_->setEnabled(true);

        QIcon q_pause = ::getMenuIconSet(":/images/pause-gray.png");
        QIcon q_play = ::getMenuIconSet(":/images/play-gray.png");
        if (local_repo.auto_sync) {
            toggle_auto_sync_action_->setText(tr("Disable auto sync"));
            toggle_auto_sync_action_->setToolTip(tr("Disable auto sync"));
            toggle_auto_sync_action_->setIcon(q_pause);
        } else {
            toggle_auto_sync_action_->setText(tr("Enable auto sync"));
            toggle_auto_sync_action_->setToolTip(tr("Enable auto sync"));
            toggle_auto_sync_action_->setIcon(q_play);
        }

    } else {
        if (item->repoDownloadable()) {
            download_action_->setEnabled(true);
            download_toolbar_action_->setEnabled(true);
            download_action_->setData(QVariant::fromValue(item->repo()));
            download_toolbar_action_->setData(QVariant::fromValue(item->repo()));
        } else {
            download_action_->setEnabled(false);
            download_toolbar_action_->setEnabled(false);
        }

        sync_now_action_->setEnabled(false);

        open_local_folder_action_->setEnabled(false);
        open_local_folder_toolbar_action_->setEnabled(false);
        unsync_action_->setEnabled(false);
        resync_action_->setEnabled(false);
        toggle_auto_sync_action_->setEnabled(false);
    }

    view_on_web_action_->setEnabled(true);
    view_on_web_action_->setData(item->repo().id);
    show_detail_action_->setEnabled(true);
    show_detail_action_->setData(QVariant::fromValue(item->repo()));

    if (item->cloneTask().isCancelable()) {
        cancel_download_action_->setEnabled(true);
        cancel_download_action_->setData(QVariant::fromValue(item->repo()));
    } else {
        cancel_download_action_->setEnabled(false);
    }
    emit dataChanged(indexes.at(0), indexes.at(0));
}
Exemplo n.º 19
0
void ResourceTableWidget::switchView(BibGlobals::ResourceSelection selection, BibGlobals::BibEntryType filter, Library *p)
{
    m_selection = selection;

    PublicationFilterModel * pfm = qobject_cast<PublicationFilterModel *>(p->viewModel(selection));
    if(pfm) {
        pfm->setResourceFilter(filter);
    }
    else {
        SeriesFilterModel * pfm = qobject_cast<SeriesFilterModel *>(p->viewModel(selection));
        if(pfm) {
            pfm->setResourceFilter(BibGlobals::SeriesType(filter));
        }
    }

    // if we only need to change the filter, forget the rest after this check
    QAbstractItemModel *oldModel = m_documentView->model();
    QAbstractItemModel *newModel = p->viewModel(selection);
    if(!newModel)
        return;
    if(oldModel == newModel)
        return;

    if(m_documentView->selectionModel()) {
        disconnect(m_documentView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
                this, SLOT(selectedResource(QItemSelection,QItemSelection)));
    }

    switch(m_selection) {
    case BibGlobals::Resource_Event:
    case BibGlobals::Resource_Series:
        m_documentView->setItemDelegateForColumn(3, m_htmlDelegate);
        break;
    default:
        m_documentView->setItemDelegateForColumn(3, NULL);
    }

    m_documentView->setWordWrap(true);
    m_documentView->setModel(p->viewModel(selection));

    //load settings for visible/hidden columns
    KConfig config;
    QString group = QLatin1String("TableView");
    group.append((int)m_selection);
    KConfigGroup tableViewGroup( &config, group );

    // go through all header elements and apply last known visibility / size status
    // also add each header name to the search combobox for selection
    QString curSearchSelection =  m_searchSelection->currentText();
    m_searchSelection->clear();
    m_searchSelection->addItem(i18n("all entries"), -1); //additem NAME, TABLEHEADERINDEX
    QHeaderView *hv = m_documentView->horizontalHeader();
    int columnCount = m_documentView->model()->columnCount();

    NepomukModel *nm = qobject_cast<NepomukModel *>(newModel);
    if(!nm) {
        QSortFilterProxyModel *qsf = qobject_cast<QSortFilterProxyModel *>(newModel);
        if(qsf) {
            nm = qobject_cast<NepomukModel *>(qsf->sourceModel());
        }
    }

    for(int i=0; i < columnCount; i++) {
        // hidden status
        QString keyHidden = QLatin1String("hidden_") + QString::number(i);
        bool hidden = tableViewGroup.readEntry( keyHidden, false );

        hv->setSectionHidden(i, hidden);

        QString headerName = m_documentView->model()->headerData(i,Qt::Horizontal).toString();
        if(!headerName.isEmpty()) {
            m_searchSelection->addItem(headerName, i);
        }

        // size status
        int sectionSize = 50;
        QString keySize = QLatin1String("size_") + QString::number(i);
        int size = tableViewGroup.readEntry( keySize, -1 );
        if(size > 4) {
            sectionSize = size;
        }
        else {
            if(nm) {
                sectionSize = nm->defaultSectionSize(i);
            }
        }

        hv->resizeSection(i,sectionSize);
    }

    //try to be clever and set the same searchElement as before, if it exist
    int lastSelection = m_searchSelection->findText(curSearchSelection);
    if(lastSelection != -1)
        m_searchSelection->setCurrentIndex(lastSelection);

    hv->setResizeMode(QHeaderView::Interactive);

    m_documentView->setSelectionMode(QAbstractItemView::ExtendedSelection);

    connect(m_documentView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SLOT(selectedResource(QItemSelection,QItemSelection)));

    m_documentView->selectRow(0);

    QList<int> fixedWithList = nm->fixedWidthSections();
    foreach(int section, fixedWithList) {
        hv->setResizeMode(section, QHeaderView::Fixed);
    }
Exemplo n.º 20
0
QAbstractItemModel *ModelDescriptorListWidget::model() const
{
    QSortFilterProxyModel *proxyModel = qobject_cast<QSortFilterProxyModel *>(QTreeView::model());
    return proxyModel->sourceModel();
}
Exemplo n.º 21
0
/*
 * 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;
}