Пример #1
0
QTreeWidgetItem* FunctionsTreeWidget::parentItem(const Function* function)
{
    Q_ASSERT(function != NULL);

    // Special case for Sequences. They belong to a Scene node
    if (function->type() == Function::Chaser && qobject_cast<const Chaser*>(function)->isSequence() == true)
    {
        quint32 sid = qobject_cast<const Chaser*>(function)->getBoundSceneID();
        Function *sceneFunc = m_doc->function(sid);
        if (sceneFunc != NULL)
        {
            QTreeWidgetItem *sceneTopItem = folderItem(sceneFunc->path());
            if (sceneTopItem != NULL)
            {
                for (int i = 0; i < sceneTopItem->childCount(); i++)
                {
                    QTreeWidgetItem *child = sceneTopItem->child(i);
                    Q_ASSERT(child != NULL);

                    if (sid == itemFunctionId(child))
                        return child;
                }
            }
        }
    }

    QString basePath = Function::typeToString(function->type());
    if (m_foldersMap.contains(QString(basePath + "/")) == false)
    {
        // Parent item for the given type doesn't exist yet so create one
        QTreeWidgetItem* item = new QTreeWidgetItem(this);
        item->setText(COL_NAME, basePath);
        item->setIcon(COL_NAME, functionIcon(function));
        item->setData(COL_NAME, Qt::UserRole, Function::invalidId());
        item->setData(COL_NAME, Qt::UserRole + 1, function->type());
        item->setText(COL_PATH, QString(basePath + "/"));
        item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled);
        m_foldersMap[QString(basePath + "/")] = item;
    }

    QTreeWidgetItem *pItem = folderItem(function->path());

    if (pItem != NULL)
    {
        //qDebug() << "Found item for function:" << function->name() << ", path: " << function->path();
        return pItem;
    }


    return NULL;
}
Пример #2
0
bool folderModel::insertRows(int position, int rows, const QModelIndex &parent)
{
    Q_UNUSED(parent);
    beginInsertRows(QModelIndex(), position, position+rows-1);

    for (int row = 0; row < rows; ++row) {
        folders.insert(position, folderItem());
    }

    endInsertRows();
    return true;
}
Пример #3
0
void folderModel::readSettings(QSettings &settings)
{
    int size = settings.beginReadArray("folderList");
    folders.clear();
    for(int i = 0; i < size; ++i) {
        settings.setArrayIndex(i);
        if (settings.value("folderName").toString().length() == 0)
            continue; // don't save this empty folder name
        folders.push_back(
            folderItem(settings.value("folderName").toString(),
                       settings.value("displayName").toString(),
                       settings.value("folderNotification", false).toBool(),
                       settings.value("folderPopup", false).toBool(),
                       settings.value("folderVibrate", false).toBool(),
                       settings.value("folderLED", false).toBool(),
                       settings.value("folderSound", false).toBool()));
    }
    settings.endArray();
}