summaryrefslogblamecommitdiffstats
path: root/src/sessiontreeitem.cpp
blob: 65deae833258e990599b0b5ede8e0cefb6c0129c (plain) (tree)
1
2

                            























                                                                                                                


                                                                              
                                                                                









                                                          
                                                          
                              

 







                                                  











                                                                              
#include "sessiontreeitem.h"

QString SessionTreeItem::typeToName(const SectionType type) {
    switch (type) {
    case SECTION_FOR_LOCATION:
        return QObject::tr("Working environments for this room");
    case SECTION_TEMPLATES:
        return QObject::tr("Templates");
    case SECTION_GENERIC:
        return QObject::tr("Working environments");
    case SECTION_XSESSION:
        return QObject::tr("X-Sessions");
    case SECTION_NULL:
        return "<null>";
    default:
        break;
    }
    return "Missing case for SectionType";
}

SessionTreeItem::SessionTreeItem(const Session* session, SessionTreeItem *parent)
    : parent_(parent), session_(session), sectionType_(session->section()), text_(session->shortDescription()) {
}

SessionTreeItem::SessionTreeItem(const SectionType type, SessionTreeItem *parent)
    : parent_(parent), session_(NULL), sectionType_(type), text_(typeToName(type)) {
}

SessionTreeItem::SessionTreeItem(const QString& text, SessionTreeItem *parent)
    : parent_(parent), session_(NULL), sectionType_(SECTION_NULL), text_(text) {
}

SessionTreeItem::~SessionTreeItem() {
    qDeleteAll(children_);
}

void SessionTreeItem::appendChild(SessionTreeItem *item) {
    children_.append(item);
}

void SessionTreeItem::removeChild(SessionTreeItem *item) {
    children_.removeOne(item);
}

SessionTreeItem *SessionTreeItem::child(int row) {
    return children_.value(row);
}

int SessionTreeItem::childCount() const {
    return children_.count();
}

SessionTreeItem *SessionTreeItem::parent() {
    return parent_;
}

int SessionTreeItem::row() const {
    if (parent_) {
        return parent_->children_.indexOf(const_cast<SessionTreeItem*>(this));
    }

    return 0;
}