Exemple #1
0
//添加槽
void HomePage::addSlot()
{
    //获取图片
/*
    QStringList Stringlist = QFileDialog::getOpenFileNames(this,"Open file",QDir::currentPath(),tr("(*.png)"));

    if (Stringlist.size() == 0)
    {
        return;
    }
*/



    //PItemData->BGKImage = Stringlist.at(i);

    PItemData->BGKImage = ":/image/2.png";
    PItemData->ID = 0;

    emit sendUrl(*PItemData);



    QStandardItem *Item = new QStandardItem;

    Item->setSizeHint(QSize(60,60));         //设置Item大小为了美观

    QVariant photoUrl(PItemData->BGKImage);

    Item->setData(photoUrl.toString(),Qt::UserRole);

    StandardItemModel->appendRow(Item);      //追加Item


}
Exemple #2
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;
}
Exemple #3
0
void ButtonsList::addItem(const QString &text, QString status, QString icon)
{
    QStandardItem *item = new QStandardItem(text);
    item->setIcon(QIcon(":/image-theme/"+ icon + ".png"));
    item->setStatusTip(status);
    item->setSizeHint(QSize(140,50));
    model->setItem(row++,col,item);
}
QStandardItem *ptImageSpotModel::createSpotItem(const ptImageSpot &ASpot) {
  QStandardItem* hSpotItem = new QStandardItem(ASpot.name());

  hSpotItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable |
                      Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
  // ListView checkboxes are tristate, so we can’t pass a bool as is.
  hSpotItem->setCheckState(ASpot.isEnabled() ? Qt::Checked : Qt::Unchecked);
  hSpotItem->setSizeHint(FSizeHint);
  hSpotItem->setToolTip(createToolTip(ASpot));

  return hSpotItem;
}
Exemple #5
0
void StatusModel::populate()
{
    if ( rowCount() < maxStatusCount ) {
        for ( int i = rowCount(); i < maxStatusCount; ++i ) {
            StatusWidget *status = new StatusWidget( this );
            QStandardItem *newItem = new QStandardItem;
            newItem->setSizeHint( status->size() );
            appendRow( newItem );
            view->setIndexWidget( newItem->index(), status );
        }
    } else {
        removeRows( maxStatusCount, rowCount() - maxStatusCount );
    }
}
Exemple #6
0
void tst_QStandardItem::streamItem()
{
    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"));

    QByteArray ba;
    {
        QDataStream ds(&ba, QIODevice::WriteOnly);
        ds << item;
    }
    {
        QStandardItem streamedItem;
        QDataStream ds(&ba, QIODevice::ReadOnly);
        ds >> streamedItem;
        QCOMPARE(streamedItem.text(), item.text());
        QCOMPARE(streamedItem.toolTip(), item.toolTip());
        QCOMPARE(streamedItem.statusTip(), item.statusTip());
        QCOMPARE(streamedItem.whatsThis(), item.whatsThis());
        QCOMPARE(streamedItem.sizeHint(), item.sizeHint());
        QCOMPARE(streamedItem.font(), item.font());
        QCOMPARE(streamedItem.textAlignment(), item.textAlignment());
        QCOMPARE(streamedItem.background(), item.background());
        QCOMPARE(streamedItem.foreground(), item.foreground());
        QCOMPARE(streamedItem.checkState(), item.checkState());
        QCOMPARE(streamedItem.accessibleText(), item.accessibleText());
        QCOMPARE(streamedItem.accessibleDescription(), item.accessibleDescription());
        QCOMPARE(streamedItem.flags(), item.flags());
    }
}
Exemple #7
0
void tst_QStandardItem::getSetData()
{
    QStandardItem item;
    for (int x = 0; x < 2; ++x) {
        for (int i = 1; i <= 2; ++i) {
            QString text = QString("text %0").arg(i);
            item.setText(text);
            QCOMPARE(item.text(), text);
            
            QPixmap pixmap(32, 32);
            pixmap.fill((i == 1) ? Qt::red : Qt::green);
            QIcon icon(pixmap);
            item.setIcon(icon);
            QCOMPARE(item.icon(), icon);
            
            QString toolTip = QString("toolTip %0").arg(i);
            item.setToolTip(toolTip);
            QCOMPARE(item.toolTip(), toolTip);
            
            QString statusTip = QString("statusTip %0").arg(i);
            item.setStatusTip(statusTip);
            QCOMPARE(item.statusTip(), statusTip);
        
            QString whatsThis = QString("whatsThis %0").arg(i);
            item.setWhatsThis(whatsThis);
            QCOMPARE(item.whatsThis(), whatsThis);
            
            QSize sizeHint(64*i, 48*i);
            item.setSizeHint(sizeHint);
            QCOMPARE(item.sizeHint(), sizeHint);
            
            QFont font;
            item.setFont(font);
            QCOMPARE(item.font(), font);
        
            Qt::Alignment textAlignment((i == 1)
                                        ? Qt::AlignLeft|Qt::AlignVCenter
                                        : Qt::AlignRight);
            item.setTextAlignment(textAlignment);
            QCOMPARE(item.textAlignment(), textAlignment);
            
            QColor backgroundColor((i == 1) ? Qt::blue : Qt::yellow);
            item.setBackground(backgroundColor);
            QCOMPARE(item.background().color(), backgroundColor);
            
            QColor textColor((i == i) ? Qt::green : Qt::cyan);
            item.setForeground(textColor);
            QCOMPARE(item.foreground().color(), textColor);
            
            Qt::CheckState checkState((i == 1) ? Qt::PartiallyChecked : Qt::Checked);
            item.setCheckState(checkState);
            QCOMPARE(item.checkState(), checkState);
            
            QString accessibleText = QString("accessibleText %0").arg(i);
            item.setAccessibleText(accessibleText);
            QCOMPARE(item.accessibleText(), accessibleText);
            
            QString accessibleDescription = QString("accessibleDescription %0").arg(i);
            item.setAccessibleDescription(accessibleDescription);
            QCOMPARE(item.accessibleDescription(), accessibleDescription);
            
            QCOMPARE(item.text(), text);
            QCOMPARE(item.icon(), icon);
            QCOMPARE(item.toolTip(), toolTip);
            QCOMPARE(item.statusTip(), statusTip);
            QCOMPARE(item.whatsThis(), whatsThis);
            QCOMPARE(item.sizeHint(), sizeHint);
            QCOMPARE(item.font(), font);
            QCOMPARE(item.textAlignment(), textAlignment);
            QCOMPARE(item.background().color(), backgroundColor);
            QCOMPARE(item.foreground().color(), textColor);
            QCOMPARE(item.checkState(), checkState);
            QCOMPARE(item.accessibleText(), accessibleText);
            QCOMPARE(item.accessibleDescription(), accessibleDescription);
            
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::DisplayRole)), text);
            QCOMPARE(qvariant_cast<QIcon>(item.data(Qt::DecorationRole)), icon);
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::ToolTipRole)), toolTip);
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::StatusTipRole)), statusTip);
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::WhatsThisRole)), whatsThis);
            QCOMPARE(qvariant_cast<QSize>(item.data(Qt::SizeHintRole)), sizeHint);
            QCOMPARE(qvariant_cast<QFont>(item.data(Qt::FontRole)), font);
            QCOMPARE(qvariant_cast<int>(item.data(Qt::TextAlignmentRole)), int(textAlignment));
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundColorRole)), QBrush(backgroundColor));
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundRole)), QBrush(backgroundColor));
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::TextColorRole)), QBrush(textColor));
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::ForegroundRole)), QBrush(textColor));
            QCOMPARE(qvariant_cast<int>(item.data(Qt::CheckStateRole)), int(checkState));
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::AccessibleTextRole)), accessibleText);
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::AccessibleDescriptionRole)), accessibleDescription);

            item.setBackground(pixmap);
            QCOMPARE(item.background().texture(), pixmap);
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundRole)).texture(), pixmap);
        }
        item.setData(QVariant(), Qt::DisplayRole);
        item.setData(QVariant(), Qt::DecorationRole);
        item.setData(QVariant(), Qt::ToolTipRole);
        item.setData(QVariant(), Qt::StatusTipRole);
        item.setData(QVariant(), Qt::WhatsThisRole);
        item.setData(QVariant(), Qt::SizeHintRole);
        item.setData(QVariant(), Qt::FontRole);
        item.setData(QVariant(), Qt::TextAlignmentRole);
        item.setData(QVariant(), Qt::BackgroundRole);
        item.setData(QVariant(), Qt::ForegroundRole);
        item.setData(QVariant(), Qt::CheckStateRole);
        item.setData(QVariant(), Qt::AccessibleTextRole);
        item.setData(QVariant(), Qt::AccessibleDescriptionRole);
        
        QCOMPARE(item.data(Qt::DisplayRole), QVariant());
        QCOMPARE(item.data(Qt::DecorationRole), QVariant());
        QCOMPARE(item.data(Qt::ToolTipRole), QVariant());
        QCOMPARE(item.data(Qt::StatusTipRole), QVariant());
        QCOMPARE(item.data(Qt::WhatsThisRole), QVariant());
        QCOMPARE(item.data(Qt::SizeHintRole), QVariant());
        QCOMPARE(item.data(Qt::FontRole), QVariant());
        QCOMPARE(item.data(Qt::TextAlignmentRole), QVariant());
        QCOMPARE(item.data(Qt::BackgroundColorRole), QVariant());
        QCOMPARE(item.data(Qt::BackgroundRole), QVariant());
        QCOMPARE(item.data(Qt::TextColorRole), QVariant());
        QCOMPARE(item.data(Qt::ForegroundRole), QVariant());
        QCOMPARE(item.data(Qt::CheckStateRole), QVariant());
        QCOMPARE(item.data(Qt::AccessibleTextRole), QVariant());
        QCOMPARE(item.data(Qt::AccessibleDescriptionRole), QVariant());
    }
}
Exemple #8
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    int rowH = 20;

    listSrcTree.setHorizontalHeaderItem(0, new QStandardItem("Src Devices"));
    QStandardItem* rootItem = listSrcTree.invisibleRootItem();
    QStandardItem* dev1 = new QStandardItem("Device 1");
    dev1->setSizeHint(QSize(20, rowH));
    dev1->appendRow(new QStandardItem("sensor 0"));
    dev1->child(dev1->rowCount()-1)->setSizeHint(QSize(20, rowH));
    dev1->appendRow(new QStandardItem("sensor 1"));
    dev1->child(dev1->rowCount()-1)->setSizeHint(QSize(20, rowH));

    QStandardItem* dev2 = new QStandardItem("Device 2");
    dev2->setSizeHint(QSize(20, rowH));
    dev2->appendRow(new QStandardItem("sensor 0"));
    dev2->child(dev2->rowCount()-1)->setSizeHint(QSize(20, rowH));
    dev2->appendRow(new QStandardItem("sensor 1"));
    dev2->child(dev2->rowCount()-1)->setSizeHint(QSize(20, rowH));
    dev2->appendRow(new QStandardItem("sensor 2"));
    dev2->child(dev2->rowCount()-1)->setSizeHint(QSize(20, rowH));
    dev2->appendRow(new QStandardItem("sensor 3"));
    dev2->child(dev2->rowCount()-1)->setSizeHint(QSize(20, rowH));
    rootItem->appendRow(dev1);
    rootItem->appendRow(dev2);

    listDstTree.setHorizontalHeaderItem(0, new QStandardItem("Dst Devices"));
    rootItem = listDstTree.invisibleRootItem();
    QStandardItem* dev3 = new QStandardItem("Device 3");
    dev3->setSizeHint(QSize(20, rowH));
    dev3->appendRow(new QStandardItem("actuator 0"));
    dev3->child(dev3->rowCount()-1)->setSizeHint(QSize(20, rowH));
    dev3->appendRow(new QStandardItem("actuator 1"));
    dev3->child(dev3->rowCount()-1)->setSizeHint(QSize(20, rowH));
    QStandardItem* dev4 = new QStandardItem("Device 4");
    dev4->setSizeHint(QSize(20, rowH));
    dev4->appendRow(new QStandardItem("actuator 0"));
    dev4->child(dev4->rowCount()-1)->setSizeHint(QSize(20, rowH));
    dev4->appendRow(new QStandardItem("actuator 1"));
    dev4->child(dev4->rowCount()-1)->setSizeHint(QSize(20, rowH));
    dev4->appendRow(new QStandardItem("actuator 2"));
    dev4->child(dev4->rowCount()-1)->setSizeHint(QSize(20, rowH));

    QStandardItem* dev5 = new QStandardItem("Device 5");
    dev5->setSizeHint(QSize(20, rowH));
    for (int i=0; i<10; ++i)
    {
        QString name = "actuator " + QString::number(i);
        dev5->appendRow(new QStandardItem(name));
        dev5->child(dev5->rowCount()-1)->setSizeHint(QSize(20, rowH));
    }
    rootItem->appendRow(dev3);
    rootItem->appendRow(dev4);
    rootItem->appendRow(dev5);

    ui->treeView1->setModel(&listSrcTree);
    ui->treeView2->setModel(&listDstTree);

    ui->treeView1->expandAll();
    ui->treeView2->expandAll();


    //
    ui->listViewArrows->setModel(&listArrows);
    //ui->listViewArrows->sizeHintForRow(25);
    //ui->listViewArrows->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    rootItem = listArrows.invisibleRootItem();
    qDebug() << "item size = " << rootItem->sizeHint();
    listArrows.setHorizontalHeaderItem(0, new QStandardItem("Mappings"));

    QStandardItem* item = new QStandardItem("Maps");

    //NOTE: tree view header is 17...
    // hackety hack...
    item->setSizeHint(QSize(30, 17));
    rootItem->appendRow(item);
    rootItem->appendRow(new QStandardItem("Maps"));
    rootItem->child(rootItem->rowCount()-1)->setSizeHint(QSize(30, rowH));
    rootItem->appendRow(new QStandardItem("Maps"));
    rootItem->child(rootItem->rowCount()-1)->setSizeHint(QSize(30, rowH));
    rootItem->appendRow(new QStandardItem("Maps"));
    rootItem->child(rootItem->rowCount()-1)->setSizeHint(QSize(30, rowH));
    rootItem->appendRow(new QStandardItem("Maps"));
    rootItem->child(rootItem->rowCount()-1)->setSizeHint(QSize(30, rowH));
    rootItem->appendRow(new QStandardItem("Maps"));
    rootItem->child(rootItem->rowCount()-1)->setSizeHint(QSize(30, rowH));


    //try other view

    //custom view

    mapperScene = new QMapperDbScene(this);
    dbModel = new QMapperDbModel();
    mapperScene->setMapperDbModel(dbModel);
    dbModel->LoadFromTest();

    //this is another model we might want to overlay on top of existing:
    dbModelActive = new QMapperDbModel();
    dbModelActive->LoadFromTest(1);
    mapperScene->setMapperDbModelActive(dbModelActive);

    ui->graphicsView->setScene(mapperScene);
    ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    mapperScene->updateScene();
    qDebug() << "gview rect = " << ui->graphicsView->rect();


    //try another view on top
