Ejemplo n.º 1
0
void NetworkUsageWindow::refresh()
{
    for (int i = 0; i < TOTAL_COUNTERS; i++)
    {
        DataCounters::CounterType counter = (DataCounters::CounterType) i;
        QString counterLabel;
        switch (counter)
        {
        case DataCounters::Messages:
            counterLabel = "Messages";
            break;
        case DataCounters::MessageBytes:
            counterLabel = "Messages bytes";
            break;
        case DataCounters::ImageBytes:
            counterLabel = "Images bytes";
            break;
        case DataCounters::VideoBytes:
            counterLabel = "Videos bytes";
            break;
        case DataCounters::AudioBytes:
            counterLabel = "Audio bytes";
            break;
        case DataCounters::ProfileBytes:
            counterLabel = "Profile pictures bytes";
            break;
        case DataCounters::SyncBytes:
            counterLabel = "Synchronization bytes";
            break;
        case DataCounters::ProtocolBytes:
            counterLabel = "Protocol bytes";
            break;
        case DataCounters::Total:
            counterLabel = "Total bytes";
            break;
        }

        int column = 0;
        QStandardItem *item = new QStandardItem(counterLabel);
        model->setItem(i, column++, item);
        item->setSelectable(false);
        qint64 bytes = Client::dataCounters.getReceivedBytes(i);
        QString str = (i > 0) ? Utilities::formatBytes(bytes)
                      : QString::number(bytes);
        item = new QStandardItem(str);
        item->setSelectable(false);
        item->setTextAlignment(Qt::AlignCenter);
        model->setItem(i, column++, item);
        bytes = Client::dataCounters.getSentBytes(i);
        str = (i > 0) ? Utilities::formatBytes(bytes)
              : QString::number(bytes);
        item = new QStandardItem(str);
        item->setSelectable(false);
        item->setTextAlignment(Qt::AlignCenter);
        model->setItem(i, column++, item);

    }
}
Ejemplo n.º 2
0
void OnyxMainWindow::bookmarkModel(QStandardItemModel & model,
                                   QModelIndex & selected)
{
    CRFileHistRecord * rec = view_->getDocView()->getCurrentFileHistRecord();
    if ( !rec )
        return;
    LVPtrVector<CRBookmark> & list( rec->getBookmarks() );
    model.setColumnCount(2);
    int row = 0;
    for(int i  = 0; i < list.length(); ++i)
    {
        // skip cites
        CRBookmark * bmk = list[i];
        if (!bmk || (bmk->getType() == bmkt_comment || bmk->getType() == bmkt_correction))
            continue;

        QString t =cr2qt(view_->getDocView()->getPageText(true, list[i]->getBookmarkPage()));
        t.truncate(100);
        QStandardItem *title = new QStandardItem(t);
        title->setData((int)list[i]);
        title->setEditable(false);
        model.setItem(row, 0, title);

        int pos = list[i]->getPercent();
        QString str(tr("%1"));
        str = str.arg(pos);
        QStandardItem *page = new QStandardItem(str);
        page->setTextAlignment(Qt::AlignCenter);
        page->setEditable(false);
        model.setItem(row, 1, page);

        row++;
    }
}
Ejemplo n.º 3
0
	void ConsoleWidget::addStartSeparator()
	{
		mStartTime = QDateTime::currentDateTime();
		QStandardItem *item = new QStandardItem(tr("Execution started at %1").arg(mStartTime.toString(QStringLiteral("dd/MM/yyyy hh:mm:ss:zzz"))));
		item->setTextAlignment(Qt::AlignCenter);
		addSeparator(item);
	}
Ejemplo n.º 4
0
void ChannelConfigModel::updateChannelConfig(const SongFormat *currentFormat)
{
    this->removeRows(0, this->rowCount());

    this->currentFormat = currentFormat;
    if(currentFormat == nullptr)
    {
        return;
    }

    this->setRowCount(currentFormat->Voices);
    for (int i = 0; i < currentFormat->Voices; i++)
    {
        const std::string &voiceName = currentFormat->VoiceName[i];
        QStandardItem *item = new QStandardItem(QString::fromStdString(voiceName));

        QBrush b(currentFormat->VoiceIsMuted[i] ? Qt::red : Qt::green);
        item->setBackground(b);

        QBrush f(currentFormat->VoiceIsMuted[i] ? Qt::white : Qt::black);
        item->setForeground(f);

        item->setTextAlignment(Qt::AlignCenter);
        item->setCheckable(false);
        item->setCheckState(currentFormat->VoiceIsMuted[i] ? Qt::Unchecked : Qt::Checked);
        this->setItem(i, 0, item);
    }
}
Ejemplo n.º 5
0
static void populateTableModel(QStandardItemModel *model)
{
    enum { ItemCount = 50 };

    const char *itemNames[] = { "potion", "ring", "amulet", "wand", "figurine" };
    const char *itemColors[] = { "black", "white", "red", "mauve", "blue", "green",
                                 "yellow", "ultramarine", "pink", "purple" };

    for (int i = 0; i < ItemCount; ++i) {
        QList<QStandardItem*> row;
        QStandardItem *item;
        item = new QStandardItem((i % 10 == 0) ? QString(itemNames[i / 10]) : QString());
        item->setEditable(false);
        row.append(item);
        item = new QStandardItem(QString("%1 %2").arg(QString(itemColors[i % 10])).
                    arg(QString(itemNames[i / 10])));
        item->setEditable(false);
        row.append(item);
        item = new QStandardItem(QString("%1 gold coins").arg(i * 10 + (i % 10) * 15 + 13));
        item->setTextAlignment(Qt::AlignCenter); // the Maemo 5 design spec recommends this.
        item->setEditable(false);
        row.append(item);
        model->appendRow(row);
    }
}
Ejemplo n.º 6
0
	void ConsoleWidget::addEndSeparator()
	{
		const QDateTime &currentDateTime = QDateTime::currentDateTime();
		int days = mStartTime.daysTo(currentDateTime);

		QString durationString;
		if(days > 0)
			durationString += tr("%n day(s) ", "", days);
        mStartTime = mStartTime.addDays(-days);

		int seconds = mStartTime.secsTo(currentDateTime);
		int hours = seconds / 3600;
		seconds = seconds % 3600;
		int minutes = seconds / 60;
		seconds = seconds % 60;

		if(hours > 0)
			durationString += tr("%n hour(s) ", "", hours);
		if(minutes > 0)
			durationString += tr("%n minute(s) ", "", minutes);
		if(seconds > 0)
			durationString += tr("%n second(s) ", "", seconds);
		int startMSec = mStartTime.toString(QStringLiteral("z")).toInt();
		int endMSec = currentDateTime.toString(QStringLiteral("z")).toInt();
		int msec = (endMSec > startMSec) ? (endMSec - startMSec) : (1000 - (startMSec - endMSec));

		durationString += tr("%n millisecond(s)", "", msec);

		QStandardItem *item = new QStandardItem(tr("Execution ended at %1\n(%2)").arg(currentDateTime.toString(QStringLiteral("dd/MM/yyyy hh:mm:ss:zzz"))).arg(durationString));
		item->setTextAlignment(Qt::AlignCenter);
		addSeparator(item);
	}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
