QStandardItem* QgsMilXLibrary::addItem( QStandardItem* parent, const QString& value, const QImage& image, bool isLeaf, const QString& symbolXml, const QString& symbolMilitaryName, int symbolPointCount , bool symbolHasVariablePoints )
{
  QIcon icon;
  QSize iconSize = isLeaf ? mTreeView->iconSize() : !image.isNull() ? QSize( 32, 32 ) : QSize( 1, 32 );
  QImage iconImage( iconSize, QImage::Format_ARGB32 );
  iconImage.fill( Qt::transparent );
  if ( !image.isNull() )
  {
    double scale = qMin( 1., image.width() > image.height() ? iconImage.width() / double( image.width() ) : iconImage.height() / double( image.height() ) );
    QPainter painter( &iconImage );
    painter.setRenderHint( QPainter::SmoothPixmapTransform );
    painter.drawImage(
      QRectF( 0.5 * ( iconSize.width() - scale * image.width() ), 0.5 * ( iconSize.height() - scale * image.height() ), scale * image.width(), scale * image.height() ),
      image );
  }
  icon = QIcon( QPixmap::fromImage( iconImage ) );
  if ( !parent )
  {
    parent = mGalleryModel->invisibleRootItem();
  }
  // Create category group item if necessary
  if ( !isLeaf )
  {
    // Don't create subgroups with same text as parent
    if ( parent->text() == value )
    {
      return parent;
    }
    QStandardItem* groupItem = 0;
    for ( int i = 0, n = parent->rowCount(); i < n; ++i )
    {
      if ( parent->child( i )->text() == value )
      {
        groupItem = parent->child( i );
        break;
      }
    }
    if ( !groupItem )
    {
      groupItem = new QStandardItem( value );
      groupItem->setDragEnabled( false );
      parent->setChild( parent->rowCount(), groupItem );
      groupItem->setIcon( icon );
    }
    return groupItem;
  }
  else
  {
    QStandardItem* item = new QStandardItem( QString( "%1" ).arg( symbolMilitaryName ) );
    parent->setChild( parent->rowCount(), item );
    item->setData( symbolXml, SymbolXmlRole );
    item->setData( symbolMilitaryName, SymbolMilitaryNameRole );
    item->setData( symbolPointCount, SymbolPointCountRole );
    item->setData( symbolHasVariablePoints, SymbolVariablePointsRole );
    item->setToolTip( item->text() );
    item->setIcon( icon );
    return item;
  }
}
Beispiel #2
0
void SoundThemeSelector::fillModel(const SoundTheme &theme)
{
	QStringList headers;
	headers.append(QT_TRANSLATE_NOOP("Notifications", "Type"));
	headers.append(QT_TRANSLATE_NOOP("SoundTheme", "Preview"));
	m_model->setHorizontalHeaderLabels(headers);

	for (int i = 0; i <= Notification::LastType; ++i) {
		Notification::Type type = static_cast<Notification::Type>(i);
		QList<QStandardItem *> items;

		QStandardItem *item = new QStandardItem(Notification::typeString(type));
		item->setToolTip(QT_TRANSLATE_NOOP("SoundTheme","Type"));
		item->setSelectable(false);
		items << item;

		item = new QStandardItem();
		item->setEditable(false);
		item->setIcon(Icon("media-playback-start"));
		item->setToolTip(QT_TRANSLATE_NOOP("SoundTheme","Play"));
		item->setEnabled(!theme.path(type).isNull());
		item->setSelectable(false);
		items << item;

		m_model->appendRow(items);
	}
	ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
}
Beispiel #3
0
void BlogsDialog::updateBlogListOther(std::list<std::string> &ids)
{
	std::list<std::string>::iterator iit;

	/* remove rows with groups before adding new ones */
	model->item(OTHER)->removeRows(0, model->item(OTHER)->rowCount());

	for (iit = ids.begin(); iit != ids.end(); iit ++) {
#ifdef BLOG_DEBUG
		std::cerr << "BlogsDialog::updateBlogListOther(): " << *iit << std::endl;
#endif
		QStandardItem *ownGroup = model->item(OTHER);
		QList<QStandardItem *> blog;
		QStandardItem *blogNameitem = new QStandardItem();
		QStandardItem *blogIditem = new QStandardItem();

		BlogInfo bi;
		if (rsBlogs && rsBlogs->getBlogInfo(*iit, bi)) {
			blogNameitem->setData(QVariant(QString::fromStdWString(bi.blogName)), Qt::DisplayRole);
			blogIditem->setData(QVariant(QString::fromStdString(bi.blogId)), Qt::DisplayRole);
			blogNameitem->setToolTip(tr("Popularity: %1\nFetches: %2\nAvailable: %3"
					).arg(QString::number(bi.pop)).arg(9999).arg(9999));
		} else {
			blogNameitem->setData(QVariant(QString("Unknown Blog")), Qt::DisplayRole);
			blogIditem->setData(QVariant(QString::fromStdString(*iit)), Qt::DisplayRole);
			blogNameitem->setToolTip("Unknown Blog\nNo Description");
		}

		blog.append(blogNameitem);
		blog.append(blogIditem);
		ownGroup->appendRow(blog);
	}
}
Beispiel #4
0
void RouteMapDock::populateTable(int /*flag*/)/*{{{*/
{
	_listModel->clear();
	QDir routes;
	routes.setFilter(QDir::Files | QDir::NoSymLinks);
	if(!routes.cd(routePath))
		return;
	QFileInfoList files = routes.entryInfoList();
	for(int it = 0; it < files.size(); ++it)
	{
		QFileInfo f = files.at(it);
		QString note = oom->noteForRouteMapping(f.filePath());
		QList<QStandardItem*> rowData;
		QStandardItem *chk = new QStandardItem(f.filePath());
		QStandardItem *tname = new QStandardItem(f.baseName());
		tname->setToolTip(note);
		chk->setToolTip(note);
		rowData.append(chk);
		rowData.append(tname);
		_listModel->blockSignals(true);
		_listModel->insertRow(_listModel->rowCount(), rowData);
		_listModel->blockSignals(false);
		routeList->setRowHeight(_listModel->rowCount(), 25);
	}
	updateTableHeader();
	//routeList->resizeRowsToContents();
}/*}}}*/
Beispiel #5
0
QStandardItem *FlagColumn::build_cell(Dwarf *d) {
        QStandardItem *item = init_cell(d);

        item->setData(CT_FLAGS, DwarfModel::DR_COL_TYPE);
        item->setData(false,DwarfModel::DR_SPECIAL_FLAG); //default

        short rating = 0;
        if(d->get_flag_value(m_bit_pos))
            rating = 1;      
        //check to fix butchering pets. currently this will cause the butchered parts to still be recognized as a pet
        //and they'll put them into a burial recepticle, but won't use them as a food source
        if(m_bit_pos == 49){
            if(d->is_pet()){
                item->setToolTip(tr("<b>Please turn off pet availability first.</b><br/><br/>Sorry, pets cannot be butchered due to technical limitations!"));
                item->setData(QBrush(QColor(187,34,34,200)),Qt::BackgroundColorRole);
                item->setData(true,DwarfModel::DR_SPECIAL_FLAG); //indicates that the cell is disabled
                rating = -1;
            }else if(!d->get_caste()->can_butcher()){
                item->setToolTip(tr("<b>This creature cannot be butchered!</b>"));
                item->setData(QBrush(QColor(187,34,34,200)),Qt::BackgroundColorRole);
                item->setData(true,DwarfModel::DR_SPECIAL_FLAG); //indicates that the cell is disabled
                rating = -1;
            }

        }

        item->setData(rating, DwarfModel::DR_SORT_VALUE);
        item->setData(m_bit_pos, DwarfModel::DR_LABOR_ID);
        item->setData(m_set->name(), DwarfModel::DR_SET_NAME);
        return item;
}
Beispiel #6
0
// private slot
void FilesWidget::addDocument(Document *document)
{
    Q_ASSERT(document != NULL);
    Q_ASSERT(document != DocumentManager::current());

    const Location &location = document->location();
    const QString &filePath = location.filePath("unnamed");
    const QString &directoryPath = location.directoryPath("unnamed");
    const QString &fileName = location.fileName("unnamed");

    // Find or create parent item
    const QModelIndexList &parents = m_model.match(m_model.index(0, 0, QModelIndex()), DirectoryPathRole,
                                                   directoryPath, 1, Qt::MatchExactly);
    QStandardItem *parent;

    if (parents.isEmpty()) {
        parent = new QStandardItem(QIcon(":/icons/16x16/folder.png"), directoryPath);

        parent->setToolTip(directoryPath);
        parent->setData(directoryPath, DirectoryPathRole);
        parent->setData(location.isEmpty() ? "" : directoryPath.toLower(), LowerCaseNameRole);

        m_model.appendRow(parent);
        m_model.sort(0);
    } else {
        parent = m_model.itemFromIndex(parents.first());
    }

    // Create child item
    QStandardItem *child = new QStandardItem(QIcon(":/icons/16x16/file.png"), fileName);

    child->setToolTip(filePath);
    child->setData(qVariantFromValue((void *)document), DocumentPointerRole);
    child->setData(fileName, FileNameRole);
    child->setData(location.isEmpty() ? "" : fileName.toLower(), LowerCaseNameRole);

    m_children.insert(document, child);

    parent->appendRow(child);
    parent->sortChildren(0);

    connect(document, &Document::locationChanged, this, &FilesWidget::updateLocationOfSender);
    connect(document, &Document::modificationChanged, this, &FilesWidget::updateModificationMarkerOfSender);

    // Apply current filter
    if (!filterAcceptsChild(child->index())) {
        m_treeFiles->setRowHidden(child->row(), parent->index(), true);

        if (parent->rowCount() == 1) {
            m_treeFiles->setRowHidden(parent->row(), m_model.invisibleRootItem()->index(), true);
        }
    }

    // Show modification marker, if necessary
    updateModificationMarker(document);
    updateParentItemMarkers(parent);
}
Beispiel #7
0
bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, int role )
{
  if ( !QStandardItemModel::setData( idx, value, role ) )
    return false;

  if ( idx.column() == dbtmType || idx.column() == dbtmSrid || idx.column() == dbtmPkCol )
  {
    QGis::WkbType wkbType = ( QGis::WkbType ) idx.sibling( idx.row(), dbtmType ).data( Qt::UserRole + 2 ).toInt();

    QString tip;
    if ( wkbType == QGis::WKBUnknown )
    {
      tip = tr( "Specify a geometry type" );
    }
    else if ( wkbType != QGis::WKBNoGeometry )
    {
      bool ok;
      int srid = idx.sibling( idx.row(), dbtmSrid ).data().toInt( &ok );

      if ( !ok || srid == INT_MIN )
        tip = tr( "Enter a SRID" );
    }

    QStringList pkCols = idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 1 ).toStringList();
    if ( tip.isEmpty() && pkCols.size() > 0 )
    {
      if ( !pkCols.contains( idx.sibling( idx.row(), dbtmPkCol ).data().toString() ) )
        tip = tr( "Select a primary key" );
    }

    for ( int i = 0; i < dbtmColumns; i++ )
    {
      QStandardItem *item = itemFromIndex( idx.sibling( idx.row(), i ) );
      if ( tip.isEmpty() )
      {
        item->setFlags( item->flags() | Qt::ItemIsSelectable | Qt::ItemIsEnabled );
        item->setToolTip( "" );
      }
      else
      {
        item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
        if ( i == dbtmSchema || i == dbtmTable || i == dbtmGeomCol )
        {
          item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
          item->setToolTip( tip );
        }
      }
    }
  }

  return true;
}
bool QgsOracleTableModel::setData( const QModelIndex &idx, const QVariant &value, int role )
{
  if ( !QStandardItemModel::setData( idx, value, role ) )
    return false;

  if ( idx.column() == DbtmType || idx.column() == DbtmSrid || idx.column() == DbtmPkCol )
  {
    QgsWkbTypes::Type wkbType = ( QgsWkbTypes::Type ) idx.sibling( idx.row(), DbtmType ).data( Qt::UserRole + 2 ).toInt();

    QString tip;
    if ( wkbType == QgsWkbTypes::Unknown )
    {
      tip = tr( "Specify a geometry type" );
    }
    else if ( wkbType != QgsWkbTypes::NoGeometry )
    {
      bool ok;
      int srid = idx.sibling( idx.row(), DbtmSrid ).data().toInt( &ok );

      if ( !ok || srid == 0 )
        tip = tr( "Enter a SRID" );
    }

    if ( tip.isEmpty() && idx.sibling( idx.row(), DbtmPkCol ).data( Qt::UserRole + 1 ).toBool() )
    {
      if ( !idx.sibling( idx.row(), DbtmPkCol ).data( Qt::UserRole + 2 ).toBool() )
        tip = tr( "Select a primary key" );
    }

    for ( int i = 0; i < DbtmColumns; i++ )
    {
      QStandardItem *item = itemFromIndex( idx.sibling( idx.row(), i ) );
      if ( tip.isEmpty() )
      {
        item->setFlags( item->flags() | Qt::ItemIsSelectable | Qt::ItemIsEnabled );
        item->setToolTip( "" );
      }
      else
      {
        item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
        if ( i == DbtmOwner || i == DbtmTable || i == DbtmGeomCol )
        {
          item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
          item->setToolTip( tip );
        }
      }
    }
  }

  return true;
}
void repo::gui::RepoFederationDialog::addAvailableProject(const QString &project)
{
    QStandardItem *item = new QStandardItem(project);
    item->setEditable(false);
    item->setToolTip(project);
    ui->availableWidget->addTopLevelRow(item);
}
QStandardItem *EquipmentColumn::build_cell(Dwarf *d){
    QStandardItem *item = init_cell(d);

    QColor rating_color = QColor(69,148,21);
    float rating =  d->get_uniform_rating();
    float coverage = d->get_coverage_rating();

    if(coverage < 100){ //prioritize coverage
        rating = coverage;
        rating_color = Item::color_uncovered();
    }else{
        if(rating < 100) //missing uniform items
            rating_color = Item::color_missing();
    }

    float sort_val = rating - d->get_inventory_wear();
    item->setData(d->get_inventory_wear(),DwarfModel::DR_SPECIAL_FLAG);
    item->setBackground(QBrush(rating_color));
    item->setData(CT_EQUIPMENT, DwarfModel::DR_COL_TYPE);
    item->setData(rating, DwarfModel::DR_RATING); //other drawing 0-100
    item->setData(sort_val, DwarfModel::DR_SORT_VALUE);
    set_export_role(DwarfModel::DR_RATING);

    QString tooltip = QString("<center><h3>%1</h3></center>%2%3")
            .arg(m_title)
            .arg(build_tooltip_desc(d))
            .arg(tooltip_name_footer(d));

    item->setToolTip(tooltip);
    return item;
}
Beispiel #11
0
RecentDock::RecentDock(QWidget *parent) :
    QDockWidget(parent),
    ui(new Ui::RecentDock)
{
    LOG_DEBUG() << "begin";
    ui->setupUi(this);
    toggleViewAction()->setIcon(windowIcon());
    m_recent = Settings.recent();

#ifdef Q_OS_WIN
    // Remove bad entries on Windows due to bug in v17.01.
    QStringList newList;
    bool isRepaired = false;
    foreach (QString s, m_recent) {
        if (s.size() >=3 && s[0] == '/' && s[2] == ':') {
            s.remove(0, 1);
            isRepaired = true;
        }
        newList << s;
    }
    if (isRepaired) {
        m_recent = newList;
        Settings.setRecent(m_recent);
        Settings.sync();
    }
#endif

    ui->listWidget->setDragEnabled(true);
    ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly);
    foreach (QString s, m_recent) {
        QStandardItem* item = new QStandardItem(Util::baseName(s));
        item->setToolTip(QDir::toNativeSeparators(s));
        m_model.appendRow(item);
    }
