void MangaListWidget::updateChaptersInfo(QModelIndex index) {
  QStandardItem* currentItem = _model->itemFromIndex(index);
  QDir chapterDir = _scansDirectory;

  if (!currentItem->parent())
    return;

  chapterDir.cd(currentItem->parent()->text());
  chapterDir.cd(currentItem->text());

  QStringList pagesList = Utils::filesList(chapterDir);

  if (pagesList.size() == 0)
    return;

  qint64 totalSize = 0;
  for (const QString& pageName: pagesList) {
    QFile currFile(chapterDir.path()+"/"+pageName);
    totalSize += currFile.size();
  }
  double chapterSize = totalSize/(1024.*1024.);

  QFileInfo chapterDirInfo(chapterDir.path());

  _chapterInfoWidget->setNumberFiles(QString::number(pagesList.size()));
  _chapterInfoWidget->setTotalSize(QString::number(chapterSize, 'f', 2)+"MB");
  _chapterInfoWidget->setLastModification(chapterDirInfo.lastModified().toString("ddd dd MMM yyyy"));
  _chapterInfoWidget->setLastRead(chapterDirInfo.lastRead().toString("ddd dd MMM yyyy"));

  if (pagesList.size() > 0)
    _chapterInfoWidget->setImgPreview(QPixmap(chapterDir.path()+"/"+pagesList.at(0)));
  else
    _chapterInfoWidget->setImgPreview(QPixmap());
}
示例#2
0
void SpotifyService::ShowContextMenu(const QPoint& global_pos) {
  EnsureMenuCreated();
  QStandardItem* item = model()->itemFromIndex(model()->current_index());
  if (item) {
    int type = item->data(InternetModel::Role_Type).toInt();
    if (type == Type_InboxPlaylist || type == Type_StarredPlaylist ||
        type == InternetModel::Type_UserPlaylist) {
      playlist_sync_action_->setData(qVariantFromValue(item));
      playlist_context_menu_->popup(global_pos);
      current_playlist_url_ = item->data(InternetModel::Role_Url).toUrl();
      get_url_to_share_playlist_->setVisible(type ==
                                             InternetModel::Type_UserPlaylist);
      return;
    } else if (type == InternetModel::Type_Track) {
      current_song_url_ = item->data(InternetModel::Role_Url).toUrl();
      // Is this track contained in a playlist we can modify?
      bool is_playlist_modifiable =
          item->parent() &&
          item->parent()->data(InternetModel::Role_CanBeModified).toBool();
      remove_from_playlist_->setVisible(is_playlist_modifiable);

      song_context_menu_->popup(global_pos);
      return;
    }
  }

  context_menu_->popup(global_pos);
}
示例#3
0
QVariant Project::data(const QModelIndex &index, int role) const
{
    if (role==Qt::UserRole) {
        QStandardItem* item = itemFromIndex(index);
        if (item->parent()==NULL || item->parent()==invisibleRootItem()) {
            if (item==projectFile) {
                return "00 - project";
            }
            //if (item==mzn) {
            //    return "01 - mzn";
            //}
            if (item==zinc) {
                return "01 - zinc";
            }
            if (item==dzn) {
                return "02 - dzn";
            }
            if (item==other) {
                return "03 - other";
            }
        }
        return QStandardItemModel::data(index,Qt::DisplayRole);
    } else {
        return QStandardItemModel::data(index,role);
    }
}
示例#4
0
bool TrialTreeModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
	if (QStandardItemModel::dropMimeData(mimeData, action, row, column, parent))
		return true;

	if (mimeData->hasUrls())
	{
		const QList<QUrl> urls = mimeData->urls();
		QStandardItem * dropInto = itemFromIndex(parent);
		if (dropInto && !dropInto->data().isNull())
		{
			// printf("Dropping onto '%s'\n", dropInto->data().toString().toAscii().data());
			QStandardItem * const tmp = new QStandardItem("Group");
			QStandardItem * const p = (dropInto->parent() ? dropInto->parent() : invisibleRootItem());
			p->insertRow(dropInto->row(), tmp);
			tmp->setChild(0, 0, dropInto->clone());
			p->removeRow(dropInto->row());
			dropInto = tmp;
		}
		if (!dropInto)
			dropInto = invisibleRootItem();
		int i = 0;
		for (QList<QUrl>::const_iterator it = urls.begin(); it != urls.end(); ++it, i++)
		{
			QFileInfo fileInfo(it->toLocalFile());
			QStandardItem * const newItem = new QStandardItem(fileInfo.fileName());
			newItem->setData(QDir::current().relativeFilePath(fileInfo.filePath()));
			newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled/* | Qt::ItemIsDropEnabled*/);
			dropInto->appendRow(newItem);
		}
		return true;
	}
	return false;
}
/** Highlight items in the Tree when one has activated this option in settings. */
void MiamSortFilterProxyModel::highlightMatchingText(const QString &text)
{
	// Clear highlight on every call
	std::function<void(QStandardItem *item)> recursiveClearHighlight;
	recursiveClearHighlight = [&recursiveClearHighlight] (QStandardItem *item) -> void {
		if (item->hasChildren()) {
			item->setData(false, Miam::DF_Highlighted);
			for (int i = 0; i < item->rowCount(); i++) {
				recursiveClearHighlight(item->child(i, 0));
			}
		} else {
			item->setData(false, Miam::DF_Highlighted);
		}
	};

	QStandardItemModel *_libraryModel = qobject_cast<QStandardItemModel*>(this->sourceModel());
	for (int i = 0; i < _libraryModel->rowCount(); i++) {
		recursiveClearHighlight(_libraryModel->item(i, 0));
	}

	// Adapt filter if one is typing '*'
	QString filter;
	Qt::MatchFlags flags;
	if (text.contains(QRegExp("^(\\*){1,5}$"))) {
		this->setFilterRole(Miam::DF_Rating);
		filter = "[" + QString::number(text.size()) + "-5]";
		flags = Qt::MatchRecursive | Qt::MatchRegExp;
	} else {
		this->setFilterRole(Qt::DisplayRole);
		filter = text;
		flags = Qt::MatchRecursive | Qt::MatchContains;
	}

	// Mark items with a bold font
	QSet<QChar> lettersToHighlight;
	if (!text.isEmpty()) {
		QModelIndexList indexes = _libraryModel->match(_libraryModel->index(0, 0, QModelIndex()), this->filterRole(), filter, -1, flags);
		QList<QStandardItem*> items;
		for (int i = 0; i < indexes.size(); ++i) {
			items.append(_libraryModel->itemFromIndex(indexes.at(i)));
		}
		for (QStandardItem *item : items) {
			item->setData(true, Miam::DF_Highlighted);
			QStandardItem *parent = item->parent();
			// For every item marked, mark also the top level item
			while (parent != nullptr) {
				parent->setData(true, Miam::DF_Highlighted);
				if (parent->parent() == nullptr) {
					lettersToHighlight << parent->data(Miam::DF_NormalizedString).toString().toUpper().at(0);
				}
				parent = parent->parent();
			}
		}
	}
	qDebug() << Q_FUNC_INFO << lettersToHighlight;
	emit aboutToHighlightLetters(lettersToHighlight);
}
示例#6
0
    void removeExistingItem(const QString& path)
    {
        if (!itemsByPath.contains(path)) {
            return;
        }

        QStandardItem *existingItem = itemsByPath[path];
        //kDebug() << "Removing existing item" << existingItem;
        Q_ASSERT(existingItem->parent());
        existingItem->parent()->removeRow(existingItem->row());
        itemsByPath.remove(path);
    }
