Ejemplo n.º 1
0
bool UnitWidget::add()
{
    if (AbstractModifyWidget::add(DBUNITXML::UNIT)) {
        QModelIndex index = itemView()->currentIndex();
        proxyModel()->setData(index.sibling(
                                 index.row(),
                                 model()->columnDisplayedAttr(
                                     DBUNITXML::UNIT,
                                     DBUNITXML::COEFF)
                                 ),
                             1);
        proxyModel()->setData(index.sibling(
                                 index.row(),
                                 model()->columnDisplayedAttr(
                                     DBUNITXML::UNIT,
                                     DBUNITXML::DELTA)
                                 ),
                             0);
        proxyModel()->setData(index.sibling(
                                 index.row(),
                                 model()->columnDisplayedAttr(
                                     DBUNITXML::UNIT,
                                     DBUNITXML::CODE)
                                 ),
                             0);
        return true;
    }
    return false;
}
Ejemplo n.º 2
0
void NumeratorRangeWidget::setModel(TreeXmlHashModel *model)
{
    AbstractModifyWidget::setModel(model);

    proxyModel()->setHeaderData(0,  Qt::Horizontal, tr("Список/Регулярное выражение"));
    proxyModel()->setHeaderData(1,  Qt::Horizontal, tr("Идентификатор"));

    for (qint32 column = 1; column < 18; ++column)
        numeratorRangeTableView->setColumnHidden(column,true);

    numeratorRangeTableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
    numeratorRangeTableView->horizontalHeader()->setDefaultSectionSize(200);
}
Ejemplo n.º 3
0
void LovValueWidget::setModel(TreeXmlHashModel *model)
{
    AbstractModifyWidget::setModel(model);

    proxyModel()->setHeaderData(0,  Qt::Horizontal, tr("Наименование"));
    proxyModel()->setHeaderData(1,  Qt::Horizontal, tr("Значение"));
    proxyModel()->setHeaderData(2,  Qt::Horizontal, tr("Список значений"));
    proxyModel()->setHeaderData(3,  Qt::Horizontal, tr("Идентификатор"));

    for (qint32 column = 2; column < 18; ++column)
        tableViewLovValue->setColumnHidden(column,true);

    tableViewLovValue->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
    tableViewLovValue->horizontalHeader()->setDefaultSectionSize(200);
}
Ejemplo n.º 4
0
QWidget* SongAttributeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    CellEditor* editor = NULL;
    QString classname = QString("%1Editor").arg(editorType(index));

    if (Creatable::category(classname) != "CellEditor")
    {
        if (classname != "Editor")
        {
            // default to StringEditor without 	warning
            WARNING << "Unknown editor widget \"" << classname << "\".";
        }
        classname = "StringEditor";
    }

    editor = static_cast<CellEditor*>( Creatable::create( classname ) );
    editor->setParent(parent);
    editor->setStyleOption(option);
    editor->setIndex(index);
    editor->setModel(SongAttributeDelegate::parent()->proxyModel());
    editor->setCurrentData( proxyModel()->data( index, Qt::EditRole ) );
    editor->polish();
    editor->setFocus();

    return editor;
}
QModelIndex ModelDescriptorListWidget::findIndex(const QUuid &uid, const QModelIndex &parent) const
{
    QString uidString = uid.toString();
    QModelIndex modelIndex;
    for(int row = 0; row < proxyModel()->rowCount(parent); row++) {
        modelIndex = proxyModel()->index(row, 0, parent);
        if(modelIndex.isValid() && modelIndex.data(Qt::UserRole).toString() == uidString) {
            break;
        } else {
            modelIndex = findIndex(uid, modelIndex);
            if(modelIndex.isValid()) {
                break;
            }
        }
    }

    return modelIndex;
}
Ejemplo n.º 6
0
void
InboxView::deleteSelectedItems()
{
    InboxModel* inboxModel = qobject_cast< InboxModel* >( model() );
    if ( inboxModel != 0 )
    {
        proxyModel()->removeIndexes( selectedIndexes() );
    }
}
Ejemplo n.º 7
0
InboxView::InboxView( QWidget* parent ) :
    TrackView( parent )
{
    proxyModel()->setStyle( PlayableProxyModel::SingleColumn );

    TrackView::setGuid( "inbox" );
    setHeaderHidden( true );
    setUniformRowHeights( false );
    setIndentation( 0 );
}
Ejemplo n.º 8
0
InboxView::InboxView( QWidget* parent ) :
    TrackView( parent )
{
    proxyModel()->setStyle( PlayableProxyModel::Large );
    setEmptyTip( tr( "No listening suggestions here." ) );

    TrackView::setGuid( "inbox" );
    setHeaderHidden( true );
    setUniformRowHeights( false );
    setIndentation( 0 );
}
Ejemplo n.º 9
0
void toNewConnection::loadPrevious(const QModelIndex & current)
{
    if (!current.isValid())
        return;

    QModelIndex baseIndex = proxyModel()->index(current.row(), 0);
    int index = proxyModel()->data(baseIndex, Qt::DisplayRole).toInt();
    toConnectionOptions opt = connectionModel()->availableConnection(index);

    // Connection provider for selected/current history connection entry was not found => throw exception
    QVariant p = QVariant::fromValue(opt.provider);
    int idx = Provider->findData(p, Qt::DisplayRole);
    if (idx == -1)
        throw QString("Connection provider not loaded: %1").arg(opt.provider);

    QString RealProviderName = Provider->itemData(idx, Qt::UserRole).toString();
    toConnectionProvider &prov = toConnectionProviderRegistrySing::Instance().get(RealProviderName);

    Provider->setCurrentIndex(Provider->findText(opt.provider));
    Host->lineEdit()->setText(opt.host);
    Database->lineEdit()->setText(opt.database);
    Username->setText(opt.username);
    Password->setText(opt.password);
    Port->setValue(opt.port);
    Schema->setText(opt.schema);
    int ix = colorComboBox->findData(opt.color);
    // safe fallback routine for undefined colors...
    if (ix == -1)
    {
        colorComboBox->addItem(Utils::connectionColorPixmap(opt.color), opt.color, opt.color);
        ix = colorComboBox->count() - 1;
    }
    colorComboBox->setCurrentIndex(ix);

    QList<QCheckBox *> widgets = OptionGroup->findChildren<QCheckBox *>();
    Q_FOREACH(QCheckBox * box, widgets)
    box->setChecked(opt.options.find(box->text()) != opt.options.end());
}
Ejemplo n.º 10
0
void KNMusicTreeViewBase::setMusicModel(KNMusicModel *musicModel)
{
    //Hide the detail tool tip first.
    KNMusicGlobal::detailTooltip()->hide();
    //If we're going to set the model to null, backup header first.
    if(musicModel==nullptr)
    {
        backupHeader();
    }
    else
    {
        //Before we set the source model, we need to check the proxy model.
        if(KNMusicGlobal::nowPlaying()->playingMusicModel()==proxyModel()->musicModel())
        {
            KNMusicGlobal::nowPlaying()->shadowPlayingModel();
        }
    }
    //Set the source model.
    proxyModel()->setSourceModel(musicModel);
    //Check and do header reset.
    if(m_initialLoad)
    {
        //Clear the initial load flag.
        m_initialLoad=false;
        resetHeaderState();
        //Clear the header state backup data.
        m_headerState.clear();
        return;
    }
    //Check if we need to load header state from backup.
    if(musicModel!=nullptr && !m_headerState.isEmpty())
    {
        header()->restoreState(m_headerState);
        m_headerState.clear();
    }
}
Ejemplo n.º 11
0
void SongAttributeDelegate::setModelData(QWidget *editor, QAbstractItemModel *, const QModelIndex &index) const
{
    QVariant newData;
    if (!editor->inherits(CellEditor::staticMetaObject.className()))
    {
        WARNING << editor << " is not a CellEditor.";
    }
    else
    {
        newData = qobject_assert_cast<CellEditor*>(editor)->editedData();
    }

    if ( model()->data( index, Qt::EditRole ) != newData  )
    {
        app().pushCommand( new SongDatabaseEditSongCommand( model(), proxyModel()->mapToSource(index), newData, Qt::EditRole ) );
    }
    m_isEditing = false;
}
Ejemplo n.º 12
0
void
InboxView::onMenuTriggered( int action )
{
    if ( action == Tomahawk::ContextMenu::ActionMarkListened )
    {
        tDebug() << Q_FUNC_INFO << "Mark as Listened";
        InboxModel* inboxModel = qobject_cast< InboxModel* >( model() );
        if ( inboxModel != 0 )
        {
            QModelIndexList sourceIndexes;
            foreach ( const QModelIndex& index, selectedIndexes() )
            {
                if ( index.column() )
                    continue;

                sourceIndexes << proxyModel()->mapToSource( index );
            }
            inboxModel->markAsListened( sourceIndexes );
        }
Ejemplo n.º 13
0
void PresetTests::appendToProxyModelTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);
    for (int i = 0; i < itemsToGenerate; i++) {
        auto metadata = artworksListModel.getMockArtwork(i);
        metadata->set("title", "description", QStringList());
    }

    Mocks::ArtworksUpdaterMock updater;
    Models::ArtworkProxyModel proxyModel(commandManager, presetKeywordsModel, updater);
    proxyModel.setSourceArtwork(artworksListModel.getMockArtwork(0), 0);
    artworksListModel.setUpdatesBlocked(false);

    QStringList keywords;
    keywords << "some" << "keywords";

    KeywordsPresets::ID_t id1 = presetKeywordsModel.addItem("test", keywords);
    proxyModel.addPreset(id1);

    QCOMPARE(artworksListModel.getMockArtwork(0)->getKeywords(), keywords);
    QVERIFY(artworksListModel.getMockArtwork(0)->isModified());
}
Ejemplo n.º 14
0
void KNMusicTreeViewBase::dropEvent(QDropEvent *event)
{
    //Clear the state.
    setState(NoState);
    //Check the model.
    if(musicModel()==nullptr)
    {
        //Ignore the drop event when the music model is null.
        event->ignore();
        return;
    }
    //Clear the dragging hover.
    m_dragMoveRow=-1;
    m_dragIndicatorPos=QAbstractItemView::OnViewport;
    //Drop the data.
    int row=-1;
    //Get the drop row.
    if(dropOn(event, row))
    {
        //Check the music model, and do the drop mime data to the proxy model.
        if(musicModel()!=nullptr &&
                proxyModel()->dropMimeData(event->mimeData(),
                                           Qt::MoveAction,
                                           row,
                                           Name,
                                           QModelIndex()))
        {
            event->accept();
        }
    }
    //Stop auto scroll.
    stopAutoScroll();
    //Set state.
    setState(NoState);
    //Update view port.
    viewport()->update();
}
Ejemplo n.º 15
0
void KNMusicTreeViewBase::dragMoveEvent(QDragMoveEvent *event)
{
    //Ignore the event by default.
    event->ignore();
    //Check the model.
    if(musicModel()==nullptr || m_notAcceptDragMove)
    {
        //Ignore the drag event when the music model is null.
        return;
    }
    //Check mime type.
    const QMimeData *dragMimeData=event->mimeData();
    //Check whether this data is from another music model.
    if(dragMimeData->hasFormat(ModelMimeType))
    {
        //Accept this format drag and drop.
        event->accept();
    }
    else
    {
        //Check whether we have urls from file viewers, like Explorer(Windows)
        //or Finder(Mac OS X).
        if(dragMimeData->hasUrls())
        {
            //Accept it first.
            event->accept();
            //Set it to the end of the whole model.
            //Set the drag move row to the last row.
            m_dragMoveRow=proxyModel()->rowCount()-1;
            //Update the drag indicator position to below item.
            m_dragIndicatorPos=QAbstractItemView::BelowItem;
            //Update the widget.
            viewport()->update();
            //Mission complete.
            return;
        }
    }
    //Check the event state.
    if(!event->isAccepted())
    {
        //Ignore the cannot accepted event.
        return;
    }
    //Get the current Y position index.
    QModelIndex dropIndex=indexAt(QPoint(0, event->pos().y()));
    //Check whether the index is valid or not.
    if(dropIndex.isValid())
    {
        //Save the new drag move index.
        m_dragMoveRow=dropIndex.row();
        //Update the drag indicator position.
        m_dragIndicatorPos=dropPosition(event->pos(), visualRect(dropIndex));
    }
    else
    {
        //Set it to the end of the whole model.
        //Set the drag move row to the last row.
        m_dragMoveRow=proxyModel()->rowCount()-1;
        //Update the drag indicator position to below item.
        m_dragIndicatorPos=QAbstractItemView::BelowItem;
    }
    //Update the widget.
    viewport()->update();
}
Ejemplo n.º 16
0
toNewConnection::toNewConnection(QWidget* parent, toWFlags fl)
    : QDialog(parent, fl)
    , toHelpContext(QString::fromLatin1("newconnection.html"))
{
    setupUi(this);

    colorComboBox->addItem("None", "");
    const QMap<QString, QVariant> ColorsMap(toConfigurationNewSingle::Instance().option(ToConfiguration::Global::ColorizedConnectionsMap).toMap());
    QMapIterator<QString, QVariant> it(ColorsMap);
    while (it.hasNext())
    {
        it.next();
        colorComboBox->addItem(Utils::connectionColorPixmap(it.key()), it.value().toString(), it.key());
    }

    toHelp::connectDialog(this);

    Previous->setModel(proxyModel());
    proxyModel()->setFilterWildcard("*");

    QList<QString> lst = toConnectionProviderRegistrySing::Instance().providers();
    foreach(QString p, lst)
    {
        try
        {
            if (p == "Oracle")
            {
                Provider->addItem(ORACLE_INSTANTCLIENT, QVariant(QString::fromLatin1(ORACLE_PROVIDER)));
                Provider->addItem(ORACLE_TNSCLIENT, QVariant(QString::fromLatin1(ORACLE_PROVIDER)));
            }
            else
            {
                toConnectionProvider &provider = toConnectionProviderRegistrySing::Instance().get(p);
                Provider->addItem(provider.displayName(), QVariant(provider.name()));
            }
        }
        TOCATCH
    }

    if (Provider->count() < 1)
    {
        TOMessageBox::information(
            NULL,
            tr("No connection provider"),
            tr("No available connection provider"));

        reject();
        return;
    }

    NewConnection = 0;

    Previous->setContextMenuPolicy(Qt::CustomContextMenu);

    PreviousContext = new QMenu(this);
    QAction *delact = PreviousContext->addAction(
                          QIcon(QPixmap(trash_xpm)),
                          tr("&Delete"));
    connect(delact,
            SIGNAL(triggered()),
            this,
            SLOT(historyDelete()));

    connect(Previous,
            SIGNAL(customContextMenuRequested(const QPoint &)),
            this,
            SLOT(previousMenu(const QPoint &)));

    Settings.beginGroup("connections");
    readSettings();

    Previous->horizontalHeader()->setStretchLastSection(true);
    Previous->horizontalHeader()->setHighlightSections(false);
    Previous->verticalHeader()->setVisible(false);

    connect(Previous->selectionModel(),
            SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
            this,
            SLOT(previousCellChanged(const QModelIndex &)));

    connect(Provider,
            SIGNAL(currentIndexChanged(int)),
            this,
            SLOT(changeProvider(int)));

    connect(Previous,
            SIGNAL(doubleClicked(const QModelIndex &)),
            this,
            SLOT(accept()));

    connect(Host,
            SIGNAL(editTextChanged(QString)),
            this,
            SLOT(changeHost()));

    connect(ImportButton, SIGNAL(clicked()),
            this, SLOT(importButton_clicked()));

    connect(searchEdit, SIGNAL(textEdited(const QString &)),
            this, SLOT(searchEdit_textEdited(const QString &)));

    connect(testConnectionButton, SIGNAL(clicked()),
            this, SLOT(testConnectionButton_clicked()));

    connect(saveConnectionButton, SIGNAL(clicked()),
            this, SLOT(saveConnectionButton_clicked()));

    // must make sure this gets called manually.
    changeProvider(Provider->currentIndex());

    int r = connectionModel()->rowCount() - 1;
    QModelIndex last = connectionModel()->index(r, 1);
    Previous->setCurrentIndex(last);
    Previous->selectionModel()->clear();
    Previous->setFocus(Qt::OtherFocusReason);
}
Ejemplo n.º 17
0
void UnitWidget::setModel(TreeXmlHashModel *model)
{
    AbstractModifyWidget::setModel(model);

    proxyModel()->setHeaderData(0,  Qt::Horizontal, tr("Наименование"));
    proxyModel()->setHeaderData(1,  Qt::Horizontal, tr("Код ОКЕИ"));
    proxyModel()->setHeaderData(2,  Qt::Horizontal, tr("Коэффициент"));
    proxyModel()->setHeaderData(3,  Qt::Horizontal, tr("Разница"));
    proxyModel()->setHeaderData(4,  Qt::Horizontal, tr("Обозначение"));
    proxyModel()->setHeaderData(5,  Qt::Horizontal, tr("Символы"));
    proxyModel()->setHeaderData(6,  Qt::Horizontal, tr("Обозначение (межд.)"));
    proxyModel()->setHeaderData(7,  Qt::Horizontal, tr("Символы (межд.)"));
    proxyModel()->setHeaderData(8,  Qt::Horizontal, tr("Величина"));
    proxyModel()->setHeaderData(9,  Qt::Horizontal, tr("Идентификатор"));
    itemView()->setModel(proxyModel());

    for (qint32 column = 8; column < 18; ++column)
        tableViewUnit->setColumnHidden(column,true);

    tableViewUnit->horizontalHeader()->setDefaultSectionSize(75);
}