Beispiel #12
0
void SynthPluginDevice::populatePatchModel(QStandardItemModel* model, int, MType, bool)
{
	if(debugMsg)
    	qWarning("SynthPluginDevice::populatePatchModel();");
    model->clear();

    if (m_plugin)
    {
        QStandardItem* root = model->invisibleRootItem();

        for (uint32_t i=0; i < m_plugin->getProgramCount(); i++)
        {
            QList<QStandardItem*> row;
            QString strId = QString::number(i);
            QStandardItem* idItem = new QStandardItem(strId);
            QStandardItem* nItem = new QStandardItem(m_plugin->getProgramName(i));
            nItem->setToolTip(m_plugin->getProgramName(i));
            row.append(nItem);
            row.append(idItem);
            root->appendRow(row);
            //QAction *act = menu->addAction(QString(mp->name));
            //act->setData(id);
            //mp = _mess->getPatchInfo(ch, mp);
        }
    }
}
void ProjectChangesModel::addProject(IProject* p)
{
    QStandardItem* it = new QStandardItem(p->name());
    it->setData(p->name(), ProjectChangesModel::ProjectNameRole);
    IPlugin* plugin = p->versionControlPlugin();
    if(plugin) {
        IBasicVersionControl* vcs = plugin->extension<IBasicVersionControl>();

        auto info = ICore::self()->pluginController()->pluginInfo(plugin);

        it->setIcon(QIcon::fromTheme(info.iconName()));
        it->setToolTip(vcs->name());

        IBranchingVersionControl* branchingExtension = plugin->extension<KDevelop::IBranchingVersionControl>();
        if(branchingExtension) {
            const auto pathUrl = p->path().toUrl();
            branchingExtension->registerRepositoryForCurrentBranchChanges(pathUrl);
            // can't use new signal slot syntax here, IBranchingVersionControl is not a QObject
            connect(plugin, SIGNAL(repositoryBranchChanged(QUrl)), this, SLOT(repositoryBranchChanged(QUrl)));
            repositoryBranchChanged(pathUrl);
        } else
            reload(QList<IProject*>() << p);
    } else {
        it->setEnabled(false);
    }
    
    appendRow(it);
}
void FindApiWidget::findApiOut(QString api, QString text, QStringList url)
{
    QStandardItem *item = new QStandardItem(api);
    item->setToolTip(text);
    item->setData(url,Qt::UserRole+1);
    m_model->appendRow(item);
}
Beispiel #15
0
bool ProgramsModel::AddProgram(int groupNum, QModelIndex &index, int row)
{
    QStandardItem *groupItem = item(groupNum);

    //if the group was disabled re-enable it
    if(groupItem->rowCount()==0) {
        groupItem->setBackground(Qt::transparent);
        groupItem->setToolTip("");
    }

    int progId = myHost->programsModel->GetNextProgId();

    QString name("New prog");

    //create the program item
    QStandardItem *prgItem = new QStandardItem( name );
    prgItem->setData(ProgramNode,NodeType);
    prgItem->setData(progId,ProgramId);
#ifndef QT_NO_DEBUG
    prgItem->setData(progId,Qt::ToolTipRole);
#endif
    prgItem->setDragEnabled(true);
    prgItem->setDropEnabled(false);
    prgItem->setEditable(true);

    if(row==-1)
        row=groupItem->rowCount();
    groupItem->insertRow(row, prgItem);

    index = prgItem->index();

//    ValidateProgChange(index);

    return true;
}
void ctkCmdLineModuleExplorerModulesSettings::pathsAdded(const QStringList &paths)
{
  // Check the validity of the entries
  foreach(const QString& path, paths)
  {
    ctkCmdLineModuleReference moduleRef = this->ModuleManager->moduleReference(QUrl::fromLocalFile(path));
    if (!moduleRef || !moduleRef.xmlValidationErrorString().isEmpty())
    {
      QStandardItem* item = ui->PathListWidget->item(path);
      if (this->WarningIcon.isNull())
      {
        this->WarningIcon = ctkCmdLineModuleExplorerUtils::createIconOverlay(
              item->icon().pixmap(item->icon().availableSizes().front()),
              QApplication::style()->standardPixmap(QStyle::SP_MessageBoxWarning));
      }

      QString toolTip = path + "\n\n" + tr("Warning") + ":\n\n";
      if (moduleRef)
      {
        item->setIcon(this->WarningIcon);
        toolTip += moduleRef.xmlValidationErrorString();
      }
      else if (this->ModulesRegistered)
      {
        item->setIcon(this->WarningIcon);
        toolTip += tr("No XML output available.");
      }
      else
      {
        toolTip = path;
      }
      item->setToolTip(toolTip);
    }
  }
QStandardItem *TraitColumn::build_cell(Dwarf *d) {
    QStandardItem *item = init_cell(d);
    item->setData(CT_TRAIT, DwarfModel::DR_COL_TYPE);
    item->setData(0, DwarfModel::DR_SPECIAL_FLAG); //default, special flag stores the alpha for the border

    short raw_value = d->trait(m_trait_id);
    short rating = raw_value;
    QStringList infos;
    if (m_trait){
        infos << m_trait->level_message(raw_value).append(m_trait->belief_conficts_msgs(raw_value,d->trait_conflicts(m_trait_id)));
    }else{
        infos << tr("Unknown trait");
    }

    if(raw_value < 0){
        infos << tr("This unit doesn't have this trait!");
    }

    if (d->trait_is_active(m_trait_id)==false)
        infos << tr("Not an active trait for this dwarf.");

    int conflicting_belief_count = 0;
    if (m_trait){
        infos << m_trait->skill_conflicts_msgs(raw_value);
        infos << m_trait->special_messages(raw_value);

        conflicting_belief_count = m_trait->get_conflicting_beliefs().count();
        if(conflicting_belief_count > 0){
            infos << tr("<br/>This trait can conflict with %1").arg(m_trait->belief_conflicts_names());
        }
        if(m_trait->valued_inversely()){
            infos << Trait::inverted_message;
            if(raw_value != -1)
                rating = 100 - raw_value;
        }
    }

    infos.removeAll("");

    if(d->trait_is_conflicted(m_trait_id) && conflicting_belief_count > 0){
        int alpha = 255 * ((float)d->trait_conflicts(m_trait_id).count() / (float)conflicting_belief_count);
        item->setData(alpha, DwarfModel::DR_SPECIAL_FLAG);
    }

    item->setText(QString::number(raw_value));
    item->setData(rating, DwarfModel::DR_SORT_VALUE);
    item->setData(rating, DwarfModel::DR_RATING);
    item->setData(rating, DwarfModel::DR_DISPLAY_RATING);
    item->setData(raw_value, DwarfModel::DR_EXPORT);
    set_export_role(DwarfModel::DR_EXPORT);

    QString tooltip = QString("<center><h3>%1</h3> %2</center><br/>%3<br/>%4")
            .arg(m_title)
            .arg(tr("<b>Raw Value: %1</b>").arg(raw_value))
            .arg(infos.join("<br/>"))
            .arg(tooltip_name_footer(d));
    item->setToolTip(tooltip);

    return item;
}
Beispiel #18
0
void tst_QStandardItem::clone()
{
    QStandardItem item;
    item.setText(QLatin1String("text"));
    item.setToolTip(QLatin1String("toolTip"));
    item.setStatusTip(QLatin1String("statusTip"));
    item.setWhatsThis(QLatin1String("whatsThis"));
    item.setSizeHint(QSize(64, 48));
    item.setFont(QFont());
    item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
    item.setBackground(QColor(Qt::blue));
    item.setForeground(QColor(Qt::green));
    item.setCheckState(Qt::PartiallyChecked);
    item.setAccessibleText(QLatin1String("accessibleText"));
    item.setAccessibleDescription(QLatin1String("accessibleDescription"));
    item.setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);

    QStandardItem *clone = item.clone();
    QCOMPARE(clone->text(), item.text());
    QCOMPARE(clone->toolTip(), item.toolTip());
    QCOMPARE(clone->statusTip(), item.statusTip());
    QCOMPARE(clone->whatsThis(), item.whatsThis());
    QCOMPARE(clone->sizeHint(), item.sizeHint());
    QCOMPARE(clone->font(), item.font());
    QCOMPARE(clone->textAlignment(), item.textAlignment());
    QCOMPARE(clone->background(), item.background());
    QCOMPARE(clone->foreground(), item.foreground());
    QCOMPARE(clone->checkState(), item.checkState());
    QCOMPARE(clone->accessibleText(), item.accessibleText());
    QCOMPARE(clone->accessibleDescription(), item.accessibleDescription());
    QCOMPARE(clone->flags(), item.flags());
    QVERIFY(!(*clone < item));
    delete clone;
}
 void resetModel()
 {
     q->clear();
     QFont bold;
     bold.setBold(true);
     // Create one item for each day of week
     for(int day = Qt::Monday; day <= Qt::Sunday; ++day) {
         QStandardItem *dayItem = new QStandardItem(QDate::longDayName(day));
         dayItem->setFont(bold);
         dayItem->setData(day, WeekDayRole);
         // Add availabilities to items
         const QVector<DayAvailability> &avail = m_UserCalendar->availabilities(day);
         for(int availabilityId = 0; availabilityId < avail.count(); ++availabilityId) {
             for(int timeRangeId = 0; timeRangeId < avail.at(availabilityId).timeRangeCount(); ++timeRangeId) {
                 TimeRange range = avail.at(availabilityId).timeRangeAt(timeRangeId);
                 QStandardItem *time = new QStandardItem(tkTr(Trans::Constants::FROM_1_TO_2).arg(range.from.toString()).arg(range.to.toString()));
                 time->setData(day, WeekDayRole);
                 time->setData(range.from, HourFromRole);
                 time->setData(range.to, HourToRole);
                 time->setData(timeRangeId, TimeRangeIdRole);
                 time->setData(availabilityId, AvailIdRole);
                 time->setToolTip(time->text());
                 dayItem->appendRow(time);
             }
         }
         if (dayItem->rowCount() > 0) {
             dayItem->sortChildren(0);
         }
         q->invisibleRootItem()->appendRow(dayItem);
     }
 }