示例#7
0
void Model::activated(const QModelIndex& index)
{
	//TODO optimize
	QStandardItem* item = itemFromIndex(index);
	Q_ASSERT(item);
	Contact *contact = item->data().value<Contact*>();
	if(!contact)
		return;
	if(!(item->parent() == m_metaRoot))
		addContact(contact, m_metaRoot);

	item->parent()->removeRow(index.row());
}
示例#8
0
/* The code below does work, but is way too slow for large lists, and
   is kept here only for reference. Both takeRow() and appendRow()
   seem to need too much time, especially when there are child
   items. The alternative method we use to flatten the tree is
   to recreate it from scratch as a list, see msg_list_window::toggle_threaded() */
void
mail_item_model::flatten()
{
  QMap<mail_id_t, QStandardItem*>::iterator it;
  for (it=items_map.begin(); it!=items_map.end(); ++it) {
    QStandardItem* item = it.value();
    if (item->parent()) {
      QModelIndex index=this->indexFromItem(item);
      QList<QStandardItem*> ql=item->parent()->takeRow(index.row());
      this->appendRow(ql);
    }
  }
}
void MangaListWidget::goToDownload(void) {
  QStandardItem* currentItem = _model->itemFromIndex(_view->currentIndex());

  if (!currentItem) {
    QMessageBox::warning(this, "Warning", "No manga selected.");
    return;
  }

  QString mangaName;
  currentItem->parent() == nullptr ? mangaName = currentItem->text() : mangaName = currentItem->parent()->text();

  emit mangaSelected(mangaName);
}
示例#10
0
Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const
{
    Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    if ( !index.isValid() )
    {
        flags |= Qt::ItemIsDropEnabled;
        return flags;
    }

    QStandardItem* item = itemFromIndex( index );
    QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( item );

    if ( cItem )
    {
        QgsComposerLegendItem::ItemType type = cItem->itemType();
        if ( type == QgsComposerLegendItem::GroupItem )
        {
            flags |= Qt::ItemIsDragEnabled;
            flags |= Qt::ItemIsDropEnabled;
        }
        else if ( type == QgsComposerLegendItem::LayerItem )
        {
            flags |= Qt::ItemIsDragEnabled;
        }
    }
    if ( index.column() == 1 && item )
    {
        // Style
        QStandardItem* firstColumnItem = 0;
        if ( item->parent() )
        {
            firstColumnItem = item->parent()->child( index.row(), 0 );
        }
        else
        {
            firstColumnItem = QgsLegendModel::item( index.row(), 0 );
        }
        cItem = dynamic_cast<QgsComposerLegendItem*>( firstColumnItem );

        if ( cItem )
        {
            if ( cItem->itemType() == QgsComposerLegendItem::GroupItem ||
                    cItem->itemType() == QgsComposerLegendItem::LayerItem )
            {
                flags |= Qt::ItemIsEditable;
            }
        }
    }
    return flags;
}
示例#11
0
// private slot
void FilesWidget::setCurrentChild(Document *document)
{
    // Set current child and parent back to normal
    if (m_currentChild != NULL) {
        markItemAsCurrent(m_currentChild, false);

        QStandardItem *parent = m_currentChild->parent();

        m_currentChild = NULL;

        updateParentItemMarkers(parent);
    }

    // Mark new current child as current
    if (document != NULL) {
        QStandardItem *child = m_children.value(document, NULL);

        Q_ASSERT(child != NULL);

        QStandardItem *parent = child->parent();

        Q_ASSERT(parent != NULL);

        m_treeFiles->expand(parent->index());
        m_treeFiles->scrollTo(child->index());
        m_treeFiles->selectionModel()->select(child->index(), QItemSelectionModel::ClearAndSelect);

        m_currentChild = child;

        markItemAsCurrent(m_currentChild, true);
        updateParentItemMarkers(parent);
    }
}
示例#12
0
// private slot
void FilesWidget::removeDocument(Document *document)
{
    Q_ASSERT(document != NULL);

    disconnect(document, &Document::modificationChanged, this, &FilesWidget::updateModificationMarkerOfSender);
    disconnect(document, &Document::locationChanged, this, &FilesWidget::updateLocationOfSender);

    QStandardItem *child = m_children.value(document, NULL);

    Q_ASSERT(child != NULL);
    Q_ASSERT(child != m_currentChild);

    QStandardItem *parent = child->parent();

    Q_ASSERT(parent != NULL);

    parent->removeRow(child->row());

    if (parent->rowCount() > 0) {
        updateParentItemMarkers(parent);
    } else {
        m_model.removeRow(parent->row());
    }

    m_children.remove(document);

    if (m_currentChild != NULL) {
        m_treeFiles->selectionModel()->select(m_currentChild->index(), QItemSelectionModel::ClearAndSelect);
    }
}
示例#13
0
void EditTOC::MoveRight()
{
    QModelIndex index = CheckSelection(0);
    if (!index.isValid()) {
        return;
    }

    QStandardItem *item = m_TableOfContents->itemFromIndex(index);
    int item_row = item->row();

    // Can't indent if row above is already parent
    if (item_row == 0) {
        return;
    }

    QStandardItem *parent_item = item->parent();
    if (!parent_item) {
        parent_item = m_TableOfContents->invisibleRootItem();
    }

    // Make the item above the parent of this item
    QList<QStandardItem *> row_items = parent_item->takeRow(item_row);
    QStandardItem *new_parent = parent_item->child(item_row - 1, 0);
    new_parent->insertRow(new_parent->rowCount(), row_items);
    QStandardItem *new_item = new_parent->child(new_parent->rowCount() - 1, 0);

    // Reselect the item
    ui.TOCTree->selectionModel()->clear();
    ui.TOCTree->setCurrentIndex(item->index());
    ui.TOCTree->selectionModel()->select(item->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
    ExpandChildren(new_item);
}
示例#14
0
void
mail_item_model::remove_msg(mail_msg* msg)
{
  DBG_PRINTF(8, "remove_msg(mail_id=" MAIL_ID_FMT_STRING ")", msg->get_id());
  QMap<mail_id_t, QStandardItem*>::iterator it = items_map.find(msg->get_id());
  if (it!=items_map.end()) {
    QStandardItem* item = it.value();
    QStandardItem* parent_item = item->parent();
    while (item->child(0,0)!=NULL) {
      // reparent childs of the item to remove
      QList<QStandardItem*> ql = item->takeRow(0);
      if (parent_item) {
	DBG_PRINTF(9, "reparenting child to immediate parent row=%d", item->index().row());
	parent_item->insertRow(item->index().row(), ql);
      }
      else {
	DBG_PRINTF(9, "reparenting child to root");
	insertRow(item->index().row(), ql);
      }
    }
    // 
    DBG_PRINTF(9, "removing mail_id=" MAIL_ID_FMT_STRING
	       " from model at index.row=%d index.column=%d",
	       msg->get_id(), item->index().row(),
	       item->index().column());
    QModelIndex index = item->index();
    removeRow(index.row(), index.parent());
    items_map.erase(it);
  }
  else {
    DBG_PRINTF(1, "ERR: mail_id=" MAIL_ID_FMT_STRING " not found in items_map", msg->get_id());
  }
}
示例#15
0
bool PlacesModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) {
  QStandardItem* item = itemFromIndex(parent);
  if(data->hasFormat("application/x-bookmark-row")) { // the data being dopped is a bookmark row
    // decode it and do bookmark reordering
    QByteArray buf = data->data("application/x-bookmark-row");
    QDataStream stream(&buf, QIODevice::ReadOnly);
    int oldPos = -1;
    char* pathStr = NULL;
    stream >> oldPos >> pathStr;
    // find the source bookmark item being dragged
    GList* allBookmarks = fm_bookmarks_get_all(bookmarks);
    FmBookmarkItem* draggedItem = static_cast<FmBookmarkItem*>(g_list_nth_data(allBookmarks, oldPos));
    // If we cannot find the dragged bookmark item at position <oldRow>, or we find an item,
    // but the path of the item is not the same as what we expected, than it's the wrong item.
    // This means that the bookmarks are changed during our dnd processing, which is an extremely rare case.
    if(!draggedItem || !fm_path_equal_str(draggedItem->path, pathStr, -1)) {
      delete []pathStr;
      return false;
    }
    delete []pathStr;

    int newPos = -1;
    if(row == -1 && column == -1) { // drop on an item
      // we only allow dropping on an bookmark item
      if(item && item->parent() == bookmarksRoot)
        newPos = parent.row();
    }
    else { // drop on a position between items
      if(item == bookmarksRoot) // we only allow dropping on a bookmark item
        newPos = row;
    }
    if(newPos != -1 && newPos != oldPos) // reorder the bookmark item
      fm_bookmarks_reorder(bookmarks, draggedItem, newPos);
  }
示例#16
0
void EditTOC::AddEntry(bool above)
{
    QModelIndex index = CheckSelection(0);
    if (!index.isValid()) {
        return;
    }

    QStandardItem *item = m_TableOfContents->itemFromIndex(index);

    QStandardItem *parent_item = item->parent();
    if (!parent_item) {
        parent_item = m_TableOfContents->invisibleRootItem();
    }

    // Add a new empty row of items
    QStandardItem *entry_item = new QStandardItem();
    QStandardItem *target_item = new QStandardItem();
    QList<QStandardItem *> row_items;
    row_items << entry_item << target_item ;
    int location = 1;
    if (above) {
        location = 0;
    }
    parent_item->insertRow(item->row() + location,row_items);

    // Select the new row
    ui.TOCTree->selectionModel()->clear();
    ui.TOCTree->setCurrentIndex(entry_item->index());
    ui.TOCTree->selectionModel()->select(entry_item->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
}
示例#17
0
void EditTOC::MoveDown()
{
    QModelIndex index = CheckSelection(0);
    if (!index.isValid()) {
        return;
    }
    QStandardItem *item = m_TableOfContents->itemFromIndex(index);

    QStandardItem *parent_item = item->parent();
    if (!parent_item) {
        parent_item = m_TableOfContents->invisibleRootItem();
    }

    int item_row = item->row();

    // Can't move down if this row is already the last one of its parent
    if (item_row == parent_item->rowCount() - 1) {
        return;
    }

    QList<QStandardItem *> row_items = parent_item->takeRow(item_row);
    parent_item->insertRow(item_row + 1, row_items);

    // Reselect the item
    ui.TOCTree->selectionModel()->clear();
    ui.TOCTree->setCurrentIndex(item->index());
    ui.TOCTree->selectionModel()->select(item->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
    ExpandChildren(item);
}
示例#18
0
//---------------------------------------------------------------------------
void TableDialog::moveUp(void) {
  QList<QModelIndex> indexes = selectModel->selectedRows();
  
  if (indexes.isEmpty()) return;

  // Retrieve the row of the last selected item.

  QModelIndex index = indexes.last();
  QStandardItem *item = tableModel->itemFromIndex(index);
  int row = index.row();

  if (row == 0 || item->parent() != 0) return;
  selectModel->clearSelection();

  // Record whether the items where expanded or not.

  QModelIndex index_prev = tableModel->index(row-1, 0); 
  QModelIndex index_curr = tableModel->index(row, 0);
  
  bool expand_prev = tableView->isExpanded(index_prev);
  bool expand_curr = tableView->isExpanded(index_curr);

  tableView->setExpanded(index_prev, false);
  tableView->setExpanded(index_curr, false);

  swap(row-1, row);

  selectModel->select(index_prev, 
		      QItemSelectionModel::Select | 
		      QItemSelectionModel::Rows);

  tableView->setExpanded(index_curr, expand_prev);
  tableView->setExpanded(index_prev, expand_curr);
}
void PlaylistListContainer::RemovePlaylist(int id) {
  QStandardItem* item = model_->PlaylistById(id);
  if (item) {
    QStandardItem* parent = item->parent();
    if (!parent) {
      parent = model_->invisibleRootItem();
    }
    parent->removeRow(item->row());
  }
}
示例#20
0
QStandardItem *StandardTreeModel::insertNewTask(Insert insert,
        const QString &name, const QModelIndex &index)
{
    QStandardItem *parent;
    if (insert == AtTopLevel)
        parent = invisibleRootItem();
    else {
        if (index.isValid()) {
            parent = itemFromIndex(index);
            if (!parent)
                return 0;
            if (insert == AsSibling)
                parent = parent->parent() ? parent->parent()
                                          : invisibleRootItem();
        }
        else
            return 0;
    }
    return createNewTask(parent, name, false);
}
void MangaListWidget::keyReleaseEvent(QKeyEvent* event) {
  // Enter released
  if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
    QModelIndex index = _view->currentIndex();
    QStandardItem* currentItem = _model->itemFromIndex(index);

    if (currentItem && currentItem->parent())
      goToRead(index);
  }

  // Up arrow or Down arrow released
  if (event->key() == Qt::Key_Down || event->key() == Qt::Key_Up) {
    QModelIndex index = _view->currentIndex();
    QStandardItem* currentItem = _model->itemFromIndex(index);

    if (currentItem && !currentItem->parent()) {
      updateMangaInfo(index);
    }
  }
}
示例#22
0
bool DebuggerItemModel::removeDebuggerStandardItem(const QVariant &id)
{
    QStandardItem *sitem = findStandardItemById(id);
    QTC_ASSERT(sitem, return false);
    QStandardItem *parent = sitem->parent();
    QTC_ASSERT(parent, return false);
    // This will trigger a change of m_currentDebugger via changing the
    // view selection.
    parent->removeRow(sitem->row());
    return true;
}
示例#23
0
// private
void FilesWidget::updateModificationMarker(Document *document)
{
    Q_ASSERT(document != NULL);

    QStandardItem *item = m_children.value(document, NULL);

    Q_ASSERT(item != NULL);

    markItemAsModified(item, document->isModified());
    updateParentItemMarkers(item->parent());
}
void MangaListWidget::goToRead(QModelIndex modelIndex) {
  QStandardItem* currentItem = _model->itemFromIndex(modelIndex);
  QStandardItem* currentItemParent = currentItem->parent();

  if (currentItemParent == nullptr)
    return;

  markRead();

  emit chapterSelected(currentItemParent->text(), currentItem->text());
}
示例#25
0
QStringList StandardTreeModel::pathForIndex(const QModelIndex &index)
    const
{
    QStringList path;
    if (index.isValid()) {
        QStandardItem *item = itemFromIndex(index);
        while (item) {
            path.prepend(item->text());
            item = item->parent();
        }
    }
    return path;
}
示例#26
0
void tst_QStandardItem::parent()
{
    {
        QStandardItem item;
        QStandardItem *child = new QStandardItem;
        QCOMPARE(child->parent(), static_cast<QStandardItem*>(0));
        item.setChild(0, 0, child);
        QCOMPARE(child->parent(), &item);
        
        QStandardItem *childOfChild = new QStandardItem;
        child->setChild(0, 0, childOfChild);
        QCOMPARE(childOfChild->parent(), child);
    }

    {
        QStandardItemModel model;
        QStandardItem *item = new QStandardItem;
        model.appendRow(item);
        // parent of a top-level item should be 0
        QCOMPARE(item->parent(), static_cast<QStandardItem*>(0));
    }
}
void AbstractCameraManager::removeGroup(QModelIndex index) {
    QStandardItem * item = getModel()->itemFromIndex( index );
    if( !item->isEditable() ) return;

    QStandardItem * parent = item->parent();
    if( parent == NULL ) parent = item->model()->invisibleRootItem();

    for(int i=item->rowCount(); i>0; i--) {
        newCameraList.insertRow(0, item->takeRow(0));
    }

    parent->removeRow( item->row() );
    detectNewCamerasAndExpand();
}
示例#28
0
void HistoryContentsWidget::updateEntry(qint64 entry)
{
	QStandardItem *entryItem = findEntry(entry);

	if (!entryItem)
	{
		addEntry(entry);

		return;
	}

	HistoryEntry historyEntry = HistoryManager::getEntry(entry);

	entryItem->setIcon(historyEntry.icon.isNull() ? Utils::getIcon(QLatin1String("text-html")) : historyEntry.icon);
	entryItem->setText(historyEntry.url.toString());
	entryItem->parent()->child(entryItem->row(), 1)->setText(historyEntry.title.isEmpty() ? tr("(Untitled)") : historyEntry.title);
	entryItem->parent()->child(entryItem->row(), 2)->setText(historyEntry.time.toString());

	if (!m_ui->filterLineEdit->text().isEmpty())
	{
		filterHistory(m_ui->filterLineEdit->text());
	}
}
示例#29
0
void Project::removeFile(const QString &fileName)
{
    if (fileName.isEmpty())
        return;
    if (!_files.contains(fileName)) {
        qDebug() << "Internal error: file " << fileName << " not in project";
        return;
    }
    setModified(true, true);
    QModelIndex index = _files[fileName];
    _files.remove(fileName);
    QStandardItem* cur = itemFromIndex(index);
    while (cur->parent() != NULL && cur->parent() != invisibleRootItem() && !cur->hasChildren()) {
        int row = cur->row();
        cur = cur->parent();
        cur->removeRow(row);
    }
    QFileInfo fi(fileName);
    if (fi.fileName()=="_coursera") {
        delete _courseraProject;
        _courseraProject = NULL;
        ui->actionSubmit_to_Coursera->setVisible(false);
    }
}
示例#30
0
QString Project::fileAtIndex(const QModelIndex &index)
{
    QStandardItem* item = itemFromIndex(index);
    if (item==NULL || item->hasChildren())
        return "";
    QString fileName;
    while (item != NULL && item->parent() != NULL && item->parent() != invisibleRootItem() ) {
        if (fileName.isEmpty())
            fileName = item->text();
        else
            fileName = item->text()+"/"+fileName;
        item = item->parent();
    }
    if (fileName.isEmpty())
        return "";
    if (!projectRoot.isEmpty()) {
        fileName = QFileInfo(projectRoot).absolutePath()+"/"+fileName;
    }
    QFileInfo fi(fileName);
    if (fi.canonicalFilePath().isEmpty())
        fileName = "/"+fileName;
    fileName = QFileInfo(fileName).canonicalFilePath();
    return fileName;
}