Example #1
0
void CSMPrefs::State::resetCategory(const std::string& category)
{
    for (Settings::CategorySettingValueMap::iterator i = mSettings.mUserSettings.begin();
         i != mSettings.mUserSettings.end(); ++i)
    {
        // if the category matches
        if (i->first.first == category)
        {
            // mark the setting as changed
            mSettings.mChangedSettings.insert(std::make_pair(i->first.first, i->first.second));
            // reset the value to the default
            i->second = mSettings.mDefaultSettings[i->first];
        }
    }

    Collection::iterator container = mCategories.find(category);
    if (container != mCategories.end())
    {
        Category settings = container->second;
        for (Category::Iterator i = settings.begin(); i != settings.end(); ++i)
        {
            (*i)->updateWidget();
            update(**i);
        }
    }
}
Example #2
0
void Override::loadACL(const DOMElement* e, Category& log)
{
    try {
        const DOMElement* acl=XMLHelper::getFirstChildElement(e,htaccess);
        if (acl) {
            log.info("building Apache htaccess AccessControl provider...");
            m_acl=SPConfig::getConfig().AccessControlManager.newPlugin(HT_ACCESS_CONTROL,acl);
        }
        else {
            acl=XMLHelper::getFirstChildElement(e,_AccessControl);
            if (acl) {
                log.info("building XML-based AccessControl provider...");
                m_acl=SPConfig::getConfig().AccessControlManager.newPlugin(XML_ACCESS_CONTROL,acl);
            }
            else {
                acl=XMLHelper::getFirstChildElement(e,AccessControlProvider);
                if (acl) {
                    auto_ptr_char type(acl->getAttributeNS(NULL,_type));
                    log.info("building AccessControl provider of type %s...",type.get());
                    m_acl=SPConfig::getConfig().AccessControlManager.newPlugin(type.get(),acl);
                }
            }
        }
    }
    catch (exception& ex) {
        log.crit("exception building AccessControl provider: %s", ex.what());
        m_acl = new AccessControlDummy();
    }
}
Example #3
0
bool Round::load(){
    QFile file(roundfile);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
      //QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
        return false;
    }

    QTextStream in(&file);

    Category *curcat = NULL;

    while(!in.atEnd()) {
        QString line = in.readLine();
        if(line.startsWith('#')){
            curcat = new Category(line.mid(1));
            categories.append(curcat);
            continue;
        }
        bool convok = false;
        int points = line.section(':', 0, 0).trimmed().toUInt(&convok);
        QString answer = line.section(':', 1).trimmed();
        if(!convok || answer.length() == 0) {
            if(answer.length() != 0) qWarning() << "Ignoring Line \"" << line << '"';
            continue;
        }
        curcat->addAnswer(answer, points);
        nAnswers++;
    }
    return true;
}
Example #4
0
// repaint cells that have been changed from previous generation
void Pstable::repaint_changed()
{
    int rows = procview->procs.size();
    int cols = procview->cats.size();
    int left = leftCell(), right = lastColVisible();
    int top = topCell(), bottom = lastRowVisible();
    if(right >= cols) right = cols - 1;
    if(bottom >= rows) bottom = rows - 1;
    int far_right = right;
    if(leftmostchanged != -1 && right >= leftmostchanged)
	right = leftmostchanged - 1;
    for(int c = right + 1; c <= far_right; c++)
	updateHeading(c);
    for(int r = top; r <= bottom; r++) {
	for(int c = left; c <= right; c++) {
	    Category *cat = procview->cats[c];
	    Procinfo *p = procview->procs[r], *op = 0;
	    if(r >= procview->old_procs.size()
	       || (op = procview->old_procs[r], cat->compare(p, op) != 0)
	       || p->selected != op->selected) {
		updateCell(r, c);
	    }
	}
	// update all cells that have moved or changed width
	for(int c = right + 1; c <= far_right; c++)
	    updateCell(r, c);
    }
    if(leftmostchanged != -1)
	clearRight();
}
Example #5
0
unique_ptr<Match> tstMatch::initMatchGroup()
{
  MatchMngr* mm = Tournament::getMatchMngr();
  Category ms = Tournament::getCatMngr()->getCategoryById(1);
  TournamentDB db{getSqliteFileName(), false};

  // fake a valid category state
  TabRow catRow = db[TAB_CATEGORY][1];
  catRow.update(GENERIC_STATE_FIELD_NAME, static_cast<int>(STAT_CAT_IDLE));
  CPPUNIT_ASSERT(ms.getState() == STAT_CAT_IDLE);

  // create a new match group
  ERR e;
  auto grp = mm->createMatchGroup(ms, 1, 2, &e);
  CPPUNIT_ASSERT(e == OK);
  CPPUNIT_ASSERT(grp != nullptr);

  grp = mm->createMatchGroup(ms, 2, 3, &e);
  CPPUNIT_ASSERT(e == OK);
  CPPUNIT_ASSERT(grp != nullptr);

  // create a new match in this group
  auto ma = mm->createMatch(*grp, &e);
  CPPUNIT_ASSERT(e == OK);
  CPPUNIT_ASSERT(ma != nullptr);

  return ma;
}
Example #6
0
void CategoryMgr::savePrefs(void)
{
  if (!m_changed)
    return;

  int count = 1;
  QString section = "CategoryMgr";
  QString prefBaseName;

  CategoryListIterator it(m_categories);
  for (Category* curCategory = it.toFirst(); 
       curCategory != NULL;
       curCategory = ++it)
  {
    prefBaseName.sprintf("Category%d_", count++);
    pSEQPrefs->setPrefString(prefBaseName + "Name", section, 
			     curCategory->name());
    pSEQPrefs->setPrefString(prefBaseName + "Filter", section,
			     curCategory->filter());
    pSEQPrefs->setPrefString(prefBaseName + "FilterOut", section,
			     curCategory->filterout());
    pSEQPrefs->setPrefColor(prefBaseName + "Color", section,
			    curCategory->color());
  }

  QColor black("black");
  while (count <= tMaxNumCategories)
  {
    prefBaseName.sprintf("Category%d_", count++);
    pSEQPrefs->setPrefString(prefBaseName + "Name", section, "");
    pSEQPrefs->setPrefString(prefBaseName + "Filter", section, "");
    pSEQPrefs->setPrefString(prefBaseName + "FilterOut", section, "");
    pSEQPrefs->setPrefColor(prefBaseName + "Color", section, black);
  }
}
Example #7
0
int CategoryManager::addRule(const Rule& value)
{
    bslmt::LockGuard<bslmt::Mutex> guard(&d_ruleSetMutex);
    int ruleId = d_ruleSet.addRule(value);
    if (ruleId < 0) {
        return 0;                                                     // RETURN
    }

    ++d_ruleSequenceNum;

    const Rule *rule = d_ruleSet.getRuleById(ruleId);

    for (int i = 0; i < length(); ++i) {
        Category *category = d_categories[i];
        if (rule->isMatch(category->categoryName())) {
            CategoryManagerImpUtil::enableRule(category, ruleId);
            int threshold = ThresholdAggregate::maxLevel(
                                                      rule->recordLevel(),
                                                      rule->passLevel(),
                                                      rule->triggerLevel(),
                                                      rule->triggerAllLevel());
            if (threshold > category->ruleThreshold()) {
                CategoryManagerImpUtil::setRuleThreshold(category, threshold);
                CategoryManagerImpUtil::updateThresholdForHolders(category);
            }
        }
    }
    return 1;
}
Example #8
0
Category::List CategoryParser::parseList( const QString &xmlString )
{
  Category::List categoryList;
  
  QXmlStreamReader xml( xmlString );
  
  while ( !xml.atEnd() ) {
    xml.readNext();
    
    if ( xml.isStartElement() && xml.name() == "category" ) {
      Category category;

      while ( !xml.atEnd() ) {
        xml.readNext();

        if ( xml.isStartElement() ) {
          if ( xml.name() == "id" ) {
            category.setId( xml.readElementText() );
          } else if ( xml.name() == "name" ) {
            category.setName( xml.readElementText() );
          }
        }

        if ( xml.isEndElement() && xml.name() == "category" ) break;
      }
      
      categoryList.append( category );
    }
  }
  
  return categoryList;
}
    boost::shared_ptr< Base<EncodingT> > IncludeInstruction<EncodingT>::interpret(Context<EncodingT> & c)
    {
        typename EncodingT::string_t buf;
        boost::shared_ptr< Bool<EncodingT> > res(new Bool<EncodingT>(false));
        boost::shared_ptr< Base<EncodingT> > expr = m_instruction->interpret(c);

        Category * logger = &Category::getInstance(LOGNAME);
        if (!readFile(A(expr->toString()), buf))
        {
            logger->errorStream() << "Cannot open file '" << A(expr->toString()) << "'.";
        }
        else
        {
            typename EncodingT::string_t instructions;
            boost::shared_ptr< Term<EncodingT> > declaration, block;
            if (Declaration<EncodingT>::parse(buf, declaration, instructions) &&
                Block<EncodingT>::parse(instructions, block))
            {
                declaration->interpret(c);
                block->interpret(c);
                res->setValue(true);
            }
            else
            {
                logger->errorStream() << "An error occurred during the file interpretation '" << A(expr->toString()) << "'.";
            }
        }
        return res;
    }