void QgsStyleManagerDialog::populateSymbols( const QStringList& symbolNames, bool check )
{
  QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
  model->clear();

  int type = currentItemType();

  for ( int i = 0; i < symbolNames.count(); ++i )
  {
    QString name = symbolNames[i];
    QgsSymbol* symbol = mStyle->symbol( name );
    if ( symbol && symbol->type() == type )
    {
      QStandardItem* item = new QStandardItem( name );
      QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize() );
      item->setIcon( icon );
      item->setData( name ); // used to find out original name when user edited the name
      item->setCheckable( check );
      item->setToolTip( name );
      // add to model
      model->appendRow( item );
    }
    delete symbol;
  }
  selectedSymbolsChanged( QItemSelection(), QItemSelection() );
  symbolSelected( listItems->currentIndex() );
}
void BookmarkPropertiesDialog::reloadFolders()
{
	m_model->clear();

	QStandardItem *item = new QStandardItem(Utils::getIcon(QLatin1String("inode-directory")), tr("Bookmarks"));
	item->setData(0, Qt::UserRole);
	item->setToolTip(tr("Bookmarks"));

	m_model->invisibleRootItem()->appendRow(item);

	m_index = item->index();

	populateFolder(BookmarksManager::getFolder(0), item);

	QTreeView *view = qobject_cast<QTreeView*>(m_ui->folderComboBox->view());

	if (view)
	{
		view->setCurrentIndex(m_index);
		view->expandAll();

		m_ui->folderComboBox->setRootModelIndex(m_index.parent());
		m_ui->folderComboBox->setModelColumn(0);
		m_ui->folderComboBox->setCurrentIndex(m_index.row());
		m_ui->folderComboBox->setRootModelIndex(QModelIndex());
	}
}
ActionComboBoxWidget::ActionComboBoxWidget(QWidget *parent) : QComboBox(parent),
	m_view(new ItemViewWidget(this)),
	m_filterLineEdit(NULL),
	m_wasPopupVisible(false)
{
	setEditable(true);
	setView(m_view);
	setItemDelegate(new ItemDelegate(this));

	m_view->setHeaderHidden(true);

	lineEdit()->hide();

	view()->viewport()->parentWidget()->installEventFilter(this);

	QStandardItemModel *model = new QStandardItemModel(this);
	const QVector<ActionDefinition> definitions = ActionsManager::getActionDefinitions();

	for (int i = 0; i < definitions.count(); ++i)
	{
		QStandardItem *item = new QStandardItem(definitions.at(i).icon, QCoreApplication::translate("actions", (definitions.at(i).description.isEmpty() ? definitions.at(i).text : definitions.at(i).description).toUtf8().constData()));
		item->setData(definitions.at(i).identifier, Qt::UserRole);
		item->setToolTip(ActionsManager::getActionName(definitions.at(i).identifier));
		item->setFlags(item->flags() | Qt::ItemNeverHasChildren);

		model->appendRow(item);
	}

	setModel(model);
	setCurrentIndex(-1);
}
QStandardItem *PluginPath::createModelItem()
{
    ensureLoaded();
    // Create a list of plugin lib files with classes.
    // If there are failed ones, create a separate "Failed"
    // category at the end
    QStandardItem *pathItem = new QStandardItem(m_path.absolutePath());
    QStandardItem *failedCategory = 0;
    const PluginDataList::iterator end = m_plugins.end();
    for (PluginDataList::iterator it = m_plugins.begin(); it != end; ++it) {
        QStandardItem *pluginItem = new QStandardItem(QFileInfo(it->path).fileName());
        if (instance(*it)) {
            pluginItem->appendRow(new QStandardItem(QString::fromLatin1(it->instanceGuard->metaObject()->className())));
            pathItem->appendRow(pluginItem);
        } else {
            pluginItem->setToolTip(it->errorMessage);
            if (!failedCategory) {
                const QString failed = QCoreApplication::translate("PluginManager", "Failed Plugins");
                failedCategory = new QStandardItem(failed);
            }
            failedCategory->appendRow(pluginItem);
        }
    }
    if (failedCategory)
        pathItem->appendRow(failedCategory);
    return pathItem;
}
	int ObjectTableView::addObject(const SceneObject *sceneObject)
	{
		QStandardItem *itemObjectName = new QStandardItem(QString::fromStdString(sceneObject->getName()));
		itemObjectName->setData(qVariantFromValue(sceneObject), Qt::UserRole + 1);
		itemObjectName->setEditable(false);

		std::string pathFileName;
		if(sceneObject->getModel()->getMeshes())
		{
			pathFileName = sceneObject->getModel()->getMeshes()->getMeshFilename();
		}
		QStandardItem *itemMeshFile = new QStandardItem(QString::fromStdString(FileHandler::getFileName(pathFileName)));
		itemMeshFile->setToolTip(QString::fromStdString(pathFileName));
		itemMeshFile->setData(qVariantFromValue(sceneObject), Qt::UserRole + 1);
		itemMeshFile->setEditable(false);

		int nextRow = objectsListModel->rowCount();
		objectsListModel->insertRow(nextRow);
		objectsListModel->setItem(nextRow, 0, itemObjectName);
		objectsListModel->setItem(nextRow, 1, itemMeshFile);

		resizeRowsToContents();

		return nextRow;
	}
