Ejemplo n.º 1
2
void ViewerModel::processParsedData(ParseJobFiles* parser)
{
   Data::Bank& bank(parser->data());
   if (bank.isEmpty()) return;

   QString name(parser->name());

   // Determine if we need to replace an existing Molecule in the Model View.
   bool overwrite(parser->flags()  & ParseJobFiles::Overwrite);
   bool makeActive(parser->flags() & ParseJobFiles::MakeActive);
   bool addStar(parser->flags()    & ParseJobFiles::AddStar);
   bool found(false);

   Layer::Molecule* molecule(newMolecule());
   molecule->setCheckState(Qt::Unchecked);
   molecule->setText(name);
   molecule->appendData(bank);
   if (addStar) molecule->setIcon(QIcon(":/resources/icons/Favourites.png"));

   QStandardItem* child;
   QStandardItem* root(invisibleRootItem());

   void* moleculePointer(parser->moleculePointer());

   if (overwrite && moleculePointer) {
      for (int row = 0; row < root->rowCount(); ++row) {
          child = root->child(row);
          if (child->text() == name) {
             Layer::Base* base = QVariantPointer<Layer::Base>::toPointer(child->data());
             Layer::Molecule* mol = qobject_cast<Layer::Molecule*>(base);

             if (mol && mol == moleculePointer) {
                molecule->setCheckState(mol->checkState());
                // makeActive = makeActive || (mol->checkState() == Qt::Checked);
                // This may result in a memory leak, but we need the Molecule
                // to remain lying around in case of an undo action.
                takeRow(row);
                insertRow(row, molecule);
                found = true;
                qDebug() << "found existing molecule";
                break;
             }
          }
      }
   }

   // If we didn't find an existing Molecule to overwrite, we check the last
   // Molecule on the list and if that is still 'Untitled' and empty, use it.
   if (!found) {
      child = root->child(root->rowCount()-1);
      if (child->text() == DefaultMoleculeName && !child->hasChildren()) {
         Layer::Base* base = QVariantPointer<Layer::Base>::toPointer(child->data());
         Layer::Molecule* mol = qobject_cast<Layer::Molecule*>(base);
         makeActive = makeActive || (mol->checkState() == Qt::Checked);
         // This may result in a memory leak, but we need the Molecule
         // to remain lying around in case of an undo action.
         takeRow(child->row());
      }

      Command::AddMolecule* cmd = new Command::AddMolecule(molecule, root);
      postCommand(cmd);
   }

   if (makeActive) {
      forAllMolecules(boost::bind(&Layer::Molecule::setCheckState, _1, Qt::Unchecked));
      molecule->setCheckState(Qt::Checked);
      sceneRadiusChanged(sceneRadius());
      changeActiveViewerMode(Viewer::Manipulate);
   }

   fileOpened(parser->filePath());
}
Ejemplo n.º 2
0
Qt::ItemFlags Project::flags(const QModelIndex& index) const
{
    if (index==editable) {
        return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
    } else {
        QStandardItem* item = itemFromIndex(index);
        if (!item->hasChildren() && (item==mzn || item==dzn || item==other) )
            return Qt::ItemIsSelectable;
        return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
    }
}
Ejemplo n.º 3
0
QStandardItem* ProjectSelectionPage::getCurrentItem() const
{
    QStandardItem* item = m_templatesModel->itemFromIndex( m_listView->currentIndex() );
    if ( item && item->hasChildren() )
    {
        const int currect = ui->templateType->currentIndex();
        const QModelIndex idx = m_templatesModel->index( currect, 0, ui->templateType->rootModelIndex() );
        item = m_templatesModel->itemFromIndex(idx);
    }
    return item;
}
Ejemplo n.º 4
0
void Switcher::walkTree(QStandardItem* item_, const QString& text_){
	for(int i = 0; i < item_->rowCount(); i++) {
		QStandardItem* item = item_->child(i);
		if(item->hasChildren())
			walkTree(item, text_);
		else{
			bool hide = !item->text().contains(text_, Qt::CaseInsensitive);
			QModelIndex index = _model->indexFromItem(item);
			switcherList->setRowHidden(index.row(), index.parent(), hide);
		}
	}
}
Ejemplo n.º 5
0
void NotesItemView::iterate(QStandardItem *item = 0)
{
    //DEBUG_FUNC_NAME
    if(item == NULL)
        return;
    const QString parentID = item->data().toString();
    for(int i = 0; i < item->rowCount(); ++i) {
        QStandardItem *m = item->child(i);
        m_notes->setRef(m->data().toString(), "parent", parentID);
        if(m->hasChildren())
            iterate(m);
    }
}
Ejemplo n.º 6
0
/* Recursively traverse all the child items and record every expanded item */
void
mail_listview::collect_expansion_states(QStandardItem* item,
					QSet<QStandardItem*>& expanded_set)
{
  QStandardItem* citem;
  int row=0;
  while ((citem=item->child(row,0))!=NULL) {
    if (isExpanded(citem->index())) {
      expanded_set.insert(citem);
    }
    if (citem->hasChildren()) {
      collect_expansion_states(citem, expanded_set);
    }
    row++;
  }
}
Ejemplo n.º 7
0
void PreferencesItemDelegate::paint(QPainter *pPainter,
                                    const QStyleOptionViewItem &pOption,
                                    const QModelIndex &pIndex) const
{
    // Paint the item as normal, if it is selectable, or bold, if it is a
    // category

    QStandardItem *pluginItem = qobject_cast<const QStandardItemModel *>(pIndex.model())->itemFromIndex(pIndex);

    QStyleOptionViewItem option(pOption);

    initStyleOption(&option, pIndex);

    if (pluginItem->hasChildren()) {
        option.font.setBold(true);
    }

    QStyledItemDelegate::paint(pPainter, option, pIndex);
}
Ejemplo n.º 8
0
void CodeEditor::select(QStandardItem *parent,const QStandardItem *sourceParent)
{
    for (int i=0; i<sourceParent->rowCount(); ++i)
    {
       QStandardItem *child = sourceParent->child(i);

       QStandardItem *item = child->QStandardItem::clone();
       item->setToolTip(child->toolTip());
       assert(item);

       QString text = child->data(Item::DescriptionRole).toStringList().join('\n');
       QStandardItem *desitem = new QStandardItem(text);
       desitem->setForeground(Qt::darkGreen);
       desitem->setEditable(false);

       parent->appendRow(QList<QStandardItem *>() << item << desitem);

       if(child->hasChildren())
           select(item,child);
    }
}
Ejemplo n.º 9
0
void InstrumentTree::patchDoubleClicked(QModelIndex index)/*{{{*/
{
    if(!m_instrument)
        return;
    QStandardItem* nItem = _patchModel->itemFromIndex(index);

    if(nItem->hasChildren()) //Its a folder perform expand collapse
    {
        setExpanded(index, !isExpanded(index));
    }
    else
    {
        int row = nItem->row();
        QStandardItem* p = nItem->parent();
        QStandardItem *idItem;
        QString pg = "";
        if(p && p != _patchModel->invisibleRootItem() && p->columnCount() == 2)
        {
            //We are in group mode
            idItem = p->child(row, 1);
            pg = p->text();
        }
        else
        {
            idItem = _patchModel->item(row, 1);
        }
        int id = idItem->text().toInt();
        QString name = nItem->text();
        //printf("Found patch Name: %s - ID: %d\n",name.toUtf8().constData(), id);

        if (!name.isEmpty() && id >= 0)
        {
            emit patchSelected(id, name);
            if(m_popup)
            {
                hide();
            }
        }
    }
}/*}}}*/
Ejemplo n.º 10
0
void Project::removeFile(const QString &fileName)
{
    if (fileName.isEmpty())
        return;
    if (!_files.contains(fileName)) {
        qDebug() << "Internal error: file " << fileName << " not in project";
        return;
    }
    setModified(true, true);
    QModelIndex index = _files[fileName];
    _files.remove(fileName);
    QStandardItem* cur = itemFromIndex(index);
    while (cur->parent() != NULL && cur->parent() != invisibleRootItem() && !cur->hasChildren()) {
        int row = cur->row();
        cur = cur->parent();
        cur->removeRow(row);
    }
    QFileInfo fi(fileName);
    if (fi.fileName()=="_coursera") {
        delete _courseraProject;
        _courseraProject = NULL;
        ui->actionSubmit_to_Coursera->setVisible(false);
    }
}
Ejemplo n.º 11
0
QString Project::fileAtIndex(const QModelIndex &index)
{
    QStandardItem* item = itemFromIndex(index);
    if (item==NULL || item->hasChildren())
        return "";
    QString fileName;
    while (item != NULL && item->parent() != NULL && item->parent() != invisibleRootItem() ) {
        if (fileName.isEmpty())
            fileName = item->text();
        else
            fileName = item->text()+"/"+fileName;
        item = item->parent();
    }
    if (fileName.isEmpty())
        return "";
    if (!projectRoot.isEmpty()) {
        fileName = QFileInfo(projectRoot).absolutePath()+"/"+fileName;
    }
    QFileInfo fi(fileName);
    if (fi.canonicalFilePath().isEmpty())
        fileName = "/"+fileName;
    fileName = QFileInfo(fileName).canonicalFilePath();
    return fileName;
}
void DayAvailabilityModel::addAvailability(const DayAvailability &availability)
{
    Q_ASSERT(d->m_UserCalendar);
    Q_ASSERT(IN_RANGE(availability.weekDay(), Qt::Monday, Qt::Sunday));

    d->m_UserCalendar->addAvailabilities(availability);

    // find the day item
    QStandardItem *dayItem = 0;
    for(int i = 0; i < invisibleRootItem()->rowCount(); ++i) {
        if (invisibleRootItem()->child(i)->data(WeekDayRole).toInt() == availability.weekDay()) {
            dayItem = invisibleRootItem()->child(i);
            break;
        }
    }

    // at this point there MUST be a valid dayItem. If not, something really bad happened.
    Q_ASSERT(dayItem);

    // delete the placeholder item, if exists
    if (dayItem->hasChildren() && dayItem->child(0)->data(AvailIdRole).toInt() == -1)
        dayItem->removeRow(0);

    // Insert the TimeRanges
    for(int i = 0; i < availability.timeRangeCount(); ++i) {
        TimeRange range = availability.timeRangeAt(i);
        QStandardItem *timeItem = new QStandardItem(tkTr(Trans::Constants::FROM_1_TO_2).arg(range.from.toString()).arg(range.to.toString()));
        timeItem->setData(availability.weekDay(), WeekDayRole);
        timeItem->setData(range.from, HourFromRole);
        timeItem->setData(range.to, HourToRole);
        timeItem->setToolTip(timeItem->text());
        dayItem->appendRow(timeItem);
    }
    dayItem->sortChildren(0);

}
Ejemplo n.º 13
0
void tst_QStandardItem::ctor()
{
    QStandardItem item;
    QVERIFY(!item.hasChildren());
}
Ejemplo n.º 14
0
bool QmitkViewNavigatorWidget::FillTreeList()
{
    // active workbench window available?
    if (m_Window.IsNull())
        return false;

    // active page available?
    berry::IWorkbenchPage::Pointer page = m_Window->GetActivePage();
    if (page.IsNull())
        return false;

    // everything is fine and we can remove the window listener
    if (m_WindowListener != nullptr)
        berry::PlatformUI::GetWorkbench()->RemoveWindowListener(m_WindowListener.data());

    // initialize tree model
    m_TreeModel->clear();
    QStandardItem *treeRootItem = m_TreeModel->invisibleRootItem();

    // get all available perspectives
    berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry();
    QList<berry::IPerspectiveDescriptor::Pointer> perspectiveDescriptors(perspRegistry->GetPerspectives());
    qSort(perspectiveDescriptors.begin(), perspectiveDescriptors.end(), comparePerspectives);

    // get all Keywords
    KeywordRegistry keywordRegistry;

    berry::IPerspectiveDescriptor::Pointer currentPersp = page->GetPerspective();
    //QStringList perspectiveExcludeList = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetPerspectiveExcludeList();

    std::vector< QStandardItem* > categoryItems;
    QStandardItem *perspectiveRootItem = new QStandardItem("Perspectives");
    perspectiveRootItem->setEditable(false);
    perspectiveRootItem->setFont(QFont("", 12, QFont::Normal));
    treeRootItem->appendRow(perspectiveRootItem);

    for (int i=0; i<perspectiveDescriptors.size(); i++)
    {
        berry::IPerspectiveDescriptor::Pointer p = perspectiveDescriptors.at(i);
/*
        bool skipPerspective = false;
        for(int e=0; e<perspectiveExcludeList.size(); e++)
            if(perspectiveExcludeList.at(e)==p->GetId())
            {
                skipPerspective = true;
                break;
            }
        if (skipPerspective)
            continue;
*/
        //QIcon* pIcon = static_cast<QIcon*>(p->GetImageDescriptor()->CreateImage());
        mitk::QtPerspectiveItem* pItem = new mitk::QtPerspectiveItem(p->GetLabel());
        pItem->m_Perspective = p;
        pItem->m_Description = p->GetDescription();
        QStringList keylist = p->GetKeywordReferences();
        pItem->m_Tags = keywordRegistry.GetKeywords(keylist);
        pItem->setEditable(false);

        QFont font; font.setBold(true);
        if (currentPersp.IsNotNull() && currentPersp->GetId()==p->GetId())
            pItem->setFont(font);

        QStringList catPath = p->GetCategoryPath();
        if (catPath.isEmpty())
        {
            perspectiveRootItem->appendRow(pItem);
        }
        else
        {
            QStandardItem* categoryItem = nullptr;

            for (unsigned int c=0; c<categoryItems.size(); c++)
            {
                if (categoryItems.at(c)->text() == catPath.front())
                {
                    categoryItem = categoryItems.at(c);
                    break;
                }
            }

            if (categoryItem==nullptr)
            {
                categoryItem  = new QStandardItem(QIcon(),catPath.front());
                categoryItems.push_back(categoryItem);
            }
            categoryItem->setEditable(false);
            categoryItem->appendRow(pItem);
            categoryItem->setFont(QFont("", 12, QFont::Normal));
        }
    }
    std::sort(categoryItems.begin(), categoryItems.end(), compareQStandardItems);
    for (unsigned int i=0; i<categoryItems.size(); i++)
        perspectiveRootItem->appendRow(categoryItems.at(i));

    // get all available views
    berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry();
    QList<berry::IViewDescriptor::Pointer> viewDescriptors(viewRegistry->GetViews());
    QList<berry::IViewPart::Pointer> viewParts(page->GetViews());
    qSort(viewDescriptors.begin(), viewDescriptors.end(), compareViews);
    auto   emptyItem = new QStandardItem();
    emptyItem->setFlags(Qt::ItemIsEnabled);
    treeRootItem->appendRow(emptyItem);
    //QStringList viewExcludeList = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetViewExcludeList();

    //There currently is no way to get the list of excluded views at application start
    QStringList viewExcludeList;
    // internal view used for the intro screen, will crash when opened directly, see T22352
    viewExcludeList.append(QString("org.blueberry.ui.internal.introview"));
    viewExcludeList.append(QString("org.mitk.views.controlvisualizationpropertiesview"));
    viewExcludeList.append(QString("org.mitk.views.modules"));
    viewExcludeList.append(QString("org.mitk.views.viewnavigatorview"));

    QStandardItem* viewRootItem = new QStandardItem(QIcon(),"Views");
    viewRootItem->setFont(QFont("", 12, QFont::Normal));
    viewRootItem->setEditable(false);
    treeRootItem->appendRow(viewRootItem);

    categoryItems.clear();
    QStandardItem* noCategoryItem = new QStandardItem(QIcon(),"Miscellaneous");
    noCategoryItem->setEditable(false);
    noCategoryItem->setFont(QFont("", 12, QFont::Normal));

    for (int i = 0; i < viewDescriptors.size(); ++i)
    {
        berry::IViewDescriptor::Pointer v = viewDescriptors[i];
        bool skipView = false;
        for(int e=0; e<viewExcludeList.size(); e++)
            if(viewExcludeList.at(e)==v->GetId())
            {
                skipView = true;
                break;
            }
        if (skipView)
            continue;

        QStringList catPath = v->GetCategoryPath();

        QIcon icon = v->GetImageDescriptor();
        mitk::QtViewItem* vItem = new mitk::QtViewItem(icon, v->GetLabel());
        vItem->m_View = v;
        vItem->setToolTip(v->GetDescription());
        vItem->m_Description = v->GetDescription();

        QStringList keylist = v->GetKeywordReferences();
        vItem->m_Tags = keywordRegistry.GetKeywords(keylist);
        vItem->setEditable(false);

        for (int i=0; i<viewParts.size(); i++)
            if(viewParts[i]->GetPartName()==v->GetLabel())
            {
                QFont font; font.setBold(true);
                vItem->setFont(font);
                break;
            }

        if (catPath.empty())
            noCategoryItem->appendRow(vItem);
        else
        {
            QStandardItem* categoryItem = nullptr;

            for (unsigned int c=0; c<categoryItems.size(); c++)
                if (categoryItems.at(c)->text() == catPath.front())
                {
                    categoryItem = categoryItems.at(c);
                    break;
                }

            if (categoryItem==nullptr)
            {
                categoryItem  = new QStandardItem(QIcon(),catPath.front());
                categoryItems.push_back(categoryItem);
            }
            categoryItem->setEditable(false);
            categoryItem->appendRow(vItem);
            categoryItem->setFont(QFont("", 12, QFont::Normal));
        }
    }
    std::sort(categoryItems.begin(), categoryItems.end(), compareQStandardItems);

    for (unsigned int i=0; i<categoryItems.size(); i++)
        viewRootItem->appendRow(categoryItems.at(i));
    if (noCategoryItem->hasChildren())
        viewRootItem->appendRow(noCategoryItem);

    m_Controls.m_PluginTreeView->expandAll();

    return true;
}
Ejemplo n.º 15
0
void ProjectSelectionPage::validateData()
{
    QUrl url = ui->locationUrl->url();
    if( !url.isLocalFile() || url.isEmpty() )
    {
        ui->locationValidWidget->setText( i18n("Invalid location") );
        ui->locationValidWidget->animatedShow();
        emit invalid();
        return;
    }

    if( appName().isEmpty() )
    {
        ui->locationValidWidget->setText( i18n("Empty project name") );
        ui->locationValidWidget->animatedShow();
        emit invalid();
        return;
    }

    if( !appName().isEmpty() )
    {
        QString appname = appName();
        QString templatefile = m_wizardDialog->appInfo().appTemplate;

        // Read template file
        KConfig config(templatefile);
        KConfigGroup configgroup(&config, "General");
        QString pattern = configgroup.readEntry( "ValidProjectName" ,  "^[a-zA-Z][a-zA-Z0-9_]+$" );

        // Validation
        int pos = 0;
        QRegExp regex( pattern );
        QRegExpValidator validator( regex );
        if( validator.validate(appname, pos) == QValidator::Invalid )
        {
            ui->locationValidWidget->setText( i18n("Invalid project name") );
            emit invalid();
            return;
        }
    }

    QDir tDir(url.toLocalFile());
    while (!tDir.exists() && !tDir.isRoot()) {
        if (!tDir.cdUp()) {
            break;
        }
    }

    if (tDir.exists())
    {
        QFileInfo tFileInfo(tDir.absolutePath());
        if (!tFileInfo.isWritable() || !tFileInfo.isExecutable())
        {
            ui->locationValidWidget->setText( i18n("Unable to create subdirectories, "
                                                  "missing permissions on: %1", tDir.absolutePath()) );
            ui->locationValidWidget->animatedShow();
            emit invalid();
            return;
        }
    }

    QStandardItem* item = getCurrentItem();
    if( item && !item->hasChildren() )
    {
        ui->locationValidWidget->animatedHide();
        emit valid();
    } else
    {
        ui->locationValidWidget->setText( i18n("Invalid project template, please choose a leaf item") );
        ui->locationValidWidget->animatedShow();
        emit invalid();
        return;
    }

    // Check for non-empty target directory. Not an error, but need to display a warning.
    url.setPath( url.path() + '/' + encodedAppName() );
    QFileInfo fi( url.toLocalFile() );
    if( fi.exists() && fi.isDir() )
    {
        if( !QDir( fi.absoluteFilePath()).entryList( QDir::NoDotAndDotDot | QDir::AllEntries ).isEmpty() )
        {
            ui->locationValidWidget->setText( i18n("Path already exists and contains files. Open it as a project.") );
            ui->locationValidWidget->animatedShow();
            emit invalid();
            return;
        }
    }
}
void ProjectSelectionPage::validateData()
{
    KUrl url = ui->locationUrl->url();
    if( !url.isLocalFile() || url.isEmpty() )
    {
        ui->locationValidLabel->setText( i18n("Invalid location") );
        setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
        emit invalid();
        return;
    }

    if( appName().isEmpty() )
    {
        ui->locationValidLabel->setText( i18n("Empty project name") );
        setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
        emit invalid();
        return;
    }

    if( appName() == "." || appName() == "..")
    {
        ui->locationValidLabel->setText( i18n("Invalid project name") );
        setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
        emit invalid();
        return;
    }

    QDir tDir(url.toLocalFile( KUrl::RemoveTrailingSlash ));
    while (!tDir.exists() && !tDir.isRoot())
        tDir.setPath( pathUp( tDir.absolutePath() ));

    if (tDir.exists())
    {
        QFileInfo tFileInfo(tDir.absolutePath());
        if (!tFileInfo.isWritable() || !tFileInfo.isExecutable())
        {
            ui->locationValidLabel->setText( i18n("Unable to create subdirectories, "
                                                  "missing permissions on: %1", tDir.absolutePath()) );
            setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
            emit invalid();
            return;
        }
    }

    QStandardItem* item = m_templatesModel->itemFromIndex( ui->templateView->currentIndex() );
    if( item && !item->hasChildren() )
    {
        ui->locationValidLabel->setText( QString(" ") );
        setForeground(ui->locationValidLabel, KColorScheme::NormalText);
        emit valid();
    } else
    {
        ui->locationValidLabel->setText( i18n("Invalid project template, please choose a leaf item") );
        setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
        emit invalid();
        return;
    }

    // Check for non-empty target directory. Not an error, but need to display a warning.
    url.addPath( encodedAppName() );
    QFileInfo fi( url.toLocalFile( KUrl::RemoveTrailingSlash ) );
    if( fi.exists() && fi.isDir() )
    {
        if( !QDir( fi.absoluteFilePath()).entryList( QDir::NoDotAndDotDot | QDir::AllEntries ).isEmpty() )
        {
            ui->locationValidLabel->setText( i18n("Path already exists and contains files") );
            setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
        }
    }
}