Example #10
0
bool DbNote::existCategory(Category & category)
{
    sqlite3_stmt *statement;
    string stmnt = "select count(*) from KatTable where KatDesc like ? or KatKey = ?";
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Select-Statement failed in existCategory()");
        return false;
    }
    req = sqlite3_bind_text(statement, 1, category.getDesc().c_str(), category.getDesc().size(), 0 );
    req = sqlite3_bind_int(statement, 2, category.getKatKey());
    if (req != SQLITE_OK)
    {
        throw SQLError("Binding Date into select statement failed");
        return false;
    }
    req = sqlite3_step(statement);

    int catCount = static_cast<int>(sqlite3_column_int(statement, 0));

    sqlite3_finalize(statement);
    sqlite3_close(db);
    if (catCount > 0)
        return true;
    return false;


}
Example #11
0
bool CategoryModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) {
    if (action == Qt::IgnoreAction)
        return true;

    if (!data->hasFormat("application/editor.categorymodel.index"))
        return false;

    QByteArray encodedData = data->data("application/editor.categorymodel.index");
    QDataStream stream(&encodedData, QIODevice::ReadOnly);

    QList<Item*> items;

    while (!stream.atEnd()) {
        quint64 address;
        stream >> address;
        Item* item = reinterpret_cast<Item*>(address);
        items.push_back(item);
    }

    Category* category = static_cast<Category*>(parent.internalPointer());

    for (QList<Item*>::const_iterator it = items.begin(); it != items.end(); ++it) {
        Item* item = *it;
        if (!item->isCategory() || !item->toCategory()->isAncestorOf(category)) {
            QModelIndex parentIndex = createIndex(item->parent()->childNumber(), 1, item->parent());
            if (parentIndex != parent) {
                beginMoveRows(parentIndex, item->childNumber(), item->childNumber(), parent, rowCount(parent));
                category->addChild(item);
                endMoveRows();
            }
        }
    }

    return true;
}
Example #12
0
void tstCatMngr::testCreateNewCategory()
{
  printStartMsg("tstCatMngr::testCreateNewCategory");
  
  TournamentDB* db = getScenario01(true);
  CatMngr cmngr(db);
  
  // try empty or invalid name
  CPPUNIT_ASSERT(cmngr.createNewCategory("") == INVALID_NAME);
  CPPUNIT_ASSERT(cmngr.createNewCategory(QString::null) == INVALID_NAME);
  CPPUNIT_ASSERT((*db)[TAB_CATEGORY].length() == 0);
  
  // actually create a valid category
  CPPUNIT_ASSERT(cmngr.createNewCategory("c1") == OK);
  CPPUNIT_ASSERT((*db)[TAB_CATEGORY].length() == 1);
  TabRow r = (*db)[TAB_CATEGORY][1];
  CPPUNIT_ASSERT(r[GENERIC_NAME_FIELD_NAME].toString() == "c1");
  
  // make sure the default values are set correctly
  Category c = cmngr.getCategory("c1");
  CPPUNIT_ASSERT(c.getState() == STAT_CAT_CONFIG);
  CPPUNIT_ASSERT(c.getMatchSystem() == GROUPS_WITH_KO);
  CPPUNIT_ASSERT(c.getMatchType() == SINGLES);
  CPPUNIT_ASSERT(c.getSex() == M);
  
  // name collision
  CPPUNIT_ASSERT(cmngr.createNewCategory("c1") == NAME_EXISTS);
  CPPUNIT_ASSERT((*db)[TAB_CATEGORY].length() == 1);
  
  delete db;
  printEndMsg();
}
Example #13
0
/* virtual */ void ObjectSearcher::operator()()
{
    #ifdef SEARCHER_DEBUG
        std::cout << "Object Searcher Start" << std::endl;
    #endif
    ObjectList res;

    ObjectList::const_iterator catItr;
    catItr = mCategories.begin();
    while( mCategories.end() != catItr )
    {
        Category cat = *catItr;
        if( cat.areObjectsSearchable() )
        {
            #ifdef SEARCHER_DEBUG
                std::cout << "Checking category: " << cat.getTitle() << std::endl;
            #endif
            res.add( cat.filterWithSelector( mSelector, mSearchText ) );
        }
        catItr++;
    }

    #ifdef SEARCHER_DEBUG
        std::cout << "Object Searcher Done" << std::endl;
    #endif
    reportSearchDone( res );
}
Example #14
0
// PRIVATE MANIPULATORS
Category *CategoryManager::addNewCategory(const char *categoryName,
                                          int         recordLevel,
                                          int         passLevel,
                                          int         triggerLevel,
                                          int         triggerAllLevel)
{
    // Create a new category and add it to the collection of categories
    // and the category registry.

    Category *category = new (*d_allocator_p) Category(categoryName,
                                                       recordLevel,
                                                       passLevel,
                                                       triggerLevel,
                                                       triggerAllLevel,
                                                       d_allocator_p);
    // rollback on failure
    CategoryProctor proctor(category, d_allocator_p);

    d_categories.push_back(category);
    proctor.setCategories(&d_categories);

    d_registry[category->categoryName()] =
                                     static_cast<int>(d_categories.size() - 1);
    proctor.release();

    return category;
}
Example #15
0
void CSpy360Dlg::OnBnClickedGetRubbish()
{
	enum{id = 9};

	Category* pCategory = NULL;
	DObj* pDObj = NULL;

	if(!ThisCall(gpSysSweeper->m8_pIRubbishClean,IRubbishClean__GetObj,id,&pCategory, &pDObj))
		return;

	CString s,s1;
	if(pCategory)
	{
		File f;
		s.Format("C:\\Rubbish%d.txt",id);
		if(!f.Open(s,"wb"))
			return;

		VecKObj* pVecKObj = pCategory->m40_vecKObj();
		for(ULONG i = 0;i<pVecKObj->m4_nItem;i++)
		{
			KObj* pKObj = pVecKObj->m0_ppItem[i];

			s1 = pKObj->m8_pathFile;
			s.Format("%s\r\n",s1);
			::fwrite(s,s.GetLength(),1,f);
		}
	}
}
Example #16
0
void tstCatMngr::testGetAllCategories()
{
  printStartMsg("tstCatMngr::testGetAllCategories");
  
  TournamentDB* db = getScenario01(true);
  CatMngr cmngr(db);
  
  // run on empty table
  QList<Category> result = cmngr.getAllCategories();
  CPPUNIT_ASSERT(result.length() == 0);
  
  // actually create a valid category
  CPPUNIT_ASSERT(cmngr.createNewCategory("c1") == OK);
  CPPUNIT_ASSERT(cmngr.createNewCategory("c2") == OK);
  
  // run on filled table
  result = cmngr.getAllCategories();
  CPPUNIT_ASSERT(result.length() == 2);
  Category c = result.at(0);
  CPPUNIT_ASSERT(c.getId() == 1);
  CPPUNIT_ASSERT(c.getName() == "c1");
  c = result.at(1);
  CPPUNIT_ASSERT(c.getId() == 2);
  CPPUNIT_ASSERT(c.getName() == "c2");
  
  delete db;
  printEndMsg();
}
Example #17
0
/*!
 * \brief Updates the activity the record belongs to.
 */
