コード例 #1
0
ファイル: bookmarks.cpp プロジェクト: RobinWuDev/Qt
AddBookmarkDialog::AddBookmarkDialog(const QString &url, const QString &title, QWidget *parent, BookmarksManager *bookmarkManager)
    : QDialog(parent)
    , m_url(url)
    , m_bookmarksManager(bookmarkManager)
{
    setWindowFlags(Qt::Sheet);
    if (!m_bookmarksManager)
        m_bookmarksManager = BrowserApplication::bookmarksManager();
    setupUi(this);
    QTreeView *view = new QTreeView(this);
    m_proxyModel = new AddBookmarkProxyModel(this);
    BookmarksModel *model = m_bookmarksManager->bookmarksModel();
    m_proxyModel->setSourceModel(model);
    view->setModel(m_proxyModel);
    view->expandAll();
    view->header()->setStretchLastSection(true);
    view->header()->hide();
    view->setItemsExpandable(false);
    view->setRootIsDecorated(false);
    view->setIndentation(10);
    location->setModel(m_proxyModel);
    view->show();
    location->setView(view);
    BookmarkNode *menu = m_bookmarksManager->menu();
    QModelIndex idx = m_proxyModel->mapFromSource(model->index(menu));
    view->setCurrentIndex(idx);
    location->setCurrentIndex(idx.row());
    name->setText(title);
}
コード例 #2
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void BookmarksItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
{
  BookmarksModel* bModel = qobject_cast<BookmarksModel*>(model);

  QLineEdit* line = static_cast<QLineEdit*>(editor);
  QString value = line->text();

  if (value.isEmpty() == false)
  {
    QModelIndex bIndex = bModel->index(index.row(), BookmarksItem::Name, index.parent());
    bModel->setData(bIndex, value, Qt::DisplayRole);
  }
}
コード例 #3
0
void BookmarksItem::remove()
{
	BookmarksModel *model = qobject_cast<BookmarksModel*>(this->model());

	if (model)
	{
		model->removeBookmark(this);
	}
	else
	{
		delete this;
	}
}
コード例 #4
0
ファイル: BookmarksModel.cpp プロジェクト: kglowins/DREAM3D
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void BookmarksModel::moveIndexInternally(const QModelIndex& index, QModelIndex& oldParent, QModelIndex& newParent)
{
  BookmarksModel* tempModel = new BookmarksModel();

  // Copy the sub-tree to a temporary model, to retain its data and structure
  copyIndexToTemp(index, oldParent, QModelIndex(), tempModel);

  // Now copy the sub-tree to its new position
  for (int i = 0; i < tempModel->rowCount(QModelIndex()); i++)
  {
    QModelIndex tempIndex = tempModel->index(i, BookmarksItem::Name, QModelIndex());
    copyTempToIndex(tempIndex, newParent, QModelIndex(), tempModel);
  }

  // Remove the index from its original spot
  self->removeRow(index.row(), oldParent);
}
コード例 #5
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void SIMPLView_UI::checkFirstRun()
{
  // Launch v6.0 dialog box if this is the first run of v6.0
  SIMPLViewSettings prefs;
  bool firstRun = prefs.value("First Run", true).toBool();
  if (firstRun == true)
  {
    // This is the first run of SIMPLView v6.0, so we need to show the v6.0 wizard
    SIMPLViewv6Wizard* wizard = new SIMPLViewv6Wizard(this, Qt::WindowTitleHint);
    wizard->exec();

    bool value = wizard->isBookmarkBtnChecked();
    if (value == true)
    {
      BookmarksModel* model = BookmarksModel::Instance();

      model->insertRow(0, QModelIndex());
      QModelIndex nameIndex = model->index(0, BookmarksItem::Name, QModelIndex());
      model->setData(nameIndex, "SIMPLView v4 Favorites", Qt::DisplayRole);
      model->setData(nameIndex, QIcon(":/folder_blue.png"), Qt::DecorationRole);

      QDir favoritesDir = getBookmarksToolboxWidget()->findV4FavoritesDirectory();
      QString favoritesPath = favoritesDir.path();
      QFileInfo fi(favoritesPath);

      if (fi.exists() && favoritesPath.isEmpty() == false)
      {
        QDirIterator iter(favoritesPath, QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
        while (iter.hasNext())
        {
          QString path = iter.next();
          model->addFileToTree(path, nameIndex);
        }
      }
    }
  }
}
コード例 #6
0
QVariant BookmarksItem::data(int role) const
{
	if (role == Qt::DisplayRole)
	{
		const BookmarksModel::BookmarkType type = static_cast<BookmarksModel::BookmarkType>(data(BookmarksModel::TypeRole).toInt());

		if (type == BookmarksModel::RootBookmark)
		{
			BookmarksModel *model = qobject_cast<BookmarksModel*>(this->model());

			if (model && model->getFormatMode() == BookmarksModel::NotesMode)
			{
				return QCoreApplication::translate("Otter::BookmarksModel", "Notes");
			}

			return QCoreApplication::translate("Otter::BookmarksModel", "Bookmarks");
		}

		if (type == BookmarksModel::TrashBookmark)
		{
			return QCoreApplication::translate("Otter::BookmarksModel", "Trash");
		}
	}

	if (role == Qt::DecorationRole)
	{
		const BookmarksModel::BookmarkType type = static_cast<BookmarksModel::BookmarkType>(data(BookmarksModel::TypeRole).toInt());

		if (type == BookmarksModel::RootBookmark || type == BookmarksModel::FolderBookmark)
		{
			return Utils::getIcon(QLatin1String("inode-directory"));
		}

		if (type == BookmarksModel::TrashBookmark)
		{
			return Utils::getIcon(QLatin1String("user-trash"));
		}

		if (type == BookmarksModel::UrlBookmark)
		{
			return HistoryManager::getIcon(data(BookmarksModel::UrlRole).toUrl());
		}

		return QVariant();
	}

	if (role == Qt::AccessibleDescriptionRole && static_cast<BookmarksModel::BookmarkType>(data(BookmarksModel::TypeRole).toInt()) == BookmarksModel::SeparatorBookmark)
	{
		return QLatin1String("separator");
	}

	if (role == BookmarksModel::IsTrashedRole)
	{
		QModelIndex parent = index().parent();

		while (parent.isValid())
		{
			const BookmarksModel::BookmarkType type = static_cast<BookmarksModel::BookmarkType>(parent.data(BookmarksModel::TypeRole).toInt());

			if (type == BookmarksModel::TrashBookmark)
			{
				return true;
			}

			if (type == BookmarksModel::RootBookmark)
			{
				break;
			}

			parent = parent.parent();
		}

		return false;
	}

	return QStandardItem::data(role);
}