QStandardItem *HappinessColumn::build_cell(Dwarf *d) {
	QStandardItem *item = init_cell(d);
	
    QString pixmap_name = QString(":status/img/%1.png").arg(Dwarf::happiness_name(d->get_happiness()));
    if(pixmap_name=="")
        pixmap_name = ":img/question-frame.png";

    item->setData(QIcon(pixmap_name), Qt::DecorationRole);
	item->setData(CT_HAPPINESS, DwarfModel::DR_COL_TYPE);
    item->setData(d->get_raw_happiness(), DwarfModel::DR_SORT_VALUE);

    QString tooltip = QString("<center><h3>%1</h3><h4>%2 (%3)</h4></center><p>%4</p>%5")
            .arg(m_title)
            .arg(Dwarf::happiness_name(d->get_happiness()))
            .arg(d->get_raw_happiness())
            .arg(d->get_thought_desc())
            .arg(tooltip_name_footer(d));

    item->setToolTip(tooltip);
	QColor bg = m_colors[d->get_happiness()];
//    item->setBackground(QBrush(bg));
    item->setData(bg,Qt::BackgroundColorRole);

	return item;
}
Beispiel #26
0
	void ShowConfigDialog::reloadSettings ()
	{
		QSettings settings (QCoreApplication::organizationName (),
				QCoreApplication::applicationName () + "_Sidebar");
		settings.beginGroup (Context_);
		const int size = settings.beginReadArray ("Actions");

		for (int i = 0; i < size; ++i)
		{
			settings.setArrayIndex (i);

			const auto& icon = settings.value ("Icon").value<QIcon> ();
			QStandardItem *item = new QStandardItem (icon,
					settings.value ("Text").toString ());
			item->setCheckState (settings.value ("Enabled").toBool () ?
						Qt::Checked :
						Qt::Unchecked);
			item->setToolTip (settings.value ("Tooltip").toString ());
			item->setData (settings.value ("ID"), Roles::ActionID);
			item->setCheckable (true);
			item->setEditable (false);
			Model_->appendRow (item);
		}

		settings.endArray ();
		settings.endGroup ();
	}