void Record::updateActivity(Activity *activity)
{
    if (m_activity && (m_activity->databaseId() != activity->databaseId())) {
        m_activity->setDatabaseId(activity->databaseId());
        m_activity->setName(activity->name());
        m_activity->setMinRepeats(activity->minRepeats());
        m_activity->setMaxRepeats(activity->maxRepeats());
        m_activity->setUseRepeats(activity->useRepeats());
        m_activity->setUseDistance(activity->useDistance());
        m_activity->setRecords(activity->records());

        Category *c = m_activity->category();
        Category *o = activity->category();

        if (c) {
            c->setDatabaseId(o->databaseId());
            c->setName(o->name());
            c->setColor(o->color());
            c->setActivities(o->activities());
        }

        if (!m_activity->useRepeats()) {
            setRepetitions(0);
        }

        if (!m_activity->useDistance()) {
            setDistance(0.0);
        }
    }
}
Example #18
0
void Override::loadACL(const DOMElement* e, Category& log)
{
    IPlugIn* plugin=NULL;
    const DOMElement* acl=saml::XML::getFirstChildElement(e,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(htaccess));
    if (acl) {
        log.info("building htaccess provider...");
        plugin=ShibConfig::getConfig().m_plugMgr.newPlugin(shibtarget::XML::htaccessType,acl);
    }
    else {
        acl=saml::XML::getFirstChildElement(e,ShibTargetConfig::SHIBTARGET_NS,SHIBT_L(AccessControlProvider));
        if (acl) {
            auto_ptr_char type(acl->getAttributeNS(NULL,SHIBT_L(type)));
            log.info("building Access Control provider of type %s...",type.get());
            plugin=ShibConfig::getConfig().m_plugMgr.newPlugin(type.get(),acl);
        }
    }
    if (plugin) {
        IAccessControl* acl=dynamic_cast<IAccessControl*>(plugin);
        if (acl)
            m_acl=acl;
        else {
            delete plugin;
            log.fatal("plugin was not an Access Control provider");
            throw UnsupportedExtensionException("plugin was not an Access Control provider");
        }
    }
}
// Convenience to find a widget by class name
bool QDesignerWidgetBox::findWidget(const QDesignerWidgetBoxInterface *wbox,
                                    const QString &className,
                                    const QString &category,
                                    Widget *widgetData)
{
    // Note that entry names do not necessarily match the class name
    // (at least, not for the standard widgets), so,
    // look in the XML for the class name of the first widget to appear
    const QString widgetTag = QLatin1String("<widget");
    QString pattern = QLatin1String("^<widget\\s+class\\s*=\\s*\"");
    pattern += className;
    pattern += QLatin1String("\".*$");
    const QRegExp regexp(pattern);
    Q_ASSERT(regexp.isValid());
    const int catCount = wbox->categoryCount();
    for (int c = 0; c < catCount; c++) {
        const Category cat = wbox->category(c);
        if (category.isEmpty() || cat.name() == category) {
            const int widgetCount =  cat.widgetCount();
            for (int w = 0; w < widgetCount; w++) {
                const Widget widget = cat.widget(w);
                QString xml = widget.domXml(); // Erase the <ui> tag that can be present starting from 4.4
                const int widgetTagIndex = xml.indexOf(widgetTag);
                if (widgetTagIndex != -1) {
                    xml.remove(0, widgetTagIndex);
                    if (regexp.exactMatch(xml)) {
                        *widgetData = widget;
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Example #20
0
void PManagerTest::test_load_db() {
    Test::print("test_load_db ");
    bool ret;
    PManager pm;
    ofstream file;
    file.open("testdb.kal");
    file << "INSERT INTO Categories VALUES(" << this->valid_category->getId() << ",'" << this->valid_category->getName() << "','" << this->valid_category->getColor() << "');" << endl;
    file << "INSERT INTO Events VALUES(" << this->valid_event->getId() << ",'" << this->valid_event->getName() << "','" << this->valid_event->getDescription() << "','" << this->valid_event->getPlace() << "'," << this->valid_event->getCategory()->getId() << "," << this->valid_event->getStart() << "," << this->valid_event->getEnd() << ", NULL);" << endl;
    file.close();
    ret = pm.load_db("");
    ret = !ret && pm.load_db("notexist");
    ret = !ret && pm.load_db("testdb.kal");
    Category *category = pm.get_category(this->valid_category->getId());
    ret = ret && category->equals(*this->valid_category);
    delete category;
    list<Event*> events = pm.get_all_events();
    if (events.size() == 1) {
        list<Event*>::iterator it = events.begin();
        ret = ret && this->valid_event->equals(**it); // *it has type Event*
        delete *it;
    } else ret = false;
    pm.remove_db();
    remove("testdb.kal");
    ASSERT (ret)
}
Example #21
0
void CategoryTest::TestGettersSetters()
{
	Category c;
	CPPUNIT_ASSERT(c.GetName() == DEF_CATEGORY_NAME);

	c.SetName("mycategory");
	CPPUNIT_ASSERT(c.GetName() == "mycategory");
}
Example #22
0
/**
   @brief Create a new category
 
   Create a new category to be stored into the database; the method 
   store need to be called to make changes persistent.
   
   @param    aValue    The category name
   @return    An instance of the new category
 */
Category *Category::factory(string aValue)
{
    Category *newCategory = new Category();
    newCategory->setIntForKey(KEY_CAT_CID, 0);
    newCategory->setValueForKey(KEY_CAT_NAME, aValue);
    
    return newCategory;
}
Example #23
0
QModelIndex CategoryModel::createCategory(const QModelIndex& parent) {
    Category* category = new Category;
    category->setName("NewCategory");
    QModelIndex index = addItem(category, parent);
    if (!index.isValid())
        delete category;

    return index;
}
Example #24
0
void CategoryModel::destroyChild(int row, const QModelIndex& parent) {
    Category* category = mRoot;
    if (parent.isValid())
        category = static_cast<Category*>(parent.internalPointer());

    beginRemoveRows(parent, row, row);
    delete category->removeChild(row);
    endRemoveRows();
}
Example #25
0
//---------------------------------------------------------
// findSubcategory
//  take hbank and lbank and return the subcategory corresponding,
//  NULL if doesn't exist
//---------------------------------------------------------
Subcategory* Set::findSubcategory(int hbank, int lbank) {
  Category* c = findCategory(hbank);
  Subcategory* s;
  if(c) {
    s = c->findSubcategory(lbank);
    return s;
  }
  else return NULL;
}
Example #26
0
bool LocalStore::Delete(const char* identifier)
{
	if (identifier == NULL)
	{
		return false;
	}

	Category* category = &m_rootCategory;
	Entry* entry = NULL;

	int identifierLen = strlen(identifier);
	char* identifierCopy = new char[identifierLen];
	memcpy(identifierCopy, identifier, identifierLen);

	//Loop over tokens
	char* nextToken = NULL;
	char* token = strtok(identifierCopy, ".");
	while (token != NULL)
	{
		//The next token is retrieved first so that we know which one is the last one.
		nextToken = strtok(NULL, ".");

		//If we haven't reached the last token, then the current one is a category.
		if (nextToken != NULL)
		{
			category = category->GetSubcategory(token);
		}
		//Otherwise we've reached the value.
		else
		{
			//Iterate through and delete
			List<Entry*>& entries = category->GetEntries();
			List<Entry*>::Node* n = entries.Begin();
			while (n != NULL)
			{
				if (n->GetValue()->GetName() == token)
				{
					delete n->GetValue();
					entries.Erase(n);

					delete[] identifierCopy;

					return true;
				}

				n = n->GetNext();
			}
		}

		//Next token becomes current token for next loop iteration.
		token = nextToken;
	}

	delete[] identifierCopy;

	return false;
}
Example #27
0
bool DbNote::insertTable(Category & cat)
{
    sqlite3_stmt *statement;
    string stmnt = "insert into KatTable (KatDesc) values (?)";
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, stmnt.c_str(), stmnt.length(), &statement,
                                 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Insert-Statement failed");
        return false;
    }
    req = sqlite3_bind_text(statement, 1, (cat.getDesc()).c_str(),
                            (cat.getDesc()).length(), SQLITE_TRANSIENT);
    if (req != SQLITE_OK)
    {
        throw SQLError(
            "Binding category descripting into insert statement failed");
        return false;
    }
    req = sqlite3_step(statement);
    if (req != SQLITE_DONE)
    {
        throw SQLError("execute of insert statement failed");
        return false;
    }
    sqlite3_finalize(statement);

    stmnt = "select seq from sqlite_sequence where name = \"KatTable\"";
    req = sqlite3_prepare_v2(db, stmnt.c_str(), stmnt.length(), &statement,
                             0);
    if (req == SQLITE_ERROR)
    {
        throw SQLError("Can't select data of the given table");
        return false;
    }
    sqlite3_column_count(statement);
    req = sqlite3_step(statement);
    if (req == SQLITE_ROW)
    {
        int nextseq = (int) sqlite3_column_int(statement, 0);
        cat.setKatKey( nextseq );
    }
    else
    {
        throw SQLError("execute of select failed");
        return false;
    }
    sqlite3_finalize(statement);
    sqlite3_close(db);
    return true;
}
Example #28
0
void CategoryModel::destroyCategory(int row, const QModelIndex& parent) {
    Category* category = mRoot;
    if (parent.isValid())
        category = static_cast<Category*>(parent.internalPointer());

    if (category->child(row)->isCategory()) {
        Item* item = removeItem(row, parent);
        delete item;
    }
}
Example #29
0
QModelIndex CategoryModel::createChild(const QModelIndex& parent) {
    Category* category = mRoot;
    if (parent.isValid())
        category = static_cast<Category*>(parent.internalPointer());

    QSet<QString> names;
    for (int n = 0; n < category->childCount(); ++n) {
        names.insert(category->child(n)->name().toLower());
    }

    int n = 1;
    QString name("newcategory%1");
    while (names.contains(name.arg(QString::number(n)))) {
        ++n;
    }

    name = "NewCategory";
    name.append(QString::number(n));


    beginInsertRows(parent, category->childCount(), category->childCount());

    Category* child = new Category;
    category->addChild(child);
    child->setName(name);

    endInsertRows();

    return createIndex(category->childCount() - 1, 0, child);
}
Example #30
0
Item* CategoryModel::removeItem(int row, const QModelIndex& parent) {
    Category* category = mRoot;
    if (parent.isValid())
        category = static_cast<Category*>(parent.internalPointer());

    beginRemoveRows(parent, row, row);
    Item* item = category->removeChild(row);
    endRemoveRows();

    return item;
}