//    QGraphicsView * view2 = new QGraphicsView(this);

//    view2->setFrameRect(ui->graphicsView->rect());

//    view2->show();
//    view2->setBackgroundBrush(QBrush(Qt::blue));
//    QMapperDbScene *scene2 = new QMapperDbScene(this);
//    QMapperDbModel *mod2 = new QMapperDbModel();
//    scene2->setMapperDbModel(mod2);
//    mod2->LoadFromTest();
//    view2->setScene(scene2);
//    scene2->updateScene();


    //ui->graphicsView->setMouseTracking(true);



    //end custom view
    return;

    QGraphicsScene *scene = new QGraphicsScene(this);

    QBrush *brush = new QBrush(Qt::gray);
    QPen *pen = new QPen(Qt::blue);
    pen->setWidth(2);
    //QGraphicsRectItem *rect = scene->addRect(0, 0, 100, 100, *pen, *brush);
    ui->graphicsView->setScene(scene);

    //ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    //ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    qDebug() << "gview rect = " << ui->graphicsView->rect();
    scene->setSceneRect(ui->graphicsView->rect());


    float origin_x = 0;
    float origin_y = 0;

    CustomRect * crect = new CustomRect(origin_x, origin_y, "dev", "sig");
    scene->addItem(crect);



}
Exemple #9
0
void ThumbView::addThumb(QString &imageFullPath)
{
	QStandardItem *thumbIitem = new QStandardItem();
	QImageReader thumbReader;
	QSize hintSize;
	QSize currThumbSize;
	static QImage thumb;

	if (GData::thumbsLayout == Squares)
		hintSize = QSize(thumbWidth / 2, thumbWidth / 2);
	else if (GData::thumbsLayout == Classic)
		hintSize = QSize(thumbWidth, thumbHeight + 
							(GData::showLabels? QFontMetrics(font()).height() + 5 : 0));
	
	thumbFileInfo = QFileInfo(imageFullPath);
	thumbIitem->setData(true, LoadedRole);
	thumbIitem->setData(0, SortRole);
	thumbIitem->setData(thumbFileInfo.filePath(), FileNameRole);
	if (GData::thumbsLayout != Squares && GData::showLabels)
		thumbIitem->setData(thumbFileInfo.fileName(), Qt::DisplayRole);

	thumbReader.setFileName(imageFullPath);
	currThumbSize = thumbReader.size();
	if (currThumbSize.isValid())
	{
		if (!GData::noEnlargeSmallThumb
			|| (currThumbSize.width() > thumbWidth || currThumbSize.height() > thumbHeight))
		{
			currThumbSize.scale(QSize(thumbWidth, thumbHeight), Qt::KeepAspectRatio);
		}
			
		thumbReader.setScaledSize(currThumbSize);
		thumb = thumbReader.read();

		if (GData::exifThumbRotationEnabled)
		{
			imageView->rotateByExifRotation(thumb, imageFullPath);
			currThumbSize = thumb.size();
			currThumbSize.scale(QSize(thumbWidth, thumbHeight), Qt::KeepAspectRatio);
		}
			
		thumbIitem->setIcon(QPixmap::fromImage(thumb));
	}
	else
	{
		thumbIitem->setIcon(QIcon::fromTheme("image-missing",
								QIcon(":/images/error_image.png")).pixmap(BAD_IMG_SZ, BAD_IMG_SZ));
		currThumbSize.setHeight(BAD_IMG_SZ);
		currThumbSize.setWidth(BAD_IMG_SZ);
	}

	if (GData::thumbsLayout == Compact)
	{
		if (GData::showLabels)
			currThumbSize.setHeight(currThumbSize.height() + QFontMetrics(font()).height() + 5);
		thumbIitem->setSizeHint(currThumbSize);
	}
	else
		thumbIitem->setSizeHint(hintSize);

	thumbViewModel->appendRow(thumbIitem);
}