Beispiel #27
0
QgsSvgSelectorGroupsModel::QgsSvgSelectorGroupsModel( QObject* parent )
    : QStandardItemModel( parent )
{
  QStringList svgPaths = QgsApplication::svgPaths();
  QStandardItem *parentItem = invisibleRootItem();

  for ( int i = 0; i < svgPaths.size(); i++ )
  {
    QDir dir( svgPaths[i] );
    QStandardItem *baseGroup;

    if ( dir.path().contains( QgsApplication::pkgDataPath() ) )
    {
      baseGroup = new QStandardItem( tr( "App Symbols" ) );
    }
    else if ( dir.path().contains( QgsApplication::qgisSettingsDirPath() ) )
    {
      baseGroup = new QStandardItem( tr( "User Symbols" ) );
    }
    else
    {
      baseGroup = new QStandardItem( dir.dirName() );
    }
    baseGroup->setData( QVariant( svgPaths[i] ) );
    baseGroup->setEditable( false );
    baseGroup->setCheckable( false );
    baseGroup->setIcon( QgsApplication::style()->standardIcon( QStyle::SP_DirIcon ) );
    baseGroup->setToolTip( dir.path() );
    parentItem->appendRow( baseGroup );
    createTree( baseGroup );
    QgsDebugMsg( QString( "SVG base path %1: %2" ).arg( i ).arg( baseGroup->data().toString() ) );
  }
}
QStandardItem *TrainedColumn::build_cell(Dwarf *d){
    QStandardItem *item = init_cell(d);

    QString desc = get_animal_trained_descriptor(d->trained_level());
    float rating = (float)d->trained_level();
    float sort_val = rating;
    QString draw_rating = QString::number(rating);

    QChar sym_master(0x263C); //masterwork symbol in df
    QChar sym_exceptional(0x2261); //3 horizontal lines
    QFontMetrics fm(DT->user_settings()->value("options/grid/font", QFont(DefaultFonts::getRowFontName(), DefaultFonts::getRowFontSize())).value<QFont>());
    bool symbols_ok = false;
    if(fm.inFont(sym_master) && fm.inFont(sym_exceptional)){
        symbols_ok = true;
    }

    if(rating == 7){ //tame
            rating = 50.0f; //don't draw tame animals, this has to be within the uberdelegate's ignore range
            sort_val = -1;
            draw_rating = tr("");
    }else if(rating >= 1 && rating <= 6){ //trained levels
        if(symbols_ok){
            if(rating == 1)
                draw_rating = tr("T");
            else if(rating == 2)
                draw_rating = tr("-");
            else if(rating == 3)
                draw_rating = tr("+");
            else if(rating == 4)
                draw_rating = tr("*");
            else if(rating == 5)
                draw_rating = sym_exceptional;
            else if(rating == 6)
                draw_rating = sym_master;
        }
        rating = (rating / 6.0f * 100.0f / 2.0f) + 50.0f; //scale from 50 to 100
    }else if(rating == 0){ //semi-wild (medium red square)
        rating = 30.0f;
        draw_rating = tr("Sw");
    }else{ //wild, unknown (large red square)
        rating = 5.0f;
        sort_val = -2;
        draw_rating = tr("W");
    }


//    item->setBackground(QBrush(QColor(225,225,225)));
    item->setData(CT_TRAINED, DwarfModel::DR_COL_TYPE);
    item->setData(draw_rating, DwarfModel::DR_DISPLAY_RATING); //numeric drawing, single digits
    item->setData(rating, DwarfModel::DR_RATING); //other drawing 0-100
    item->setData(sort_val, DwarfModel::DR_SORT_VALUE);
    set_export_role(DwarfModel::DR_RATING);

    QString tooltip = QString("<center><h3>%1</h3></center>%2")
            .arg(desc)
            .arg(tooltip_name_footer(d));
    item->setToolTip(tooltip);
    return item;
}
QStandardItem *HistoryDialog::createItem(QVariant& data)
{
	QStandardItem* item = new QStandardItem(data.toString());
	item->setEditable(false);
	item->setToolTip(data.toString());
	item->setData(data);
	return item;
}
Beispiel #30
0
QList<QStandardItem *> TreeItem::get_list_representation(const TreeItemViewFormat & view_format)
{
	// http://www.qtforum.org/article/34069/store-user-data-void-with-qstandarditem-in-qstandarditemmodel.html

	QList<QStandardItem *> items;
	QVariant variant;

	const QString tooltip = this->get_tooltip();

	for (const TreeItemViewColumn & col : view_format.columns) {

		QStandardItem * item = NULL;

		switch (col.id) {
		case TreeItemPropertyID::TheItem:
			item = new QStandardItem(this->name);
			item->setToolTip(tooltip);
			item->setEditable(this->editable);
			variant = QVariant::fromValue(this);
			item->setData(variant, RoleLayerData);
			if (!this->icon.isNull()) { /* Icon can be set with ::apply_tree_item_icon(). */
				item->setIcon(this->icon);
			}
			//item->moveToThread(QApplication::instance()->thread())
			items << item;
			break;

		case TreeItemPropertyID::Visibility:
			item = new QStandardItem();
			item->setCheckable(true);
			item->setCheckState(this->visible ? Qt::Checked : Qt::Unchecked);
			//item->moveToThread(QApplication::instance()->thread())
			items << item;
			break;


		case TreeItemPropertyID::Editable:
			item = new QStandardItem();
			variant = QVariant::fromValue(this->editable);
			item->setData(variant, RoleLayerData);
			//item->moveToThread(QApplication::instance()->thread())
			items << item;
			break;

		case TreeItemPropertyID::Timestamp:
			/* Value in this column can be set with ::apply_tree_item_timestamp(). */
			item = new QStandardItem(this->timestamp.get_value());
			//item->moveToThread(QApplication::instance()->thread())
			items << item;
			break;
		default:
			qDebug() << SG_PREFIX_N << "Unexpected tree item column id" << (int) col.id;
			break;
		}
	}

	return items;
}