void DialogActiveRunways::appendRow(QString airportCode, QString rwyCode, QStandardItemModel *model)
{
    QList<QStandardItem*> row;

    QStandardItem *spacer1 = new QStandardItem();
    spacer1->setFlags(Qt::NoItemFlags);
    spacer1->setTextAlignment(Qt::AlignCenter);
    row.append(spacer1);

    QStandardItem *spacer2 = new QStandardItem();
    spacer2->setFlags(Qt::NoItemFlags);
    spacer2->setTextAlignment(Qt::AlignCenter);
    row.append(spacer2);

    QStandardItem *airport = new QStandardItem(airportCode);
    airport->setFlags(Qt::NoItemFlags);
    airport->setTextAlignment(Qt::AlignCenter);
    row.append(airport);

    QStandardItem *runway = new QStandardItem(rwyCode);
    runway->setFlags(Qt::NoItemFlags);
    runway->setTextAlignment(Qt::AlignCenter);
    row.append(runway);

    QStandardItem *spacer3 = new QStandardItem();
    spacer3->setFlags(Qt::NoItemFlags);
    spacer3->setTextAlignment(Qt::AlignCenter);
    row.append(spacer3);

    QStandardItem *spacer4 = new QStandardItem();
    spacer4->setFlags(Qt::NoItemFlags);
    spacer4->setTextAlignment(Qt::AlignCenter);
    row.append(spacer4);

    QStandardItem *spacer5 = new QStandardItem();
    spacer5->setFlags(Qt::NoItemFlags);
    spacer5->setTextAlignment(Qt::AlignCenter);
    row.append(spacer5);

    model->appendRow(row);

    createCenteredCheckbox(model->indexFromItem(spacer1));
    createCenteredCheckbox(model->indexFromItem(spacer2));
    createCenteredCheckbox(model->indexFromItem(spacer3));
    createCenteredCheckbox(model->indexFromItem(spacer4));
}
Ejemplo n.º 9
0
QStandardItem *ResultsTree::CreateLineNumberItem(const QString &linenumber)
{
    QStandardItem *item = new QStandardItem();
    item->setData(QVariant(linenumber.toULongLong()), Qt::DisplayRole);
    item->setToolTip(linenumber);
    item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
    item->setEditable(false);
    return item;
}
Ejemplo n.º 10
0
static void loadOutline(miniexp_t outlineExp, int offset, QStandardItem* parent, const QHash< QString, int >& indexByName)
{
    const int outlineLength = miniexp_length(outlineExp);

    for(int outlineN = qMax(0, offset); outlineN < outlineLength; ++outlineN)
    {
        miniexp_t bookmarkExp = miniexp_nth(outlineN, outlineExp);
        const int bookmarkLength = miniexp_length(bookmarkExp);

        if(bookmarkLength <= 1 || !miniexp_stringp(miniexp_nth(0, bookmarkExp)) || !miniexp_stringp(miniexp_nth(1, bookmarkExp)))
        {
            continue;
        }

        const QString title = QString::fromUtf8(miniexp_to_str(miniexp_nth(0, bookmarkExp)));
        QString destination = QString::fromUtf8(miniexp_to_str(miniexp_nth(1, bookmarkExp)));

        if(!title.isEmpty() && !destination.isEmpty())
        {
            if(destination.at(0) == QLatin1Char('#'))
            {
                destination.remove(0,1);

                bool ok = false;
                int destinationPage = destination.toInt(&ok);

                if(!ok)
                {
                    if(indexByName.contains(destination))
                    {
                        destinationPage = indexByName[destination] + 1;
                    }
                    else
                    {
                        continue;
                    }
                }

                QStandardItem* item = new QStandardItem(title);
                item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);

                item->setData(destinationPage, Qt::UserRole + 1);

                QStandardItem* pageItem = item->clone();
                pageItem->setText(QString::number(destinationPage));
                pageItem->setTextAlignment(Qt::AlignRight);

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

                if(bookmarkLength >= 3)
                {
                    loadOutline(bookmarkExp, 2, item, indexByName);
                }
            }
        }
    }
}
Ejemplo n.º 11
0
void InstrumentTree::updateHeader()/*{{{*/
{
    //update the patchList headers as well
    QStandardItem* pid = new QStandardItem("");
    QStandardItem* patch = new QStandardItem(tr("Select Patch"));
    patch->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
    _patchModel->setHorizontalHeaderItem(0, patch);
    _patchModel->setHorizontalHeaderItem(1, pid);
    setColumnHidden(1, true);
}/*}}}*/
Ejemplo n.º 12
0
void DUsbList::initList(){
    m_SelectedDev = "";
    m_StandardItemModel->clear();
    QStandardItem *standItem = new QStandardItem(s_EmptyString);
   // standItem->setIcon(QIcon(":/ui/images/unselect.png"));
    standItem->setTextAlignment(Qt::AlignCenter);
    m_StandardItemModel->appendRow(standItem);
    m_LastIndex = m_StandardItemModel->index(0,0);
    this->setModel(m_StandardItemModel);
}
Ejemplo n.º 13
0
static void populateListModel(QStandardItemModel *model)
{
    enum { ItemCount = 50 };

    for (int i = 0; i < ItemCount; ++i) {
        QStandardItem *item = new QStandardItem(QString("%1 coins").arg(i*12+5));
        item->setTextAlignment(Qt::AlignCenter); // the Maemo 5 design spec recommends this.
        item->setEditable(false); // prevent editing of the item
        model->appendRow(item);
    }
}
Ui_pluginManagerWindow::Ui_pluginManagerWindow(QWidget* parent) : QDialog(parent)
{
	UiPluginManager manager;

	ui.setupUi(this);

	QStandardItemModel *model = new QStandardItemModel();
	QStandardItem *nameItem = new QStandardItem(tr("Name"));
	QStandardItem *versionItem = new QStandardItem(tr("Version"));
	QStandardItem *descItem = new QStandardItem(tr("Description"));

	nameItem->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
	versionItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
	descItem->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);

	model->setHorizontalHeaderItem(0, nameItem);
	model->setHorizontalHeaderItem(1, versionItem);
	model->setHorizontalHeaderItem(2, descItem);

	ui.pluginTableView->verticalHeader()->setVisible(false);
	ui.pluginTableView->setModel(model);

	connect(
		ui.pluginTableView->selectionModel(), 
		SIGNAL(currentRowChanged(const QModelIndex, const QModelIndex)), this, 
		SLOT(pluginTableView_rowChanged(const QModelIndex, const QModelIndex)));

	connect(ui.setDefaultButton, SIGNAL(clicked(bool)), this, SLOT(setDefaultButton_clicked(bool)));
	connect(ui.enableAllButton, SIGNAL(clicked(bool)), this, SLOT(enableAllButton_clicked(bool)));
	connect(ui.disableAllButton, SIGNAL(clicked(bool)), this, SLOT(disableAllButton_clicked(bool)));
	connect(ui.moveUpButton, SIGNAL(clicked(bool)), this, SLOT(moveUpButton_clicked(bool)));
	connect(ui.moveDownButton, SIGNAL(clicked(bool)), this, SLOT(moveDownButton_clicked(bool)));

	fillVideoEncoderList(manager);
	ui.pluginTableView->resizeColumnsToContents();

	connect(
		ui.pluginTableView->model(),
		SIGNAL(itemChanged(QStandardItem*)), this,
		SLOT(pluginTableView_itemChanged(QStandardItem*)));
}
Ejemplo n.º 15
0
InterceptWidget::InterceptWidget(IntercepSource * source, QWidget *parent) :
    QWidget(parent),
    source(source)
{
    currentBlockSource = NULL;
    currentGui = NULL;
    ui = new(std::nothrow) Ui::InterceptWidget;
    if (ui == NULL) {
        qFatal("Cannot allocate memory for Ui::InterceptWidget X{");
    }
    ui->setupUi(this);

    packetsTable = new(std::nothrow) QTableView(this);
    if (packetsTable == NULL) {
        qFatal("Cannot allocate memory for QTableView X{");
    }
    QAbstractItemModel *old = packetsTable->model();
    model = source->getModel();
    packetsTable->setModel(model);
    delete old;

    packetsTable->setSelectionMode(QAbstractItemView::ContiguousSelection);
    packetsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
    packetsTable->verticalHeader()->setFont(RegularFont);
    packetsTable->horizontalHeader()->setFont(RegularFont);
    packetsTable->setColumnWidth(PayloadModel::TIMESPTAMP_COLUMN,TIMESTAMP_COLUMN_WIDTH);
    packetsTable->setColumnWidth(PayloadModel::DIRECTION_COLUMN,25);
    packetsTable->verticalHeader()->setDefaultSectionSize(20);
#if QT_VERSION >= 0x050000
    packetsTable->horizontalHeader()->setSectionsMovable( false );
#else
    packetsTable->horizontalHeader()->setMovable(true);
#endif
    connect(packetsTable->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), SLOT(onCurrentSelectedChanged(QModelIndex,QModelIndex)));
    ui->listLayout->addWidget(packetsTable);

    updateColumns();

    sourceChoices << CHOOSE_TEXT << UDP_EXTERNAL_SOURCE_TEXT << TCP_EXTERNAL_SOURCE_TEXT << RAW_TCP_SOURCE_TEXT;
    ui->blockSourceComboBox->addItems(sourceChoices);
    ui->blockSourceComboBox->setCurrentIndex(0);
    QStandardItem * item = qobject_cast<QStandardItemModel *>(ui->blockSourceComboBox->model())->item(0);
    item->setEnabled( false );
    item->setTextAlignment(Qt::AlignCenter);
    item->setBackground(Qt::darkGray);
    item->setForeground(Qt::white);

    connect(ui->blockSourceComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(onSourceChanged(QString)));
}
Ejemplo n.º 16
0
SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
{
    setWindowTitle("GetThingsDone settings");

    settings_ = Settings::getInstance();

    QVBoxLayout *vbox = new QVBoxLayout(this);
    setLayout(vbox);

    confirmDone_ = new QCheckBox("Confirm item removal", this);
    confirmDone_->setCheckState(
        (settings_->get("confirm-removal") != "") ? Qt::Checked
                                                : Qt::Unchecked
    );

    vbox->addWidget(confirmDone_);

#ifdef Q_WS_MAEMO_5
    selector_ = new QMaemo5ListPickSelector(this);
    QStandardItemModel *model = new QStandardItemModel(0, 1, selector_);
    for (int i = 5; i <= 120; i += 5) {
        QStandardItem *item = new QStandardItem(QString("%1").arg(i));
        item->setTextAlignment(Qt::AlignCenter);
        item->setEditable(false);
        model->appendRow(item);
    }
    selector_->setModel(model);
    int minutes = settings_->get("pomodoro-time").toInt();
    selector_->setCurrentIndex((minutes / 5) - 1); // _should_ work...

    timeout_ = new QMaemo5ValueButton("Pomodoro timeout", this);
    timeout_->setValueLayout(QMaemo5ValueButton::ValueBesideText);
    timeout_->setPickSelector(selector_);

    vbox->addWidget(timeout_);

    setAttribute(Qt::WA_Maemo5AutoOrientation,      true);
    setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
    setAttribute(Qt::WA_Maemo5PortraitOrientation,  false);
#endif

    connect(this, SIGNAL(finished(int)), this, SLOT(finishedSlot()));
}
Ejemplo n.º 17
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());
    }
}
void Ui_pluginManagerWindow::addRow(QString id, QString name, QString version, QString desc, bool enabled, bool isDefault)
{
	QStandardItemModel *model = (QStandardItemModel*)ui.pluginTableView->model();
	QStandardItem *nameItem = new QStandardItem(name);
	QStandardItem *versionItem = new QStandardItem(version);
	QStandardItem *descItem = new QStandardItem(desc);
	int row = model->rowCount();

	nameItem->setCheckable(true);
	nameItem->setData(id, PLUGIN_ID);
	versionItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);

	if (enabled)
		nameItem->setCheckState(Qt::Checked);

	model->setItem(row, 0, nameItem);
	model->setItem(row, 1, versionItem);
	model->setItem(row, 2, descItem);

	if (isDefault)
		setDefaultRow(row);
}
Ejemplo n.º 19
0
void TransformsGui::buildSavedCombo()
{
    ui->savedComboBox->blockSignals(true);
    ui->savedComboBox->clear();
    int row = 0;
    // first inactive element
    ui->savedComboBox->addItem(QString("User's chains"));
    QStandardItem * item = qobject_cast<QStandardItemModel *>(ui->savedComboBox->model())->item( row );
    item->setEnabled( false );
    item->setTextAlignment(Qt::AlignCenter);
    item->setBackground(Qt::darkGray);
    item->setForeground(Qt::white);
    // then the rest
    QHash<QString, QString> hash = transformFactory->getSavedConfs();
    QStringList list = hash.keys();
    if (list.isEmpty()) {
        ui->savedComboBox->setEnabled(false);
    } else {
        ui->savedComboBox->addItems(list);
        ui->savedComboBox->setEnabled(true);
    }

    ui->savedComboBox->blockSignals(false);
}
Ejemplo n.º 20
0
void SelectSiteDialog::initializeTable()
{
    model = new QStandardItemModel(importedSites.size(), 1, this);
    QStandardItem *item;

    QStringList verticalHeader;

    int row = 0;
    foreach(QSharedPointer<Site> site, importedSites)
    {
        verticalHeader.append(QString::number(row + 1));

        item = new QStandardItem(site.data()->siteDetails.Csc);
        item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
        item->setData(QVariant(QString::number(site.data()->siteDetails.SwpId)), DataType::SWP_ID);
        item->setCheckable(true);
        item->setTextAlignment(Qt::AlignJustify);
        item->setCheckState(Qt::Unchecked);
        item->setBackground(QColor(Qt::white));
        item->setForeground(QColor(Qt::black));
        model->setItem(row, 0, item);

        row++;
    }
Ejemplo n.º 21
0
void OfficeView::getBookmarksModel(QStandardItemModel& bookmarks_model) {
    bookmarks_model.setColumnCount(2);
    vbf::BookmarksIter begin = instance_.bookmarks().begin();
    vbf::BookmarksIter end   = instance_.bookmarks().end();
    int row = 0;
    for (vbf::BookmarksIter iter  = begin; iter != end; ++iter, ++row) {
        int page_number = iter->data().value<int>();
        qDebug() << page_number;
        if (page_number != 0) {
            QStandardItem *title = new QStandardItem(iter->title());
            title->setData(iter->data());
            title->setEditable(false);
            bookmarks_model.setItem(row, 0, title);

            QString str = QString::number(page_number);
            QStandardItem *page = new QStandardItem(str);
            page->setEditable(false);
            page->setTextAlignment(Qt::AlignCenter);
            bookmarks_model.setItem(row, 1, page);
        }
    }
    bookmarks_model.setHeaderData(0, Qt::Horizontal, QVariant::fromValue(tr("Bookmarks")), Qt::DisplayRole);
    bookmarks_model.setHeaderData(1, Qt::Horizontal, QVariant::fromValue(tr("Page")), Qt::DisplayRole);
}
Ejemplo n.º 22
0
void PreferencesDialog::InitChanInfo()
{
    QHash<MachineType, int> toprows;

    chanModel->clear();
    toplevel.clear();
    toprows.clear();
    QStringList headers;
    headers.append(tr("Name"));
    headers.append(tr("Color"));
    headers.append(tr("Overview"));
    headers.append(tr("Flag Type"));
    headers.append(tr("Label"));
    headers.append(tr("Details"));
    chanModel->setHorizontalHeaderLabels(headers);
    ui->chanView->setColumnWidth(0, 200);
    ui->chanView->setColumnWidth(1, 40);
    ui->chanView->setColumnWidth(2, 60);
    ui->chanView->setColumnWidth(3, 100);
    ui->chanView->setColumnWidth(4, 100);
    ui->chanView->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->chanView->setSelectionBehavior(QAbstractItemView::SelectItems);

    chanModel->setColumnCount(6);

    QStandardItem *hdr = nullptr;

    QMap<MachineType, QString> Section;

    Section[MT_CPAP] = tr("CPAP Events");
    Section[MT_OXIMETER] = tr("Oximeter Events");
    Section[MT_POSITION] = tr("Positional Events");
    Section[MT_SLEEPSTAGE] = tr("Sleep Stage Events");
    Section[MT_UNCATEGORIZED] = tr("Unknown Events");

    QMap<MachineType, QString>::iterator it;

    QHash<QString, schema::Channel *>::iterator ci;

    for (it = Section.begin(); it != Section.end(); ++it) {
        toplevel[it.key()] = hdr = new QStandardItem(it.value());
        hdr->setEditable(false);
        QList<QStandardItem *> list;
        list.append(hdr);
        for (int i=0; i<5; i++) {
            QStandardItem *it = new QStandardItem();
            it->setEnabled(false);
            list.append(it);
        }
        chanModel->appendRow(list);
    }

    ui->chanView->setAlternatingRowColors(true);

    // ui->graphView->setFirstColumnSpanned(0,daily->index(),true); // Crashes on windows.. Why do I need this again?


    ComboBoxDelegate * combobox = new ComboBoxDelegate(ui->waveView);

    ui->chanView->setItemDelegateForColumn(3,combobox);

    int row = 0;
    for (ci = schema::channel.names.begin(); ci != schema::channel.names.end(); ci++) {
        schema::Channel * chan = ci.value();
        if ((chan->type() == schema::DATA) || (chan->type() == schema::SETTING) || chan->type() == schema::WAVEFORM) continue;

        QList<QStandardItem *> items;
        QStandardItem *it = new QStandardItem(chan->fullname());
        it->setCheckable(true);
        it->setCheckState(chan->enabled() ? Qt::Checked : Qt::Unchecked);
        it->setEditable(true);
        it->setData(chan->id(), Qt::UserRole);

        // Dear translators: %1 is a unique ascii english string used to indentify channels in the code, I'd like feedback on how this goes..
        // It's here in case users mess up which field is which.. it will always show the Channel Code underneath in the tooltip.
        it->setToolTip(tr("Double click to change the descriptive name the '%1' channel.").arg(chan->code()));
        items.push_back(it);


        it = new QStandardItem();
        it->setBackground(QBrush(chan->defaultColor()));
        it->setEditable(false);
        it->setData(chan->defaultColor().rgba(), Qt::UserRole);
        it->setToolTip(tr("Double click to change the default color for this channel plot/flag/data."));
        it->setSelectable(false);
        items.push_back(it);

        it = new QStandardItem(QString());
        it->setToolTip(tr("Whether this flag has a dedicated overview chart."));
        it->setCheckable(true);
        it->setCheckState(chan->showInOverview() ? Qt::Checked : Qt::Unchecked);
        it->setTextAlignment(Qt::AlignCenter);
        it->setData(chan->id(), Qt::UserRole);
        items.push_back(it);

        schema::ChanType type = chan->type();

        it = new QStandardItem(channeltype[type]);
        it->setToolTip(tr("Here you can change the type of flag shown for this event"));
        it->setEditable(type != schema::UNKNOWN);
        items.push_back(it);

        it = new QStandardItem(chan->label());
        it->setToolTip(tr("This is the short-form label to indicate this channel on screen."));

        it->setEditable(true);
        items.push_back(it);

        it = new QStandardItem(chan->description());
        it->setToolTip(tr("This is a description of what this channel does."));

        it->setEditable(true);
        items.push_back(it);

        MachineType mt = chan->machtype();
        if (chan->type() == schema::UNKNOWN) mt = MT_UNCATEGORIZED;
        row = toprows[mt]++;
        toplevel[mt]->insertRow(row, items);
    }


    for(QHash<MachineType, QStandardItem *>::iterator i = toplevel.begin(); i != toplevel.end(); ++i) {
        if (i.value()->rowCount() == 0) {
            chanModel->removeRow(i.value()->row());
        }
    }

    ui->chanView->expandAll();
    ui->chanView->setSortingEnabled(true);
}
Ejemplo n.º 23
0
void QgsWFSSourceSelect::capabilitiesReplyFinished()
{
  btnConnect->setEnabled( true );

  if ( !mCapabilities )
    return;
  QgsWFSCapabilities::ErrorCode err = mCapabilities->errorCode();
  if ( err != QgsWFSCapabilities::NoError )
  {
    QString title;
    switch ( err )
    {
      case QgsWFSCapabilities::NetworkError:
        title = tr( "Network Error" );
        break;
      case QgsWFSCapabilities::XmlError:
        title = tr( "Capabilities document is not valid" );
        break;
      case QgsWFSCapabilities::ServerExceptionError:
        title = tr( "Server Exception" );
        break;
      default:
        tr( "Error" );
        break;
    }
    // handle errors
    QMessageBox* box = new QMessageBox( QMessageBox::Critical, title, mCapabilities->errorMessage(), QMessageBox::Ok, this );
    box->setAttribute( Qt::WA_DeleteOnClose );
    box->setModal( true );
    box->setObjectName( "WFSCapabilitiesErrorBox" );
    if ( !property( "hideDialogs" ).toBool() )
      box->open();

    mAddButton->setEnabled( false );
    return;
  }

  mCaps = mCapabilities->capabilities();

  mAvailableCRS.clear();
  Q_FOREACH ( const QgsWFSCapabilities::FeatureType& featureType, mCaps.featureTypes )
  {
    // insert the typenames, titles and abstracts into the tree view
    QStandardItem* titleItem = new QStandardItem( featureType.title );
    QStandardItem* nameItem = new QStandardItem( featureType.name );
    QStandardItem* abstractItem = new QStandardItem( featureType.abstract );
    abstractItem->setToolTip( "<font color=black>" + featureType.abstract  + "</font>" );
    abstractItem->setTextAlignment( Qt::AlignLeft | Qt::AlignTop );
    QStandardItem* filterItem = new QStandardItem();

    typedef QList< QStandardItem* > StandardItemList;
    mModel->appendRow( StandardItemList() << titleItem << nameItem << abstractItem << filterItem );

    // insert the available CRS into mAvailableCRS
    mAvailableCRS.insert( featureType.name, featureType.crslist );
  }

  if ( !mCaps.featureTypes.isEmpty() )
  {
    treeView->resizeColumnToContents( MODEL_IDX_TITLE );
    treeView->resizeColumnToContents( MODEL_IDX_NAME );
    treeView->resizeColumnToContents( MODEL_IDX_ABSTRACT );
    for ( int i = MODEL_IDX_TITLE; i < MODEL_IDX_ABSTRACT; i++ )
    {
      if ( treeView->columnWidth( i ) > 300 )
      {
        treeView->setColumnWidth( i, 300 );
      }
    }
    if ( treeView->columnWidth( MODEL_IDX_ABSTRACT ) > 150 )
    {
      treeView->setColumnWidth( MODEL_IDX_ABSTRACT, 150 );
    }
    btnChangeSpatialRefSys->setEnabled( true );
    treeView->selectionModel()->setCurrentIndex( mModelProxy->index( 0, 0 ), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
    treeView->setFocus();
  }
  else
  {
    QMessageBox::information( nullptr, tr( "No Layers" ), tr( "capabilities document contained no layers." ) );
    mAddButton->setEnabled( false );
    mBuildQueryButton->setEnabled( false );
  }
}
Ejemplo n.º 24
0
    void UpdaterDialog::initModel(QJsonObject json)
    {
        model = new QStandardItemModel(0,4,this);

        /**
         * @brief jsonObject has the following item structure:
         *
         *   {...},
         *   {
         *     "wpnxmscp": {
         *       "latest": {
         *           "url": "https://github.com/WPN-XM/../file.zip",
         *           "version": "0.8.4"
         *       },
         *       "name": "WPN-XM Server Control Panel x86",
         *       "website": "http://wpn-xm.org/"
         *   },
         *   {...}
         */

        /**
         * populate Model with JSON data
         */
        for (QJsonObject:: Iterator iter = json.begin(); iter != json.end(); ++iter)
        {
            QList<QStandardItem*> rowItems;

            // The "key" is the registry name of the software component.
            //QString *registrySoftwareName = QString(iter.key());

            // The "value" is the data of the software component
            QJsonObject software = iter.value().toObject();

            // Map for Latest URL and Version
            QVariantMap latestVersionMap = software["latest"].toObject().toVariantMap();
            //qDebug() << latestVersion["url"].toString() << latestVersion["version"].toString();

            // Table Columns

            // Software Name
            QStandardItem *softwareName = new QStandardItem( "      " + software["name"].toString() );
            rowItems.append(softwareName);

            // Website Link
            QStandardItem *websiteURL = new QStandardItem( software["website"].toString() );
            rowItems.append(websiteURL);

            // Installed Version (= Your current version)
            QString installedVersionString = "1.2.3"; // TODO: detect currently installed versions
            QStandardItem *installedVersion = new QStandardItem( installedVersionString );
            installedVersion->setTextAlignment(Qt::AlignCenter);
            rowItems.append(installedVersion);

            // Latest Version
            QStandardItem *latestVersion = new QStandardItem( latestVersionMap["version"].toString() );
            latestVersion->setTextAlignment(Qt::AlignCenter);
            rowItems.append(latestVersion);

            // Download URL for Latest Version
            QStandardItem *latestVersionURL = new QStandardItem( latestVersionMap["url"].toString() );
            rowItems.append(latestVersionURL);

            // Action

            /**
             * How to render widgets in a table cell when using QTableView?
             *
             * Setting a QPushButton directly to the model is not possible at this point.
             * But its possible to set the model to the tableView and then use rowCount()
             * and draw the buttons using setIndexWidet() in a second iteration.
             *
             * Boils down to: When using a
             * - tableWidget: ugly sorting, no-model, but full cell control with all widgets
             * - tableView: either nice sorting, less cell control, no widgets, but a proper model
             *
             * ----------
             * Finally, i came up with using an ItemDelegate to render the widgets in the action column.
             * The rendering is done by the delegate's paint function.
             * To render multiple widgets (Download Button, Download ProgressBar, Install Button)
             * i've added a custom UserRole "WidgetRole" and three Roles:
             * DownloadPushButton, DownloadProgressBar, InstallPushButton.
             * These roles are set as data to the model and tell the view what to render.
             * This allows to easily update the model and get the matching widgets based on the role.
             */
            QStandardItem *action = new QStandardItem("ActionCell");
            action->setData(ActionColumnItemDelegate::DownloadPushButton, ActionColumnItemDelegate::WidgetRole);
            rowItems.append(action);

            model->appendRow(rowItems);            
        }

        /**
         * Set Header Labels for Table
         */
        QStringList headerLabels;
        // Table               1              (hidden)           2               3             (hidden)        4
        headerLabels<<"Software Component"<<"WebsiteURL"<<"Your Version"<<"Latest Version"<<"DownloadURL"<<"Actions";
        model->setHorizontalHeaderLabels(headerLabels);

        /**
         * Setup SortingProxy for the Model
         */
        sortFilterProxyModel = new QSortFilterProxyModel(this);
        sortFilterProxyModel->setSourceModel(model);
        // sorting is case-insensitive
        sortFilterProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
        // filtering is case-insensitive and using the software name column
        sortFilterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
        sortFilterProxyModel->setFilterKeyColumn(Columns::SoftwareComponent);
    }
Ejemplo n.º 25
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());
    }
}
Ejemplo n.º 26
0
void TrackListView::populateTable()/*{{{*/
{
    if(debugMsg)
        printf("TrackListView::populateTable\n");
    QScrollBar *bar = m_table->verticalScrollBar();
    int barPos = 0;
    if(bar)
        barPos = bar->sliderPosition();

    m_model->clear();
    for(iMidiTrack i = song->artracks()->begin(); i != song->artracks()->end(); ++i)
    {
        MidiTrack* track = (MidiTrack*)(*i);
        PartList* pl = track->parts();
        if(m_displayRole == PartRole && pl->empty())
        {
            continue;
        }

        QStandardItem* trackName = new QStandardItem();
        trackName->setForeground(QBrush(QColor(205,209,205)));
        trackName->setBackground(QBrush(QColor(20,20,20)));
        trackName->setFont(QFont("fixed-width", 10, QFont::Bold));
        trackName->setText(track->name());
        trackName->setCheckable(true);
        trackName->setCheckState(m_selectedTracks.contains(track->id()) ? Qt::Checked : Qt::Unchecked);

        trackName->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        trackName->setData(1, TrackRole);
        trackName->setData(track->name(), TrackNameRole);
        trackName->setData(track->id(), TrackIdRole);
        trackName->setEditable(true);
        m_model->appendRow(trackName);

        for(iPart ip = pl->begin(); ip != pl->end(); ++ip)
        {
            Part* part = ip->second;
            QStandardItem* partName = new QStandardItem();
            partName->setFont(QFont("fixed-width", 9, QFont::Bold));
            partName->setText(part->name());
            partName->setData(part->sn(), PartRole);
            partName->setData(2, TrackRole);
            partName->setData(track->name(), TrackNameRole);
            partName->setData(part->name(), PartNameRole);
            partName->setData(part->tick(), TickRole);
            partName->setData(track->id(), TrackIdRole);
            partName->setEditable(true);
            partName->setCheckable(true);
            partName->setCheckState(m_editor->hasPart(part->sn()) ? Qt::Checked : Qt::Unchecked);

            if(!partColorIcons.isEmpty() && part->colorIndex() < partColorIcons.size())
                partName->setIcon(partColorIcons.at(part->colorIndex()));

            m_model->appendRow(partName);
        }
    }
    m_model->setHorizontalHeaderLabels(m_headers);
    if(m_selectedIndex < m_model->rowCount())
    {
        m_table->selectRow(m_selectedIndex);
        m_table->scrollTo(m_model->index(m_selectedIndex, 0));
    }
    if(bar)
        bar->setSliderPosition(barPos);
}/*}}}*/
Ejemplo n.º 27
0
void QgsGCPListModel::updateModel()
{
  //clear();
  if ( !mGCPList )
    return;

  bool bTransformUpdated = false;

  QVector<QgsPointXY> mapCoords, pixelCoords;
  mGCPList->createGCPVectors( mapCoords, pixelCoords );

  //  // Setup table header
  QStringList itemLabels;
  QString unitType;
  QgsSettings s;
  bool mapUnitsPossible = false;

  if ( mGeorefTransform )
  {
    bTransformUpdated = mGeorefTransform->updateParametersFromGCPs( mapCoords, pixelCoords );
    mapUnitsPossible = mGeorefTransform->providesAccurateInverseTransformation();
  }


  if ( s.value( QStringLiteral( "/Plugin-GeoReferencer/Config/ResidualUnits" ) ) == "mapUnits" && mapUnitsPossible )
  {
    unitType = tr( "map units" );
  }
  else
  {
    unitType = tr( "pixels" );
  }

  itemLabels << tr( "Visible" )
             << tr( "ID" )
             << tr( "Source X" )
             << tr( "Source Y" )
             << tr( "Dest. X" )
             << tr( "Dest. Y" )
             << tr( "dX (%1)" ).arg( unitType )
             << tr( "dY (%1)" ).arg( unitType )
             << tr( "Residual (%1)" ).arg( unitType );

  setHorizontalHeaderLabels( itemLabels );
  setRowCount( mGCPList->size() );

  for ( int i = 0; i < mGCPList->sizeAll(); ++i )
  {
    int j = 0;
    QgsGeorefDataPoint *p = mGCPList->at( i );

    if ( !p )
      continue;

    p->setId( i );

    QStandardItem *si = new QStandardItem();
    si->setTextAlignment( Qt::AlignCenter );
    si->setCheckable( true );
    if ( p->isEnabled() )
      si->setCheckState( Qt::Checked );
    else
      si->setCheckState( Qt::Unchecked );

    setItem( i, j++, si );
    setItem( i, j++, new QgsStandardItem( i ) );
    setItem( i, j++, new QgsStandardItem( p->pixelCoords().x() ) );
    setItem( i, j++, new QgsStandardItem( p->pixelCoords().y() ) );
    setItem( i, j++, new QgsStandardItem( p->mapCoords().x() ) );
    setItem( i, j++, new QgsStandardItem( p->mapCoords().y() ) );

    double residual;
    double dX = 0;
    double dY = 0;
    // Calculate residual if transform is available and up-to-date
    if ( mGeorefTransform && bTransformUpdated && mGeorefTransform->parametersInitialized() )
    {
      QgsPointXY dst;
      QgsPointXY pixel = mGeorefTransform->hasCrs() ? mGeorefTransform->toColumnLine( p->pixelCoords() ) : p->pixelCoords();
      if ( unitType == tr( "pixels" ) )
      {
        // Transform from world to raster coordinate:
        // This is the transform direction used by the warp operation.
        // As transforms of order >=2 are not invertible, we are only
        // interested in the residual in this direction
        if ( mGeorefTransform->transformWorldToRaster( p->mapCoords(), dst ) )
        {
          dX = ( dst.x() - pixel.x() );
          dY = -( dst.y() - pixel.y() );
        }
      }
      else if ( unitType == tr( "map units" ) )
      {
        if ( mGeorefTransform->transformRasterToWorld( pixel, dst ) )
        {
          dX = ( dst.x() - p->mapCoords().x() );
          dY = ( dst.y() - p->mapCoords().y() );
        }
      }
    }
    residual = std::sqrt( dX * dX + dY * dY );

    p->setResidual( QPointF( dX, dY ) );

    if ( residual >= 0.f )
    {
      setItem( i, j++, new QgsStandardItem( dX ) );
      setItem( i, j++, new QgsStandardItem( dY ) );
      setItem( i, j++, new QgsStandardItem( residual ) );
    }
    else
    {
      setItem( i, j++, new QgsStandardItem( QStringLiteral( "n/a" ) ) );
      setItem( i, j++, new QgsStandardItem( QStringLiteral( "n/a" ) ) );
      setItem( i, j++, new QgsStandardItem( QStringLiteral( "n/a" ) ) );
    }
  }
}
Ejemplo n.º 28
0
void DialogHandoff::appendRow(QString text, QStandardItemModel *model)
{
    QStandardItem *item = new QStandardItem(text);
    item->setTextAlignment(Qt::AlignCenter);
    model->appendRow(item);
}
Ejemplo n.º 29
0
void QgsGCPListModel::updateModel()
{
  clear();
  if (!mGCPList)
    return;

//  // Setup table header
  QStringList itemLabels;
//  // Set column headers
  itemLabels<< "on/off" << "id" << "srcX" << "srcY" << "dstX" << "dstY" << "dX" << "dY" << "residual";
//  setColumnCount(itemLabels.size());
  setHorizontalHeaderLabels(itemLabels);
  setRowCount(mGCPList->size());

  bool bTransformUpdated = false;
  if (mGeorefTransform)
  {
    vector<QgsPoint> mapCoords, pixelCoords;
    mGCPList->createGCPVectors(mapCoords, pixelCoords);

    // TODO: the parameters should probable be updated externally (by user interaction)
    bTransformUpdated = mGeorefTransform->updateParametersFromGCPs(mapCoords, pixelCoords);
  }

  for (int i = 0; i < mGCPList->sizeAll(); ++i)
  {
    int j = 0;
    QgsGeorefDataPoint *p = mGCPList->at(i);
    p->setId(i);

    QStandardItem *si = new QStandardItem();
    si->setTextAlignment(Qt::AlignCenter);
    si->setCheckable(true);
    if (p->isEnabled())
      si->setCheckState(Qt::Checked);
    else
      si->setCheckState(Qt::Unchecked);

    setItem(i, j++, si);
    setItem(i, j++, QGSSTANDARDITEM(i) /*create_item<int>(i)*/);
    setItem(i, j++, QGSSTANDARDITEM(p->pixelCoords().x()) /*create_item<double>( p->pixelCoords().x() )*/);
    setItem(i, j++, QGSSTANDARDITEM(-p->pixelCoords().y()) /*create_item<double>(-p->pixelCoords().y() )*/);
    setItem(i, j++, QGSSTANDARDITEM(p->mapCoords().x()) /*create_item<double>( p->mapCoords().x() )*/);
    setItem(i, j++, QGSSTANDARDITEM(p->mapCoords().y()) /*create_item<double>( p->mapCoords().y() )*/);

    double residual = -1.f;
    double dX, dY;
    // Calculate residual if transform is available and up-to-date
    if (mGeorefTransform && bTransformUpdated && mGeorefTransform->parametersInitialized())
    {
      QgsPoint dst;
      // Transform from world to raster coordinate:
      // This is the transform direction used by the warp operation.
      // As transforms of order >=2 are not invertible, we are only
      // interested in the residual in this direction
      mGeorefTransform->transformWorldToRaster(p->mapCoords(), dst);
      dX = (dst.x() - p->pixelCoords().x());
      dY = (dst.y() - p->pixelCoords().y());
      residual = sqrt(dX*dX + dY*dY);
    }
    else
    {
      dX = dY = residual = 0;
    }
    if (residual >= 0.f) {
      setItem(i, j++, QGSSTANDARDITEM(dX) /*create_item<double>(dX)*/);
      setItem(i, j++, QGSSTANDARDITEM(-dY) /*create_item<double>(-dY)*/);
      setItem(i, j++, QGSSTANDARDITEM(residual) /*create_item<double>(residual)*/);
    }
    else {
      setItem(i, j++, QGSSTANDARDITEM("n/a") /*create_std_item("n/a")*/);
      setItem(i, j++, QGSSTANDARDITEM("n/a") /*create_std_item("n/a")*/);
      setItem(i, j++, QGSSTANDARDITEM("n/a") /*create_std_item("n/a")*/);
    }
  }
  //sort();  // Sort data
  //reset(); // Signal to views that the model has changed
}
Ejemplo n.º 30
0
void NotifyOptionsWidget::createTreeModel()
{
	static const struct { ushort kind; QString name; } KindsList[] = { 
		{ INotification::PopupWindow, tr("Display a notification in popup window") },
		{ INotification::SoundPlay, tr("Play sound at the notification") },
		{ INotification::ShowMinimized, tr("Show the corresponding window minimized in the taskbar") },
		{ INotification::AlertWidget, tr("Highlight the corresponding window in the taskbar") },
		{ INotification::TabPageNotify, tr("Display a notification in tab") },
		{ INotification::RosterNotify, tr("Display a notification in your roster") },
		{ INotification::TrayNotify, tr("Display a notification in tray") },
		{ INotification::TrayAction, tr("Display a notification in tray context menu") },
		{ INotification::AutoActivate, tr("Immediately activate the notification") },
		{ 0, QString::null }
	};

	FModel.clear();
	FModel.setColumnCount(2);

	INotificationType globalType;
	globalType.order = 0;
	globalType.kindMask = 0xFFFF;
	globalType.title = tr("Allowed types of notifications");
	globalType.icon = IconStorage::staticStorage(RSR_STORAGE_MENUICONS)->getIcon(MNI_NOTIFICATIONS);

	QMap<QString,INotificationType> notifyTypes;
	notifyTypes.insert(QString::null,globalType);
	foreach(const QString &typeId, FNotifications->notificationTypes())
		notifyTypes.insert(typeId,FNotifications->notificationType(typeId));

	for(QMap<QString,INotificationType>::const_iterator it=notifyTypes.constBegin(); it!=notifyTypes.constEnd(); ++it)
	{
		if (!it->title.isEmpty() && it->kindMask>0)
		{
			QStandardItem *typeNameItem = new QStandardItem(it->title);
			typeNameItem->setFlags(Qt::ItemIsEnabled);
			typeNameItem->setData(it.key(),MDR_TYPE);
			typeNameItem->setData(it->order,MDR_SORT);
			typeNameItem->setIcon(it->icon);
			setItemBold(typeNameItem,true);

			QStandardItem *typeEnableItem = new QStandardItem;
			typeEnableItem->setFlags(Qt::ItemIsEnabled);

			FTypeItems.insert(it.key(),typeNameItem);
			FModel.invisibleRootItem()->appendRow(QList<QStandardItem *>() << typeNameItem << typeEnableItem);

			for (int index =0; KindsList[index].kind!=0; index++)
			{
				if ((it->kindMask & KindsList[index].kind)>0)
				{
					QStandardItem *kindNameItem = new QStandardItem(KindsList[index].name);
					kindNameItem->setFlags(Qt::ItemIsEnabled);
					kindNameItem->setData(index,MDR_SORT);

					QStandardItem *kindEnableItem = new QStandardItem();
					kindEnableItem->setFlags(Qt::ItemIsEnabled);
					kindEnableItem->setTextAlignment(Qt::AlignCenter);
					kindEnableItem->setCheckable(true);
					kindEnableItem->setCheckState(Qt::PartiallyChecked);
					kindEnableItem->setData(it.key(),MDR_TYPE);
					kindEnableItem->setData(KindsList[index].kind,MDR_KIND);

					typeNameItem->appendRow(QList<QStandardItem *>() << kindNameItem << kindEnableItem);
				}
			}
		}
	}
}